diff --git a/jest-puppeteer.config.js b/jest-puppeteer.config.js new file mode 100644 index 0000000000..596ad911be --- /dev/null +++ b/jest-puppeteer.config.js @@ -0,0 +1,20 @@ +const configPaths = require('./config/paths.json') +const PORT = process.env.PORT || configPaths.ports.test + +module.exports = { + browserContext: 'incognito', + launch: { + // we use --no-sandbox --disable-setuid-sandbox as a workaround for the + // 'No usable sandbox! Update your kernel' error + // see more https://github.com/Googlechrome/puppeteer/issues/290 + args: [ + '--no-sandbox', + '--disable-setuid-sandbox' + ] + }, + server: { + command: `PORT=${PORT} node app/start.js`, + launchTimeout: 30000, // Allow time for application to start + port: PORT + } +} diff --git a/lib/puppeteer/environment.js b/lib/puppeteer/environment.js deleted file mode 100644 index 4ce8734e31..0000000000 --- a/lib/puppeteer/environment.js +++ /dev/null @@ -1,33 +0,0 @@ -const chalk = require('chalk') -const NodeEnvironment = require('jest-environment-node') -const puppeteer = require('puppeteer') -const fs = require('fs') -const os = require('os') -const path = require('path') - -const DIR = path.join(os.tmpdir(), 'jest-puppeteer-global-setup') - -class PuppeteerEnvironment extends NodeEnvironment { - async setup () { - console.log(chalk.yellow('Setup Test Environment.')) - await super.setup() - const wsEndpoint = fs.readFileSync(path.join(DIR, 'wsEndpoint'), 'utf8') - if (!wsEndpoint) { - throw new Error('wsEndpoint not found') - } - this.global.__BROWSER__ = await puppeteer.connect({ - browserWSEndpoint: wsEndpoint - }) - } - - async teardown () { - console.log(chalk.yellow('Teardown Test Environment.')) - await super.teardown() - } - - runScript (script) { - return super.runScript(script) - } -} - -module.exports = PuppeteerEnvironment diff --git a/lib/puppeteer/setup.js b/lib/puppeteer/setup.js deleted file mode 100644 index cf41a5711f..0000000000 --- a/lib/puppeteer/setup.js +++ /dev/null @@ -1,37 +0,0 @@ -const chalk = require('chalk') -const puppeteer = require('puppeteer') -const fs = require('fs') -const mkdirp = require('mkdirp') -const os = require('os') -const path = require('path') -const app = require('../../app/app.js')({ - nunjucks: { watch: false } -}) - -const configPaths = require('../../config/paths.json') -const PORT = configPaths.ports.test - -const DIR = path.join(os.tmpdir(), 'jest-puppeteer-global-setup') - -// Jest Setup.js expects promises, using callbacks results in a race condition. -const appListen = (port) => { - return new Promise((resolve) => { - const server = app.listen(port, () => { - resolve(server) - }) - }) -} - -module.exports = async () => { - console.log(chalk.green('\nStart Server')) - global.__SERVER__ = await appListen(PORT) - console.log('Server started at http://localhost:' + PORT) - console.log(chalk.green('Setup Puppeteer')) - // we use --no-sandbox --disable-setuid-sandbox as a workaround for the - // 'No usable sandbox! Update your kernel' error - // see more https://github.com/Googlechrome/puppeteer/issues/290 - const browser = await puppeteer.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox'] }) - global.__BROWSER__ = browser - mkdirp.sync(DIR) - fs.writeFileSync(path.join(DIR, 'wsEndpoint'), browser.wsEndpoint()) -} diff --git a/lib/puppeteer/teardown.js b/lib/puppeteer/teardown.js deleted file mode 100644 index 659a92c448..0000000000 --- a/lib/puppeteer/teardown.js +++ /dev/null @@ -1,14 +0,0 @@ -const chalk = require('chalk') -const rimraf = require('rimraf') -const os = require('os') -const path = require('path') - -const DIR = path.join(os.tmpdir(), 'jest-puppeteer-global-setup') - -module.exports = async function () { - console.log(chalk.green('Teardown Puppeteer')) - await global.__BROWSER__.close() - console.log(chalk.green('Close server')) - await global.__SERVER__.close() - rimraf.sync(DIR) -} diff --git a/package-lock.json b/package-lock.json index a7a44ae103..1b7cdfdf87 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2667,6 +2667,45 @@ "integrity": "sha1-4+JbIHrE5wGvch4staFnksrD3Fg=", "dev": true }, + "clone-deep": { + "version": "0.2.4", + "resolved": "https://registry.npmjs.org/clone-deep/-/clone-deep-0.2.4.tgz", + "integrity": "sha1-TnPdCen7lxzDhnDF3O2cGJZIHMY=", + "dev": true, + "requires": { + "for-own": "^0.1.3", + "is-plain-object": "^2.0.1", + "kind-of": "^3.0.2", + "lazy-cache": "^1.0.3", + "shallow-clone": "^0.1.2" + }, + "dependencies": { + "for-own": { + "version": "0.1.5", + "resolved": "https://registry.npmjs.org/for-own/-/for-own-0.1.5.tgz", + "integrity": "sha1-UmXGgaTylNq78XyVCbZ2OqhFEM4=", + "dev": true, + "requires": { + "for-in": "^1.0.1" + } + }, + "kind-of": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", + "integrity": "sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=", + "dev": true, + "requires": { + "is-buffer": "^1.1.5" + } + }, + "lazy-cache": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/lazy-cache/-/lazy-cache-1.0.4.tgz", + "integrity": "sha1-odePw6UEdMuAhF07O24dpJpEbo4=", + "dev": true + } + } + }, "clone-stats": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/clone-stats/-/clone-stats-0.0.1.tgz", @@ -3277,6 +3316,16 @@ "array-find-index": "^1.0.1" } }, + "cwd": { + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/cwd/-/cwd-0.10.0.tgz", + "integrity": "sha1-FyQAaUBXwioTsM8WFix+S3p/5Wc=", + "dev": true, + "requires": { + "find-pkg": "^0.1.2", + "fs-exists-sync": "^0.1.0" + } + }, "d": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/d/-/d-1.0.0.tgz", @@ -4622,6 +4671,12 @@ "jest-regex-util": "^24.3.0" } }, + "expect-puppeteer": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/expect-puppeteer/-/expect-puppeteer-4.1.1.tgz", + "integrity": "sha512-xNpu6uYJL9Qrrp4Z31MOpDWK68zAi+2qg5aMQlyOTVZNy7cAgBZiPvKCN0C1JmP3jgPZfcxhetVjZLaw/KcJOQ==", + "dev": true + }, "express": { "version": "4.16.4", "resolved": "https://registry.npmjs.org/express/-/express-4.16.4.tgz", @@ -4905,12 +4960,91 @@ "unpipe": "~1.0.0" } }, + "find-file-up": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/find-file-up/-/find-file-up-0.1.3.tgz", + "integrity": "sha1-z2gJG8+fMApA2kEbN9pczlovvqA=", + "dev": true, + "requires": { + "fs-exists-sync": "^0.1.0", + "resolve-dir": "^0.1.0" + }, + "dependencies": { + "expand-tilde": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/expand-tilde/-/expand-tilde-1.2.2.tgz", + "integrity": "sha1-C4HrqJflo9MdHD0QL48BRB5VlEk=", + "dev": true, + "requires": { + "os-homedir": "^1.0.1" + } + }, + "global-modules": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/global-modules/-/global-modules-0.2.3.tgz", + "integrity": "sha1-6lo77ULG1s6ZWk+KEmm12uIjgo0=", + "dev": true, + "requires": { + "global-prefix": "^0.1.4", + "is-windows": "^0.2.0" + } + }, + "global-prefix": { + "version": "0.1.5", + "resolved": "https://registry.npmjs.org/global-prefix/-/global-prefix-0.1.5.tgz", + "integrity": "sha1-jTvGuNo8qBEqFg2NSW/wRiv+948=", + "dev": true, + "requires": { + "homedir-polyfill": "^1.0.0", + "ini": "^1.3.4", + "is-windows": "^0.2.0", + "which": "^1.2.12" + } + }, + "is-windows": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/is-windows/-/is-windows-0.2.0.tgz", + "integrity": "sha1-3hqm1j6indJIc3tp8f+LgALSEIw=", + "dev": true + }, + "resolve-dir": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/resolve-dir/-/resolve-dir-0.1.1.tgz", + "integrity": "sha1-shklmlYC+sXFxJatiUpujMQwJh4=", + "dev": true, + "requires": { + "expand-tilde": "^1.2.2", + "global-modules": "^0.2.3" + } + } + } + }, "find-index": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/find-index/-/find-index-0.1.1.tgz", "integrity": "sha1-Z101iyyjiS15Whq0cjL4tuLg3eQ=", "dev": true }, + "find-pkg": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/find-pkg/-/find-pkg-0.1.2.tgz", + "integrity": "sha1-G9wiwG42NlUy4qJIBGhUuXiNpVc=", + "dev": true, + "requires": { + "find-file-up": "^0.1.2" + } + }, + "find-process": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/find-process/-/find-process-1.4.1.tgz", + "integrity": "sha512-RkYWDeukxEoDKUyocqMGKAYuwhSwq77zL99gCqhX9czWon3otdlzihJ0MSZ6YWNKHyvS/MN2YR4+RGYOuIEANg==", + "dev": true, + "requires": { + "chalk": "^2.0.1", + "commander": "^2.11.0", + "debug": "^2.6.8" + } + }, "find-root": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/find-root/-/find-root-1.1.0.tgz", @@ -5117,6 +5251,12 @@ "js-yaml": "^3.4.6" } }, + "fs-exists-sync": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/fs-exists-sync/-/fs-exists-sync-0.1.0.tgz", + "integrity": "sha1-mC1ok6+RjnLQjeyehnP/K1qNat0=", + "dev": true + }, "fs-extra": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-2.1.2.tgz", @@ -6890,6 +7030,12 @@ "integrity": "sha512-l9sfDFsuqtOqKDsQdqrMRk0U85RZc0RtOR9yPI7mRVOa4FsR/BVnZ0shmQRM96Ji99kYZP/7hn1cedc1+ApsTQ==", "dev": true }, + "hoek": { + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/hoek/-/hoek-5.0.4.tgz", + "integrity": "sha512-Alr4ZQgoMlnere5FZJsIyfIjORBqZll5POhDsF4q64dPuJR6rNxXdDxtHSQq8OXRurhmx+PWYEE8bXRROY8h0w==", + "dev": true + }, "homedir-polyfill": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/homedir-polyfill/-/homedir-polyfill-1.0.3.tgz", @@ -7783,6 +7929,23 @@ "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", "dev": true }, + "isemail": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/isemail/-/isemail-3.2.0.tgz", + "integrity": "sha512-zKqkK+O+dGqevc93KNsbZ/TqTUFd46MwWjYOoMrjIMZ51eU7DtQG3Wmd9SQQT7i7RVnuTPEiYEWHU3MSbxC1Tg==", + "dev": true, + "requires": { + "punycode": "2.x.x" + }, + "dependencies": { + "punycode": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", + "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", + "dev": true + } + } + }, "isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -8330,6 +8493,58 @@ "realpath-native": "^1.1.0" } }, + "jest-dev-server": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/jest-dev-server/-/jest-dev-server-4.1.1.tgz", + "integrity": "sha512-VB/myFWW1q271FUWWbuTy/tWFTw1bQ8Gs5U/5I0h6p8vNJSs+nBivOJQNiOrc745ijh1ND0WMs1rDSmCCnh5Cg==", + "dev": true, + "requires": { + "chalk": "^2.4.2", + "cwd": "^0.10.0", + "find-process": "^1.4.1", + "prompts": "^2.0.4", + "spawnd": "^4.0.0", + "tree-kill": "^1.2.1", + "wait-on": "^3.2.0" + }, + "dependencies": { + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "requires": { + "color-convert": "^1.9.0" + } + }, + "chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "dev": true, + "requires": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + } + }, + "has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", + "dev": true + }, + "supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "requires": { + "has-flag": "^3.0.0" + } + } + } + }, "jest-diff": { "version": "24.7.0", "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-24.7.0.tgz", @@ -8535,6 +8750,55 @@ "jest-util": "^24.7.1" } }, + "jest-environment-puppeteer": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/jest-environment-puppeteer/-/jest-environment-puppeteer-4.1.1.tgz", + "integrity": "sha512-H+Wqxq4w9mFb0sBRGcbFIU02T+0YZbf/HKfQhwHvbam4UQqq7/n3kRkF0iYYlf76Jmys/H8rThtdh+HHxFgA5Q==", + "dev": true, + "requires": { + "chalk": "^2.4.2", + "cwd": "^0.10.0", + "jest-dev-server": "^4.1.1", + "merge-deep": "^3.0.2" + }, + "dependencies": { + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "requires": { + "color-convert": "^1.9.0" + } + }, + "chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "dev": true, + "requires": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + } + }, + "has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", + "dev": true + }, + "supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "requires": { + "has-flag": "^3.0.0" + } + } + } + }, "jest-get-type": { "version": "24.3.0", "resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-24.3.0.tgz", @@ -9253,6 +9517,16 @@ "integrity": "sha512-pgFw2tm54fzgYvc/OHrnysABEObZCUNFnhjoRjaVOCN8NYc032/gVjPaHD4Aq6ApkSieWtfKAFQtmDKAmhupnQ==", "dev": true }, + "jest-puppeteer": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/jest-puppeteer/-/jest-puppeteer-4.1.1.tgz", + "integrity": "sha512-nMZ8oUrmzp67UfPKXKmoEU1wLsZfPAhlOlLYHZSCb78eIkHmeP8tqSibhAMxH8BIQUHTsnAfel5z5AsGv2SzGQ==", + "dev": true, + "requires": { + "expect-puppeteer": "^4.1.1", + "jest-environment-puppeteer": "^4.1.1" + } + }, "jest-regex-util": { "version": "24.3.0", "resolved": "https://registry.npmjs.org/jest-regex-util/-/jest-regex-util-24.3.0.tgz", @@ -9746,6 +10020,17 @@ } } }, + "joi": { + "version": "13.7.0", + "resolved": "https://registry.npmjs.org/joi/-/joi-13.7.0.tgz", + "integrity": "sha512-xuY5VkHfeOYK3Hdi91ulocfuFopwgbSORmIwzcwHKESQhC7w1kD5jaVSPnqDxS2I8t3RZ9omCKAxNwXN5zG1/Q==", + "dev": true, + "requires": { + "hoek": "5.x.x", + "isemail": "3.x.x", + "topo": "3.x.x" + } + }, "js-base64": { "version": "2.4.3", "resolved": "https://registry.npmjs.org/js-base64/-/js-base64-2.4.3.tgz", @@ -10688,6 +10973,28 @@ "integrity": "sha512-VjFo4P5Whtj4vsLzsYBu5ayHhoHJ0UqNm7ibvShmbmoz7tGi0vXaoJbGdB+GmDMLUdg8DpQXEIeVDAe8MaABvQ==", "dev": true }, + "merge-deep": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/merge-deep/-/merge-deep-3.0.2.tgz", + "integrity": "sha512-T7qC8kg4Zoti1cFd8Cr0M+qaZfOwjlPDEdZIIPPB2JZctjaPM4fX+i7HOId69tAti2fvO6X5ldfYUONDODsrkA==", + "dev": true, + "requires": { + "arr-union": "^3.1.0", + "clone-deep": "^0.2.4", + "kind-of": "^3.0.2" + }, + "dependencies": { + "kind-of": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", + "integrity": "sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=", + "dev": true, + "requires": { + "is-buffer": "^1.1.5" + } + } + } + }, "merge-descriptors": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", @@ -10879,6 +11186,24 @@ } } }, + "mixin-object": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/mixin-object/-/mixin-object-2.0.1.tgz", + "integrity": "sha1-T7lJRB2rGCVA8f4DW6YOGUel5X4=", + "dev": true, + "requires": { + "for-in": "^0.1.3", + "is-extendable": "^0.1.1" + }, + "dependencies": { + "for-in": { + "version": "0.1.8", + "resolved": "https://registry.npmjs.org/for-in/-/for-in-0.1.8.tgz", + "integrity": "sha1-2Hc5COMSVhCZUrH9ubP6hn0ndeE=", + "dev": true + } + } + }, "mkdirp": { "version": "0.5.1", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", @@ -14947,6 +15272,12 @@ "integrity": "sha512-DEqnSRTDw/Tc3FXf49zedI638Z9onwUotBMiUFKmrO2sdFKIbXamXGQ3Axd4qgphxKB4kw/qP1w5kTxnfU1B9Q==", "dev": true }, + "rx": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/rx/-/rx-4.1.0.tgz", + "integrity": "sha1-pfE/957zt0D+MKqAP7CfmIBdR4I=", + "dev": true + }, "rx-lite": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/rx-lite/-/rx-lite-3.1.2.tgz", @@ -16132,6 +16463,35 @@ "integrity": "sha1-0L2FU2iHtv58DYGMuWLZ2RxU5lY=", "dev": true }, + "shallow-clone": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/shallow-clone/-/shallow-clone-0.1.2.tgz", + "integrity": "sha1-WQnodLp3EG1zrEFM/sH/yofZcGA=", + "dev": true, + "requires": { + "is-extendable": "^0.1.1", + "kind-of": "^2.0.1", + "lazy-cache": "^0.2.3", + "mixin-object": "^2.0.1" + }, + "dependencies": { + "kind-of": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-2.0.1.tgz", + "integrity": "sha1-AY7HpM5+OobLkUG+UZ0kyPqpgbU=", + "dev": true, + "requires": { + "is-buffer": "^1.0.2" + } + }, + "lazy-cache": { + "version": "0.2.7", + "resolved": "https://registry.npmjs.org/lazy-cache/-/lazy-cache-0.2.7.tgz", + "integrity": "sha1-f+3fLctu23fRHvHRF6tf/fCrG2U=", + "dev": true + } + } + }, "shebang-command": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", @@ -16375,6 +16735,18 @@ "integrity": "sha1-Gsu/tZJDbRC76PeFt8xvgoFQEsM=", "dev": true }, + "spawnd": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/spawnd/-/spawnd-4.0.0.tgz", + "integrity": "sha512-ql3qhJnhAkvXpaqKBWOqou1rUTSQhFRaZkyOT+MTFB4xY3X+brgw6LTWV2wHuE9A6YPhrNe1cbg7S+jAYnbC0Q==", + "dev": true, + "requires": { + "exit": "^0.1.2", + "signal-exit": "^3.0.2", + "tree-kill": "^1.2.1", + "wait-port": "^0.2.2" + } + }, "spdx-correct": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-1.0.2.tgz", @@ -17705,6 +18077,23 @@ "through2": "^2.0.3" } }, + "topo": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/topo/-/topo-3.0.3.tgz", + "integrity": "sha512-IgpPtvD4kjrJ7CRA3ov2FhWQADwv+Tdqbsf1ZnPUSAtCJ9e1Z44MmoSGDXGk4IppoZA7jd/QRkNddlLJWlUZsQ==", + "dev": true, + "requires": { + "hoek": "6.x.x" + }, + "dependencies": { + "hoek": { + "version": "6.1.3", + "resolved": "https://registry.npmjs.org/hoek/-/hoek-6.1.3.tgz", + "integrity": "sha512-YXXAAhmF9zpQbC7LEcREFtXfGq5K1fmd+4PHkBq8NUqmzW3G+Dq10bI/i0KucLRwss3YYFQ0fSfoxBZYiGUqtQ==", + "dev": true + } + } + }, "touch": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/touch/-/touch-3.1.0.tgz", @@ -17740,6 +18129,12 @@ "integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=", "dev": true }, + "tree-kill": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/tree-kill/-/tree-kill-1.2.1.tgz", + "integrity": "sha512-4hjqbObwlh2dLyW4tcz0Ymw0ggoaVDMveUB9w8kFSQScdRLo0gxO9J7WFcUBo+W3C1TLdFIEwNOWebgZZ0RH9Q==", + "dev": true + }, "trim-newlines": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/trim-newlines/-/trim-newlines-1.0.0.tgz", @@ -18471,6 +18866,65 @@ "browser-process-hrtime": "^0.1.2" } }, + "wait-on": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/wait-on/-/wait-on-3.2.0.tgz", + "integrity": "sha512-QUGNKlKLDyY6W/qHdxaRlXUAgLPe+3mLL/tRByHpRNcHs/c7dZXbu+OnJWGNux6tU1WFh/Z8aEwvbuzSAu79Zg==", + "dev": true, + "requires": { + "core-js": "^2.5.7", + "joi": "^13.0.0", + "minimist": "^1.2.0", + "request": "^2.88.0", + "rx": "^4.1.0" + }, + "dependencies": { + "core-js": { + "version": "2.6.5", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.5.tgz", + "integrity": "sha512-klh/kDpwX8hryYL14M9w/xei6vrv6sE8gTHDG7/T/+SEovB/G4ejwcfE/CBzO6Edsu+OETZMZ3wcX/EjUkrl5A==", + "dev": true + }, + "minimist": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", + "dev": true + } + } + }, + "wait-port": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/wait-port/-/wait-port-0.2.2.tgz", + "integrity": "sha1-1RpJHkhKF791qUfnEaLwErTm8uM=", + "dev": true, + "requires": { + "chalk": "^1.1.3", + "commander": "^2.9.0", + "debug": "^2.6.6" + }, + "dependencies": { + "ansi-styles": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", + "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", + "dev": true + }, + "chalk": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", + "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", + "dev": true, + "requires": { + "ansi-styles": "^2.2.1", + "escape-string-regexp": "^1.0.2", + "has-ansi": "^2.0.0", + "strip-ansi": "^3.0.0", + "supports-color": "^2.0.0" + } + } + } + }, "walker": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/walker/-/walker-1.0.7.tgz", diff --git a/package.json b/package.json index 6c7c7c946c..328b96ca40 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "html5shiv": "^3.7.3", "jest": "^24.7.1", "jest-axe": "^3.1.1", + "jest-puppeteer": "^4.1.1", "jest-serializer-html": "^6.0.0", "js-yaml": "^3.13.1", "map-stream": "0.0.7", @@ -88,6 +89,12 @@ "iOS >= 9" ], "standard": { + "globals": [ + "page", + "browser", + "context", + "jestPuppeteer" + ], "ignore": [ "/dist/**/*.js", "/package/**/*.js", @@ -95,13 +102,12 @@ ] }, "jest": { + "preset": "jest-puppeteer", "setupFilesAfterEnv": [ "./config/jest-setup.js" ], "snapshotSerializers": [ "jest-serializer-html" - ], - "globalSetup": "./lib/puppeteer/setup.js", - "globalTeardown": "./lib/puppeteer/teardown.js" + ] } } diff --git a/src/all.test.js b/src/all.test.js index 6e2c1834b1..b88f5f6b4c 100644 --- a/src/all.test.js +++ b/src/all.test.js @@ -1,6 +1,3 @@ -/** - * @jest-environment ./lib/puppeteer/environment.js - */ /* eslint-env jest */ const util = require('util') @@ -15,14 +12,9 @@ const sassConfig = { includePaths: [ configPaths.src ] } -let browser -let page let baseUrl = 'http://localhost:' + PORT beforeAll(async (done) => { - browser = global.__BROWSER__ - page = await browser.newPage() - // Capture JavaScript errors. page.on('pageerror', error => { // If the stack trace includes 'all.js' then we want to fail these tests. @@ -33,11 +25,6 @@ beforeAll(async (done) => { done() }) -afterAll(async (done) => { - await page.close() - done() -}) - describe('GOV.UK Frontend', () => { describe('javascript', () => { it('can be accessed via `GOVUKFrontend`', async () => { diff --git a/src/components/accordion/accordion.test.js b/src/components/accordion/accordion.test.js index 7611e02c0c..b8a440ff0c 100644 --- a/src/components/accordion/accordion.test.js +++ b/src/components/accordion/accordion.test.js @@ -1,6 +1,3 @@ -/** - * @jest-environment ./lib/puppeteer/environment.js - */ /* eslint-env jest */ // const devices = require('puppeteer/DeviceDescriptors') @@ -9,26 +6,20 @@ const configPaths = require('../../../config/paths.json') const PORT = configPaths.ports.test -let browser -let page let baseUrl = 'http://localhost:' + PORT -beforeAll(async (done) => { - browser = global.__BROWSER__ - page = await browser.newPage() - done() -}) - -afterAll(async (done) => { - await page.close() - done() -}) - describe('/components/accordion', () => { describe('/components/accordion/preview', () => { describe('when JavaScript is unavailable or fails', () => { - it('falls back to making all accordion sections visible', async () => { + beforeAll(async () => { await page.setJavaScriptEnabled(false) + }) + + afterAll(async () => { + await page.setJavaScriptEnabled(true) + }) + + it('falls back to making all accordion sections visible', async () => { await page.goto(baseUrl + '/components/accordion/preview', { waitUntil: 'load' }) const numberOfExampleSections = 2 @@ -42,7 +33,6 @@ describe('/components/accordion', () => { }) it('does not display "+/-" in the section headings', async () => { - await page.setJavaScriptEnabled(false) await page.goto(baseUrl + '/components/accordion/preview', { waitUntil: 'load' }) const numberOfIcons = await page.evaluate(() => document.body.querySelectorAll('.govuk-accordion .govuk-accordion__section .govuk-accordion__icon').length) @@ -52,7 +42,6 @@ describe('/components/accordion', () => { describe('when JavaScript is available', () => { it('should indicate that the sections are not expanded', async () => { - await page.setJavaScriptEnabled(true) await page.goto(baseUrl + '/components/accordion/preview', { waitUntil: 'load' }) const numberOfExampleSections = 2 @@ -93,7 +82,6 @@ describe('/components/accordion', () => { }) it('should already have all sections open if they have the expanded class', async () => { - await page.setJavaScriptEnabled(true) await page.goto(baseUrl + '/components/accordion/with-all-sections-already-open/preview', { waitUntil: 'load' }) const numberOfExampleSections = 2 @@ -135,7 +123,6 @@ describe('/components/accordion', () => { describe('"+/-" icon', () => { it('should display "+/-" in the section headings', async () => { - await page.setJavaScriptEnabled(true) await page.goto(baseUrl + '/components/accordion/preview', { waitUntil: 'load' }) const numberOfExampleSections = 2 diff --git a/src/components/accordion/template.test.js b/src/components/accordion/template.test.js index 153b3d1749..7ff6fa97c4 100644 --- a/src/components/accordion/template.test.js +++ b/src/components/accordion/template.test.js @@ -1,3 +1,6 @@ +/** + * @jest-environment jsdom + */ /* eslint-env jest */ const { axe } = require('jest-axe') diff --git a/src/components/back-link/template.test.js b/src/components/back-link/template.test.js index a3a69c5d61..2e25b804ba 100644 --- a/src/components/back-link/template.test.js +++ b/src/components/back-link/template.test.js @@ -1,3 +1,6 @@ +/** + * @jest-environment jsdom + */ /* eslint-env jest */ const axe = require('../../../lib/axe-helper') diff --git a/src/components/breadcrumbs/template.test.js b/src/components/breadcrumbs/template.test.js index dd2b20a2b7..e7da920462 100644 --- a/src/components/breadcrumbs/template.test.js +++ b/src/components/breadcrumbs/template.test.js @@ -1,3 +1,6 @@ +/** + * @jest-environment jsdom + */ /* eslint-env jest */ const axe = require('../../../lib/axe-helper') diff --git a/src/components/button/button.test.js b/src/components/button/button.test.js index 739bb7b1b3..aaa99215a9 100644 --- a/src/components/button/button.test.js +++ b/src/components/button/button.test.js @@ -1,26 +1,10 @@ -/** - * @jest-environment ./lib/puppeteer/environment.js - */ /* eslint-env jest */ const configPaths = require('../../../config/paths.json') const PORT = configPaths.ports.test -let browser -let page let baseUrl = 'http://localhost:' + PORT -beforeAll(async (done) => { - browser = global.__BROWSER__ - page = await browser.newPage() - done() -}) - -afterAll(async (done) => { - await page.close() - done() -}) - describe('/components/button', () => { describe('/components/button/link', () => { it('triggers the click event when the space key is pressed', async () => { diff --git a/src/components/button/template.test.js b/src/components/button/template.test.js index 0e2b161079..72b51fda2d 100644 --- a/src/components/button/template.test.js +++ b/src/components/button/template.test.js @@ -1,3 +1,6 @@ +/** + * @jest-environment jsdom + */ /* eslint-env jest */ const axe = require('../../../lib/axe-helper') diff --git a/src/components/character-count/character-count.test.js b/src/components/character-count/character-count.test.js index ead14b4711..932e2bf388 100644 --- a/src/components/character-count/character-count.test.js +++ b/src/components/character-count/character-count.test.js @@ -1,24 +1,9 @@ -/** - * @jest-environment ./lib/puppeteer/environment.js - */ /* eslint-env jest */ const configPaths = require('../../../config/paths.json') const PORT = configPaths.ports.test const baseUrl = `http://localhost:${PORT}` -let browser -let page - -beforeAll(async () => { - browser = global.__BROWSER__ - page = await browser.newPage() -}) - -afterAll(async () => { - await page.close() -}) - const goToExample = (exampleName = false) => { let url = exampleName ? `${baseUrl}/components/character-count/${exampleName}/preview` diff --git a/src/components/character-count/template.test.js b/src/components/character-count/template.test.js index 5f7a29d612..cad7282a08 100644 --- a/src/components/character-count/template.test.js +++ b/src/components/character-count/template.test.js @@ -1,3 +1,6 @@ +/** + * @jest-environment jsdom + */ /* eslint-env jest */ const { axe } = require('jest-axe') diff --git a/src/components/checkboxes/checkboxes.test.js b/src/components/checkboxes/checkboxes.test.js index 34fed92ad2..0c55073d13 100644 --- a/src/components/checkboxes/checkboxes.test.js +++ b/src/components/checkboxes/checkboxes.test.js @@ -1,6 +1,3 @@ -/** - * @jest-environment ./lib/puppeteer/environment.js - */ /* eslint-env jest */ const cheerio = require('cheerio') @@ -8,8 +5,6 @@ const cheerio = require('cheerio') const configPaths = require('../../../config/paths.json') const PORT = configPaths.ports.test -let browser -let page let baseUrl = 'http://localhost:' + PORT const goToAndGetComponent = async (name, example) => { @@ -34,20 +29,17 @@ const waitForVisibleSelector = async (selector) => { }) } -beforeEach(async () => { - browser = global.__BROWSER__ - page = await browser.newPage() -}) - -afterEach(async () => { - await page.close() -}) - describe('Checkboxes with conditional reveals', () => { describe('when JavaScript is unavailable or fails', () => { - it('has no ARIA attributes applied', async () => { + beforeAll(async () => { await page.setJavaScriptEnabled(false) + }) + afterAll(async () => { + await page.setJavaScriptEnabled(true) + }) + + it('has no ARIA attributes applied', async () => { const $ = await goToAndGetComponent('checkboxes', 'with-conditional-items') const $component = $('.govuk-checkboxes') @@ -58,8 +50,6 @@ describe('Checkboxes with conditional reveals', () => { expect(hasAriaControls).toBeFalsy() }) it('falls back to making all conditional content visible', async () => { - await page.setJavaScriptEnabled(false) - await goToAndGetComponent('checkboxes', 'with-conditional-items') const isContentVisible = await waitForVisibleSelector('.govuk-checkboxes__conditional') diff --git a/src/components/checkboxes/template.test.js b/src/components/checkboxes/template.test.js index e18b3e3873..a32b3a0fc2 100644 --- a/src/components/checkboxes/template.test.js +++ b/src/components/checkboxes/template.test.js @@ -1,3 +1,6 @@ +/** + * @jest-environment jsdom + */ /* eslint-env jest */ const axe = require('../../../lib/axe-helper') diff --git a/src/components/date-input/template.test.js b/src/components/date-input/template.test.js index 49805fd92b..09a8ac99b8 100644 --- a/src/components/date-input/template.test.js +++ b/src/components/date-input/template.test.js @@ -1,3 +1,6 @@ +/** + * @jest-environment jsdom + */ /* eslint-env jest */ const axe = require('../../../lib/axe-helper') diff --git a/src/components/details/details.test.js b/src/components/details/details.test.js index e4459a7474..c8c323dfd7 100644 --- a/src/components/details/details.test.js +++ b/src/components/details/details.test.js @@ -1,26 +1,10 @@ -/** - * @jest-environment ./lib/puppeteer/environment.js - */ /* eslint-env jest */ const configPaths = require('../../../config/paths.json') const PORT = configPaths.ports.test -let browser -let page let baseUrl = 'http://localhost:' + PORT -beforeAll(async (done) => { - browser = global.__BROWSER__ - page = await browser.newPage() - done() -}) - -afterAll(async (done) => { - await page.close() - done() -}) - describe('/components/details', () => { describe('/components/details/preview', () => { it('should add to summary the button role', async () => { diff --git a/src/components/details/template.test.js b/src/components/details/template.test.js index 76cf160a73..fa4e20a3fe 100644 --- a/src/components/details/template.test.js +++ b/src/components/details/template.test.js @@ -1,3 +1,6 @@ +/** + * @jest-environment jsdom + */ /* eslint-env jest */ const axe = require('../../../lib/axe-helper') diff --git a/src/components/error-message/template.test.js b/src/components/error-message/template.test.js index 16eab9b3c0..6acc64d8f3 100644 --- a/src/components/error-message/template.test.js +++ b/src/components/error-message/template.test.js @@ -1,3 +1,6 @@ +/** + * @jest-environment jsdom + */ /* eslint-env jest */ const axe = require('../../../lib/axe-helper') diff --git a/src/components/error-summary/error-summary.test.js b/src/components/error-summary/error-summary.test.js index 57b861b282..73bc06f68b 100644 --- a/src/components/error-summary/error-summary.test.js +++ b/src/components/error-summary/error-summary.test.js @@ -1,26 +1,10 @@ -/** - * @jest-environment ./lib/puppeteer/environment.js - */ /* eslint-env jest */ const configPaths = require('../../../config/paths.json') const PORT = configPaths.ports.test -let browser -let page let baseUrl = 'http://localhost:' + PORT -beforeAll(async (done) => { - browser = global.__BROWSER__ - page = await browser.newPage() - done() -}) - -afterAll(async (done) => { - await page.close() - done() -}) - describe('Error Summary', () => { it('is automatically focused when the page loads', async () => { await page.goto(`${baseUrl}/components/error-summary/preview`, { waitUntil: 'load' }) diff --git a/src/components/error-summary/template.test.js b/src/components/error-summary/template.test.js index 76bb66d0d5..c41b3286b6 100644 --- a/src/components/error-summary/template.test.js +++ b/src/components/error-summary/template.test.js @@ -1,3 +1,6 @@ +/** + * @jest-environment jsdom + */ /* eslint-env jest */ const axe = require('../../../lib/axe-helper') diff --git a/src/components/fieldset/template.test.js b/src/components/fieldset/template.test.js index 51cffb8a5d..7c6ee6096d 100644 --- a/src/components/fieldset/template.test.js +++ b/src/components/fieldset/template.test.js @@ -1,3 +1,6 @@ +/** + * @jest-environment jsdom + */ /* eslint-env jest */ const axe = require('../../../lib/axe-helper') diff --git a/src/components/file-upload/template.test.js b/src/components/file-upload/template.test.js index db94b0505c..ac3b2c0546 100644 --- a/src/components/file-upload/template.test.js +++ b/src/components/file-upload/template.test.js @@ -1,3 +1,6 @@ +/** + * @jest-environment jsdom + */ /* eslint-env jest */ const axe = require('../../../lib/axe-helper') diff --git a/src/components/footer/template.test.js b/src/components/footer/template.test.js index f2b258a412..7376bbd2ae 100644 --- a/src/components/footer/template.test.js +++ b/src/components/footer/template.test.js @@ -1,3 +1,6 @@ +/** + * @jest-environment jsdom + */ /* eslint-env jest */ const axe = require('../../../lib/axe-helper') diff --git a/src/components/header/header.test.js b/src/components/header/header.test.js index 25d7aeabe0..2113e70ee1 100644 --- a/src/components/header/header.test.js +++ b/src/components/header/header.test.js @@ -1,6 +1,3 @@ -/** - * @jest-environment ./lib/puppeteer/environment.js - */ /* eslint-env jest */ const devices = require('puppeteer/DeviceDescriptors') @@ -8,27 +5,25 @@ const iPhone = devices['iPhone 6'] const configPaths = require('../../../config/paths.json') const PORT = configPaths.ports.test -let browser -let page let baseUrl = 'http://localhost:' + PORT beforeAll(async (done) => { - browser = global.__BROWSER__ - page = await browser.newPage() await page.emulate(iPhone) done() }) -afterAll(async (done) => { - await page.close() - done() -}) - describe('/components/header', () => { describe('/components/header/with-navigation/preview', () => { describe('when JavaScript is unavailable or fails', () => { - it('falls back to making the navigation visible', async () => { + beforeAll(async () => { await page.setJavaScriptEnabled(false) + }) + + afterAll(async () => { + await page.setJavaScriptEnabled(true) + }) + + it('falls back to making the navigation visible', async () => { await page.goto(baseUrl + '/components/header/with-navigation/preview', { waitUntil: 'load' }) const isContentVisible = await page.waitForSelector('.govuk-header__navigation', { visible: true, timeout: 1000 }) expect(isContentVisible).toBeTruthy() @@ -38,7 +33,6 @@ describe('/components/header', () => { describe('when JavaScript is available', () => { describe('when menu button is pressed', () => { it('should indicate the open state of the toggle button', async () => { - await page.setJavaScriptEnabled(true) await page.goto(baseUrl + '/components/header/with-navigation/preview', { waitUntil: 'load' }) await page.click('.js-header-toggle') diff --git a/src/components/header/template.test.js b/src/components/header/template.test.js index 5f3b10cb62..ce0854ea67 100644 --- a/src/components/header/template.test.js +++ b/src/components/header/template.test.js @@ -1,3 +1,6 @@ +/** + * @jest-environment jsdom + */ /* eslint-env jest */ const axe = require('../../../lib/axe-helper') diff --git a/src/components/hint/template.test.js b/src/components/hint/template.test.js index f54cf33252..3dc399b987 100644 --- a/src/components/hint/template.test.js +++ b/src/components/hint/template.test.js @@ -1,3 +1,6 @@ +/** + * @jest-environment jsdom + */ /* eslint-env jest */ const axe = require('../../../lib/axe-helper') diff --git a/src/components/input/template.test.js b/src/components/input/template.test.js index 50b66537ae..1a0469f687 100644 --- a/src/components/input/template.test.js +++ b/src/components/input/template.test.js @@ -1,3 +1,6 @@ +/** + * @jest-environment jsdom + */ /* eslint-env jest */ const axe = require('../../../lib/axe-helper') diff --git a/src/components/inset-text/template.test.js b/src/components/inset-text/template.test.js index b743425bbb..5afca296b9 100644 --- a/src/components/inset-text/template.test.js +++ b/src/components/inset-text/template.test.js @@ -1,3 +1,6 @@ +/** + * @jest-environment jsdom + */ /* eslint-env jest */ const axe = require('../../../lib/axe-helper') diff --git a/src/components/label/template.test.js b/src/components/label/template.test.js index c7d8efac1b..44b54df707 100644 --- a/src/components/label/template.test.js +++ b/src/components/label/template.test.js @@ -1,3 +1,6 @@ +/** + * @jest-environment jsdom + */ /* eslint-env jest */ const axe = require('../../../lib/axe-helper') diff --git a/src/components/panel/template.test.js b/src/components/panel/template.test.js index f138fbe086..d0fbe5e793 100644 --- a/src/components/panel/template.test.js +++ b/src/components/panel/template.test.js @@ -1,3 +1,6 @@ +/** + * @jest-environment jsdom + */ /* eslint-env jest */ const axe = require('../../../lib/axe-helper') diff --git a/src/components/phase-banner/template.test.js b/src/components/phase-banner/template.test.js index a9be19b697..63ec3d00b5 100644 --- a/src/components/phase-banner/template.test.js +++ b/src/components/phase-banner/template.test.js @@ -1,3 +1,6 @@ +/** + * @jest-environment jsdom + */ /* eslint-env jest */ const axe = require('../../../lib/axe-helper') diff --git a/src/components/radios/radios.test.js b/src/components/radios/radios.test.js index da8f2bac28..0f4a64db0d 100644 --- a/src/components/radios/radios.test.js +++ b/src/components/radios/radios.test.js @@ -1,6 +1,3 @@ -/** - * @jest-environment ./lib/puppeteer/environment.js - */ /* eslint-env jest */ const cheerio = require('cheerio') @@ -8,8 +5,6 @@ const cheerio = require('cheerio') const configPaths = require('../../../config/paths.json') const PORT = configPaths.ports.test -let browser -let page let baseUrl = 'http://localhost:' + PORT const goToAndGetComponent = async (name, example) => { @@ -34,20 +29,17 @@ const waitForVisibleSelector = async (selector) => { }) } -beforeEach(async () => { - browser = global.__BROWSER__ - page = await browser.newPage() -}) - -afterEach(async () => { - await page.close() -}) - describe('Radios with conditional reveals', () => { describe('when JavaScript is unavailable or fails', () => { - it('has no ARIA attributes applied', async () => { + beforeAll(async () => { await page.setJavaScriptEnabled(false) + }) + afterAll(async () => { + await page.setJavaScriptEnabled(true) + }) + + it('has no ARIA attributes applied', async () => { const $ = await goToAndGetComponent('radios', 'with-conditional-items') const $component = $('.govuk-radios') @@ -58,8 +50,6 @@ describe('Radios with conditional reveals', () => { expect(hasAriaControls).toBeFalsy() }) it('falls back to making all conditional content visible', async () => { - await page.setJavaScriptEnabled(false) - await goToAndGetComponent('radios', 'with-conditional-items') const isContentVisible = await waitForVisibleSelector('.govuk-radios__conditional') diff --git a/src/components/radios/template.test.js b/src/components/radios/template.test.js index 201a613f0b..8cf313475d 100644 --- a/src/components/radios/template.test.js +++ b/src/components/radios/template.test.js @@ -1,3 +1,6 @@ +/** + * @jest-environment jsdom + */ /* eslint-env jest */ const axe = require('../../../lib/axe-helper') diff --git a/src/components/select/template.test.js b/src/components/select/template.test.js index 134a08a957..7ac482722a 100644 --- a/src/components/select/template.test.js +++ b/src/components/select/template.test.js @@ -1,3 +1,6 @@ +/** + * @jest-environment jsdom + */ /* eslint-env jest */ const axe = require('../../../lib/axe-helper') diff --git a/src/components/skip-link/template.test.js b/src/components/skip-link/template.test.js index 0635a2c632..b2be094ab0 100644 --- a/src/components/skip-link/template.test.js +++ b/src/components/skip-link/template.test.js @@ -1,3 +1,6 @@ +/** + * @jest-environment jsdom + */ /* eslint-env jest */ const axe = require('../../../lib/axe-helper') diff --git a/src/components/summary-list/template.test.js b/src/components/summary-list/template.test.js index 1d3b1d9df8..49a482be50 100644 --- a/src/components/summary-list/template.test.js +++ b/src/components/summary-list/template.test.js @@ -1,3 +1,6 @@ +/** + * @jest-environment jsdom + */ /* eslint-env jest */ const axe = require('../../../lib/axe-helper') diff --git a/src/components/table/template.test.js b/src/components/table/template.test.js index 96378e7f5e..3e4fd8dd07 100644 --- a/src/components/table/template.test.js +++ b/src/components/table/template.test.js @@ -1,3 +1,6 @@ +/** + * @jest-environment jsdom + */ /* eslint-env jest */ const axe = require('../../../lib/axe-helper') diff --git a/src/components/tabs/tabs.test.js b/src/components/tabs/tabs.test.js index 387e53e022..9221010472 100644 --- a/src/components/tabs/tabs.test.js +++ b/src/components/tabs/tabs.test.js @@ -1,6 +1,3 @@ -/** - * @jest-environment ./lib/puppeteer/environment.js - */ /* eslint-env jest */ const devices = require('puppeteer/DeviceDescriptors') @@ -9,26 +6,20 @@ const iPhone = devices['iPhone 6'] const configPaths = require('../../../config/paths.json') const PORT = configPaths.ports.test -let browser -let page let baseUrl = 'http://localhost:' + PORT -beforeAll(async (done) => { - browser = global.__BROWSER__ - page = await browser.newPage() - done() -}) - -afterAll(async (done) => { - await page.close() - done() -}) - describe('/components/tabs', () => { describe('/components/tabs/preview', () => { describe('when JavaScript is unavailable or fails', () => { - it('falls back to making all tab containers visible', async () => { + beforeAll(async () => { await page.setJavaScriptEnabled(false) + }) + + afterAll(async () => { + await page.setJavaScriptEnabled(true) + }) + + it('falls back to making all tab containers visible', async () => { await page.goto(baseUrl + '/components/tabs/preview', { waitUntil: 'load' }) const isContentVisible = await page.waitForSelector('.govuk-tabs__panel', { visible: true, timeout: 1000 }) expect(isContentVisible).toBeTruthy() @@ -37,7 +28,6 @@ describe('/components/tabs', () => { describe('when JavaScript is available', () => { it('should indicate the open state of the first tab', async () => { - await page.setJavaScriptEnabled(true) await page.goto(baseUrl + '/components/tabs/preview', { waitUntil: 'load' }) const firstTabAriaSelected = await page.evaluate(() => document.body.querySelector('.govuk-tabs__list-item:first-child .govuk-tabs__tab').getAttribute('aria-selected')) diff --git a/src/components/tabs/template.test.js b/src/components/tabs/template.test.js index 312c841739..a685730b6d 100644 --- a/src/components/tabs/template.test.js +++ b/src/components/tabs/template.test.js @@ -1,3 +1,6 @@ +/** + * @jest-environment jsdom + */ /* eslint-env jest */ const axe = require('../../../lib/axe-helper') diff --git a/src/components/tag/template.test.js b/src/components/tag/template.test.js index 6b0ea32b6c..f1096c70b1 100644 --- a/src/components/tag/template.test.js +++ b/src/components/tag/template.test.js @@ -1,3 +1,6 @@ +/** + * @jest-environment jsdom + */ /* eslint-env jest */ const axe = require('../../../lib/axe-helper') diff --git a/src/components/textarea/template.test.js b/src/components/textarea/template.test.js index b00dcb4922..2f2747b574 100644 --- a/src/components/textarea/template.test.js +++ b/src/components/textarea/template.test.js @@ -1,3 +1,6 @@ +/** + * @jest-environment jsdom + */ /* eslint-env jest */ const axe = require('../../../lib/axe-helper') diff --git a/src/components/warning-text/template.test.js b/src/components/warning-text/template.test.js index 03f753402a..7801b65824 100644 --- a/src/components/warning-text/template.test.js +++ b/src/components/warning-text/template.test.js @@ -1,3 +1,6 @@ +/** + * @jest-environment jsdom + */ /* eslint-env jest */ const axe = require('../../../lib/axe-helper')