Instructor: In the last section,
we started putting together our Travis.yml file.
Remember, this is the file that's gonna tell Travis
what we want it to do with our code.
So we've now told it that we have a copy of Docker running,
and we've also told it to build an image
using the Dockerfile.dev file.
We now need to add in one last little line of configuration
that's gonna tell Travis how to run our test suite.
So back inside of my .travis.yml file
I'm gonna add in a new section called script.
The script section is supposed to contain
all the different commands that need to be executed
to actually run our test suite.
So these are gonna be a series of commands
just like before install was that are going to be ran
when our tests need to actually be executed.
Travis CI is going to be watching
the output of each of these commands,
and from each command,
if it ever gets a return status code other than zero
Travis is going to assume that our build failed
or that our test suite failed to run properly
and it's going to assume that our code
is essentially broken.
So in order to actually run our tests,
we're gonna use the same Docker command
that we used just a little bit ago
to start up our container out of that image right there
and run the test inside of it.
So, quick reminder on how we do that.
We're essentially gonna say
something like docker run, the image,
and then we're going to override the default start command
by saying npm run test, like so.
Now one little gotcha here, just a tiny little gotcha.
Anytime that we run our test suite on Travis CI,
Travis is going to assume that our test suite runs
and then exits automatically.
And he essentially says,
"Okay, I either successfully ran all tests
or something wrong just occurred."
However, the default behavior of npm run test,
let's run this right now
and you'll see what the default behavior is.
So the default behavior is to run our test suite one time
and then present us with this menu right here
that says, "Okay, well, I'm just gonna sit here
and wait for you to tell me
whether you want to do some more tests
or filter or do whatever else."
So the default npm run test command
just kind of hangs there and never exits ever.
And so if we ran this on Travis CI,
Travis would say, "Well, you know, it's been like 30 days
and I'm still waiting here for the results of npm run test."
And they're never gonna come
because NPM run test just sits and hangs
and waits for input from you and I.
So to work around this
and make sure that the test suite automatically exits
the instant that the first run is completed,
we're gonna add on a little additional command up here.
We're gonna say -- --coverage, like so.
So notice how there's two sets of dashes.
So I'm gonna run that.
And then we're going to see that the test suite runs
and then exits back to the command line.
You'll notice that when it runs,
we get a little bit of output right here.
This is essentially telling us how much code
inside of our project is being covered by our tests.
In reality, it's essentially saying how many lines of code
or functions or whatever it might be
actually got executed when the tests were executed.
Now, it's totally fine
that we return this stuff to Travis CI again.
The only thing that Travis cares about is the status code
that comes back from running this command.
So we're just gonna add on that -- --coverage
just to make sure that the npm run test command
automatically exits when the test suite is done.
Okay, so with that in mind, back at script right here,
to run our test suite, we're gonna say docker run.
Then we'll provide the name of the image that we just built,
stephengrider/docker-react,
and then we'll override the default command
by saying npm run test -- --coverage.
Again, don't forget the two sets of dashes there
with the space in between.
All right, and that is pretty much it.
That's all we have to do right now.
So now anytime that Travis sees
that we have pushed a new commit up to GitHub,
it's gonna clone all of our code
and then use these series of directions
to build our docker image, run some tests,
and then report on whether our tests succeeded or failed.
So let's save this file.
We're gonna take a break right now
and then we'll test out the setup in the next section.