Home > Articles > Open Source > Ajax & JavaScript

  • Print
  • + Share This
From the author of Running the Test Suite

Running the Test Suite

With the test written, all that's left to do is run it, in one of two ways. The first is in the browser. To do that, we can start the server with which Konacha ships:

> rake konacha:serve

That command starts a server on port 3500. If you then navigate to http://localhost:3500, you should be greeted with a screen that looks something like Figure 1.

Congratulations! You have written and run your very first JavaScript/CoffeeScript test.

When we go to http://localhost:3500, it will run the entire test suite we've written—in this case, just the one test. However, if we want to run just this one file, we can do it by visiting http://localhost:3500/greeter_spec, as shown in Figure 2.

Running the test suite is really fast, but often it's nice to be able to run the specs in the background, using a tool such as Guard, or as part of your continuous integration server. To do this, we can run the following rake task:

> rake konacha:run

Depending on how your system is configured, when you ran that command the Firefox browser should have launched and then quickly disappeared. Why? Because we're testing JavaScript, we need a JavaScript environment in which we can execute the test suite, so the rake task launches a browser, runs the tests, exits the browser, and prints something similar to the following to your terminal window:

Finished in 3.51 seconds
1 examples, 0 failures

Unfortunately, having Firefox popping up continually while you're trying to work isn't very nice. This also won't work on continuous integration servers that most likely don't have Firefox installed. How do we solve this problem? We need to install a headless web browser.

  • + Share This
  • 🔖 Save To Your Account