There are 3 different ways to run your tests- see them all in action, and see why we settle on ember test --server
.
Links
Code
$ ember test --server
Transcript
In the last two episodes, we prepared for testing by creating the ember-cli-mirage server and a factory that helped generate all these monsters. This infrastructure will be very useful once we start writing our tests. But now we need to do a separate piece of preparation which is getting our test runner in order.
Now there are three different ways that we can run our tests. The first is at localhost/tests. Now this format has some advantages. You can do things like hide all the past tests, you can disable the linting tests... so this is using JSLint which basically checks to see if you have any semicolons missing and stuff like that, and several other options. I’ll go ahead and in the background fix these JSLint errors. Okay, there, they’re all fixed.
One thing I like about this format is that it’s really easy to set up, you can show it to hide the past tests and so it’ll automatically just show you red when anything is messing up and otherwise give you a nice little checkmark in the background of your browser. One downside though is that it’s run in development
mode.
So there are by default three different modes in your ember app. There’s development
, test
, and production
, and they’re all going to have different options set. And so if you have something running in development
mode, it’s going to run differently than if it’s running in test
mode. So that’s why the official ember guides recommend that you not use the ember server tests. Instead it recommends you use ember test --server
, which we’ll get to in just a second.
But first the second option which is just ember test
without the --server
. So you can see it running and it’s going to build your app every time. That’s one of the weaknesses of this particular method. And it runs all your tests. They pass. Awesome. Now ember test --server
is going to run it all in test
mode and then like ember test
it’s going to build your app. But then it’ll do this and this popped up on the other screen. Not that, this. And so this is the screen that we had for our /tests
, but now it’s in a different browser and it’s in test
mode instead of in development
mode. And you’ll see this pops up under a new browser instead of the browser we’re using for everything else.
So ember test --server
has all the good points of ember test
and the good points of running it on the /tests
on the browser. So let’s go ahead and see this in action with something failing. I’ll go ahead and make JSLint fail and we will see that this updates and we see our error here. So it’ll display as many errors as it can. If you have a lot of errors it’ll only display some of them. And it’ll also show it running in two different environments right now, PhantomJS
as well as Chrome
. And this is the Chrome environment that it’s running in. If you want to add more environments, you can go to your testem.js
file and add it to the launch_in_dev
array.
So there we go. That’s our test runners. In the next video, we will write our first acceptance test.