E2E test
To create e2e tests we will use CodeceptJS which is an acceptance testing "metaframework" that provides helpers on top of popular browser-based frameworks like Selenium, Protractor and Nightmare.
In our case we will use codecept-nightmare.
We will keep our tests in a separated project, so lets create the project
mkdir e2e-tests
cd e2e-tests/
yarn init -y
yarn add -D codeceptjs-nightmare nightmare nightmare-upload
node_modules/codeceptjs/bin/codecept.js init
In the wizard I have chosen:
- Nightmare
- tests: test/*/_test.js
- Server: http://localhost:3000
Then create a first silly test
vi test/load_users_test.js
With content
Feature('Users List')
Scenario('Loads fine', (I) => {
I.amOnPage('/')
I.see('E2E testing with Docker')
I.waitForText('Socrates')
})
Then lets add a script to package.json to run the tests
"scripts": {
"test": "DEBUG=nightmare yarn codeceptjs run --steps --verbose"
},
And it is good to see the browser window for debugging, so edit the file codecept.json and add the **show: true
"Nightmare": {
"url": "http://localhost:3000",
"show": true
}
Now make sure that you have all 2 apps running
cd frontend
yarn start
cd backend
yarn start
And now just run the tests in a 3rd console
yarn test
yarn test v0.21.3
$ DEBUG=nightmare yarn codeceptjs run --steps --verbose
yarn codeceptjs v0.21.3
verbose 0.262 current time: 2017-05-06T23:35:45.069Z
$ "/Users/jfernandes/dev/data/repo/scv/docker/e2e-tests/node_modules/.bin/codeceptjs" run
CodeceptJS v0.6.2
Using test root "/Users/jfernandes/dev/data/repo/scv/docker/e2e-tests"
Users List --
nightmare queuing process start +0ms
nightmare queueing child action addition for "upload" +1ms
nightmare queueing child action addition for "pressKey" +1ms
nightmare queueing action "goto" for http://localhost:3000/ +1ms
nightmare running +0ms
nightmare queueing action "inject" +2s
nightmare queueing action "evaluate" +48ms
nightmare running +2ms
nightmare queueing action "wait" +23ms
nightmare running +1ms
✓ Loads fine in 1686ms
nightmare running +7ms
OK | 1 passed // 2s
nightmare electron child process exited with code 0: success! +74ms
✨ Done in 2.35s.
✨ Done in 2.83s.
That's it we have e2e tests for our app. Of course one would have many and more complete tests clicking elements, browsing, navigating, filling inputs, and asserting, things. But this is enough for the sake of the example.
It already has the structural complexity that we would like to solve. That is: we want to avoid having 3 terminals to manually start front and back and also having mongoose.
And for that we will use docker ! :)