Full-Stack Web Development with Vue.js and Node

(singke) #1
Testing an MEVN Application Chapter 9

The tests should pass.


Finally, to run all the tests, we can simply run the following command:


$ npm run test

Writing e2e testing


The vue.js applications created with vue-cli command contains the support for end-to-


end testing which uses Nightwatch. Nightwatch is a very easy framework to write end-


to-end test. Nightwatch uses Selenium commands to run the JavaScript.


Installing Nightwatch


If you haven't set up the application for e2e, then let's first install the package needed to


run the e2e tests:


$ npm install nightwatch --save

Configuring Nightwatch


Now, we need a configuration file to run the test. Create a folder called e2e inside the test


folder. Add the nightwatch.conf.js file and add the following contents to it:


require('babel-register')
var config = require('../../config')

// http://nightwatchjs.org/gettingstarted#settings-file
module.exports = {
src_folders: ['test/e2e/specs'],
custom_assertions_path: ['test/e2e/custom-assertions'],

selenium: {
start_process: true,
server_path: require('selenium-server').path,
host: '127.0.0.1',
port: 4444,
cli_args: {
'webdriver.chrome.driver': require('chromedriver').path
}
},
Free download pdf