Full-Stack Web Development with Vue.js and Node

(singke) #1
Testing an MEVN Application Chapter 9

.end();
},
};

This is the main file, where we will add our test cases for the application.


The end-to-end testing makes sure that all the the flow of our application is performing as
expected or not. When we run the e2e test, we want certain parts of our application to be


clicked and behave the way it should. This can be described as testing the behavior of the
application.


To be able to run the e2e tests, we will need to start a selenium-server. If we take a look


at the test/e2e/nightwatch.conf.js file, we can find a line that says:


...
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
}
},
...

This means that when we run the e2e test, a selenium-server is started automatically,


and we don't have to run a separate server. The port defines which port to use
for selenium-server. You can leave this as it is and run the test, or you can change the


values and configure it yourself.


Finally, we need a runner file for Nightwatch to run the test. Create a file called


runner.js inside the e2e folder and add the following contents:


// 1. start the dev server using production config
process.env.NODE_ENV = 'testing'

const webpack = require('webpack')
const DevServer = require('webpack-dev-server')

const webpackConfig = require('../../build/webpack.prod.conf')
const devConfigPromise = require('../../build/webpack.dev.conf')

let server

devConfigPromise.then(devConfig => {
Free download pdf