Skip to content

Commit

Permalink
Refactor test setup (#5391)
Browse files Browse the repository at this point in the history
- [x] Move jest config from npm scripts to `jest.config.js`
- [x] Remove obsolete cross-env package (we don't need it anymore 🎉)
- [x] Fix bug where tests are not waiting for webdriver to be ready.
  • Loading branch information
HaNdTriX authored and timneutkens committed Oct 12, 2018
1 parent d4785eb commit 95a6a87
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 14 deletions.
8 changes: 4 additions & 4 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ steps:
displayName: 'Install Node.js'

- script: |
npm install
yarn install
displayName: 'Install dependencies'

- script: |
npm run bootstrap
yarn bootstrap
displayName: 'Lerna bootstrap'

- script: |
npm test
displayName: 'Run tests'
yarn test
displayName: 'Run tests'
12 changes: 12 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict'

module.exports = {
testMatch: ['**/*.test.js'],
verbose: true,
bail: true,
testEnvironment: 'node',
rootDir: 'test',
modulePaths: ['<rootDir>/lib'],
globalSetup: '<rootDir>/jest-global-setup.js',
globalTeardown: '<rootDir>/jest-global-teardown.js'
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"lerna": "lerna",
"bootstrap": "lerna bootstrap",
"dev": "lerna run build --stream --parallel",
"testonly": "cross-env NODE_PATH=test/lib jest \\.test.js --config=./test/jest-config.json",
"testonly": "jest",
"testall": "npm run testonly -- --coverage --forceExit --runInBand",
"pretest": "npm run lint",
"test": "cross-env npm run testall || npm run testall",
"test": "npm run testall || npm run testall",
"coveralls": "cat ./test/coverage/lcov.info | coveralls",
"lint": "lerna run lint",
"prepublish": "lerna run prepublish",
Expand Down Expand Up @@ -46,7 +46,6 @@
"chromedriver": "2.42.0",
"clone": "2.1.1",
"coveralls": "3.0.2",
"cross-env": "5.2.0",
"express": "4.16.3",
"fkill": "5.1.0",
"flatten": "1.0.2",
Expand All @@ -66,6 +65,7 @@
"rimraf": "2.6.2",
"standard": "11.0.1",
"taskr": "1.1.0",
"wait-port": "0.2.2",
"wd": "1.10.3"
}
}
7 changes: 0 additions & 7 deletions test/jest-config.json

This file was deleted.

9 changes: 9 additions & 0 deletions test/jest-global-setup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
'use strict'

const chromedriver = require('chromedriver')
const waitPort = require('wait-port')

module.exports = async function globalSetup () {
chromedriver.start()

// https://github.com/giggio/node-chromedriver/issues/117
await waitPort({
port: 9515,
timeout: 1000 * 60 * 2 // 2 Minutes
})
}
2 changes: 2 additions & 0 deletions test/jest-global-teardown.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

const chromedriver = require('chromedriver')

module.exports = async function globalSetup () {
Expand Down

0 comments on commit 95a6a87

Please sign in to comment.