Launching the test runner

Now that we have our test code and a Calculator object, it's time to launch Karma to execute our test. Open the command line and in the practice-karma root folder, execute the following command:

./node_modules/karma/.bin/karma start karma.conf.js

The preceding command will output a bunch of logs, while it opens a new window in your Chrome web browser and executes your test into the web page recently started. This page is opened in Chrome because it is configured in the karma.conf.js. Consider this example:

$ ./node_modules/karma/bin/karma start karma.conf.js

10 12 2017 12:12:43.049:WARN [karma]: No captured browser, open http://localhost:9876/
10 12 2017 12:12:43.059:INFO [karma]: Karma v1.7.1 server started at http://0.0.0.0:9876/
10 12 2017 12:12:43.060:INFO [launcher]: Launching browser Chrome with unlimited concurrency
10 12 2017 12:12:43.086:INFO [launcher]: Starting browser Chrome
10 12 2017 12:12:44.628:INFO [Chrome 62.0.3202 (Mac OS X 10.12.6)]: Connected on socket 8n0My3AYk-xKfu9sAAAA with id 38155723
Chrome 62.0.3202 (Mac OS X 10.12.6): Executed 1 of 1 SUCCESS (0 secs / 0.002 secChrome 62.0.3202 (Mac OS X 10.12.6): Executed 1 of 1 SUCCESS (0.007 secs / 0.002 secs)

Note in the last lines that our test was executed with a successful result. The web page launched looks similar to this:

As you might have noted, running the previous command might be too long to remember; to make our life easy, let's configure our package.json file to configure the test script to execute this command for us. Open the package.json files and apply the following changes:

{
"name": "practice-karma",
...
"scripts": {
"test": "./node_modules/karma/bin/karma start karma.conf.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
...
}
}

Once configured, execute the following command to run the tests:

$ npm test

That's it. Using Karma and Jasmine will give us all the enablers we need to write robust tests for our applications. Both technologies are not limited to web development. You can use them in any Javascript project such as a backend written in Node.js. So now, it's time to see an example with a real Aurelia component. Keep reading!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.76.30