From 95a6a872b605ea46334aa80a15be622442e5a080 Mon Sep 17 00:00:00 2001 From: Henrik Wenz Date: Fri, 12 Oct 2018 14:32:17 +0100 Subject: [PATCH] Refactor test setup (#5391) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - [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. --- azure-pipelines.yml | 8 ++++---- jest.config.js | 12 ++++++++++++ package.json | 6 +++--- test/jest-config.json | 7 ------- test/jest-global-setup.js | 9 +++++++++ test/jest-global-teardown.js | 2 ++ 6 files changed, 30 insertions(+), 14 deletions(-) create mode 100644 jest.config.js delete mode 100644 test/jest-config.json diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 23baa835..6dab13bf 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -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' \ No newline at end of file + yarn test + displayName: 'Run tests' diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 00000000..1a481c6b --- /dev/null +++ b/jest.config.js @@ -0,0 +1,12 @@ +'use strict' + +module.exports = { + testMatch: ['**/*.test.js'], + verbose: true, + bail: true, + testEnvironment: 'node', + rootDir: 'test', + modulePaths: ['/lib'], + globalSetup: '/jest-global-setup.js', + globalTeardown: '/jest-global-teardown.js' +} diff --git a/package.json b/package.json index ff25f436..64890aad 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", @@ -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" } } diff --git a/test/jest-config.json b/test/jest-config.json deleted file mode 100644 index 89c132b3..00000000 --- a/test/jest-config.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "verbose": true, - "bail": true, - "testEnvironment": "node", - "globalSetup": "./jest-global-setup.js", - "globalTeardown": "./jest-global-teardown.js" -} diff --git a/test/jest-global-setup.js b/test/jest-global-setup.js index 1146f86a..ce633de8 100644 --- a/test/jest-global-setup.js +++ b/test/jest-global-setup.js @@ -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 + }) } diff --git a/test/jest-global-teardown.js b/test/jest-global-teardown.js index 18a88ce5..4396210b 100644 --- a/test/jest-global-teardown.js +++ b/test/jest-global-teardown.js @@ -1,3 +1,5 @@ +'use strict' + const chromedriver = require('chromedriver') module.exports = async function globalSetup () {