This repo contains a demo for the Travis CI codebase.
We use npm init
, which is pretty self-explanatory. The only step you need to
really look for is the test command
question.
For that, we use eslint to check the /src
directory.
test command: eslint src/
That's it, then we just need to install the dependencies:
npm install --save-dev \
eslint \
eslint-config-standard \
eslint-plugin-import \
eslint-plugin-promise \
eslint-plugin-standard
ESLint requires an .eslintrc
file, which contains configuration data.
Luckily, this is very easy, since the Standard code standard basically defines all rules for ESLint.
{
"extends": "standard",
"env": {
"node": true
}
}
To configure Travis CI, we create a .travis.yml
file, which will contain
information for Travis on how to handle the compilation of the project.
We have to specify an environment, which is one of the list below (which can be found in the docs of Travis CI):
In our case, we use node_js
and we want it to run npm test
. This means we
have to specify which NodeJS versions we want to test and what command we want
to run. The node_js
environment will run npm install
for us, so we don't
need to mention that.
language: node_js
node_js:
- "node"
- "6"
script:
- npm test
Now we need to go to our Travis account and enable the repository we want to use.
After we've done this, we can commit everything we've added, and push it to GitHub. Travis will then start running a build and will report back the results.
git add .eslintrc .travis.yml package.json
git commit -m "Initial commit"
As we don't have any code yet, the build may fail as eslint has nothing to check and will report an error instead.
As the current code is broken, we need to fix it. The Travis CI log contains error information on what's broken and what is not.
$ npm test
> travis-demo@1.0.0 test /home/travis/build/teamfieldtrip/travis-demo
> eslint src/
/home/travis/build/teamfieldtrip/travis-demo/src/index.js
1:1 error Expected an assignment or function call and no-unused-expressions
instead saw an expression
1:10 error Missing space before function parentheses space-before-function-paren
2:5 error Expected indentation of 2 spaces but found 4 indent
2:17 error Extra semicolon semi
4:5 error Expected indentation of 2 spaces but found 4 indent
4:28 error Missing space before function parentheses space-before-function-paren
5:9 error Expected indentation of 6 spaces but found 8 indent
5:41 error Extra semicolon semi
6:6 error Extra semicolon semi
8:5 error Expected indentation of 2 spaces but found 4 indent
8:60 error Extra semicolon semi
9:3 error Extra semicolon semi
✖ 12 problems (12 errors, 0 warnings)
npm ERR! Test failed. See above for more details.
The command "npm test" exited with 1.
It's a lot of errors, but not too much to worry about. After fixing the code and commit it, the build will succeed.
diff --git a/src/index.js b/src/index.js
index 68f697a..f5055da 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,9 +1,9 @@
-(function() {
- 'use strict';
+(function () {
+ 'use strict'
- var sayHello = function() {
- console.log('Mein little Füher');
- };
+ var sayHello = function () {
+ console.log('Mein little Füher')
+ }
- document.addEventListener('DOMContentLoaded', sayHello);
-});
+ document.addEventListener('DOMContentLoaded', sayHello)
+}())
After we've applied the above patch, and committed it, the build will succeed.