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