Bummer! This is just a preview. You need to be signed in with a Pro account to view the entire video.
Start a free Basic trial
to watch this video
In this video we'll integrate Travis CI in to a Node.js project.
-
0:00
Here we have a simple Node.js project called calculator.js.
-
0:04
We have some tests here that test the functionality which includes an add,
-
0:08
subtract, and divide function.
-
0:11
If you want to follow along hit the fork repo button and
-
0:13
then clone the repository down to your local machine.
-
0:20
Then jump into the calculator directory and
-
0:25
then install any dependencies.
-
0:32
Finally run the test suite.
-
0:35
You should have nine tests passing.
-
0:38
We've got three pending, which we'll implement later.
-
0:42
Now I'm going to create a branch.
-
0:44
You don't have to do this, this is an optional step but I'm going to do it for
-
0:48
the integration for Travis.
-
0:53
I'm gonna name a branch travis.
-
0:55
It could be named anything, it doesn't really matter.
-
0:58
And then open up the code editor of choice.
-
1:01
Mine is Visual Studio code.
-
1:03
Now let's head over to Travis CI.
-
1:06
I'm in the accounts page again and you can select your username, and if you're
-
1:10
part of any organization where you forked this repo to, you want select that.
-
1:15
In my case it's treehouse-projects/calculator.js.
-
1:18
For you, it may be your username and then calculator.js.
-
1:22
So the first step is to flick the switch to enable travis-ci on that repo.
-
1:27
So let's click on that project and here's the dashboard for the calculator.
-
1:32
As you can see there's no builds for this repository yet.
-
1:35
Let's read the docs and go to JavaScript and we can see a sample .travis.yml file.
-
1:42
Notice this dot here.
-
1:43
It needs that dot there or else it won't work.
-
1:46
So you can see here we've got a key, which is language, and
-
1:51
then the value is node_js.
-
1:54
And then it describes all the versions of node_js you want to test.
-
1:57
If you just include 6 without any minor or patch releases,
-
2:02
it will test the latest version of node_js.
-
2:06
So let's copy those three lines of code there, and head over to our editor.
-
2:13
And let's create our .travis.yml file, and
-
2:19
remember, make sure you've got that dot there.
-
2:22
Paste that in and then commit the code.
-
2:32
Git commit -m "Travis integration".
-
2:40
And then we can do git push, and then set the upstream to origin travis.
-
2:50
So now my local branch has been pushed to GitHub on the travis branch.
-
2:57
So we can go back now to our dashboard and
-
3:03
as you can see the Travis integration is now being tested.
-
3:07
This is the travis-ci building the dependencies for
-
3:13
node.js, and as you can see it's cloning the repo.
-
3:21
It's downloading the latest version of node.js, it's running npm
-
3:26
install, And testing.
-
3:31
And there's all our Mocha tests.
-
3:34
And it says the command npm test exited with 0.
-
3:37
Meaning, it's exited okay.
-
3:39
So the build is done and as you can see, our Travis integration has worked.
-
3:47
We also have this cool little icon up here saying the build passing.
-
3:51
You can actually include this in your documentation so you can click on this
-
3:55
markdown and then copy and paste this SVG and put that into your readme.
-
4:02
Now this is where I would merge the Travis branch into my master branch,
-
4:06
but since you're forking from my master, I'm gonna keep it separate for now.
-
4:11
In the next video, we're gonna take a look at when things go wrong.
You need to sign up for Treehouse in order to download course files.
Sign up