diff --git a/config/jest-puppeteer.rollup.config.js b/config/jest-puppeteer.rollup.config.js index b036eab..177cf2b 100644 --- a/config/jest-puppeteer.rollup.config.js +++ b/config/jest-puppeteer.rollup.config.js @@ -1,4 +1,8 @@ +const path = require('path'); + module.exports = { + port: 8080, + root: path.join(__dirname, '../'), build: '.build', html: { input: 'index.html', @@ -8,4 +12,8 @@ module.exports = { input: 'index.browser', output: 'build', }, + dev: { + servePort: 18080, + livereloadPort: 28080, + }, }; diff --git a/config/jest-puppeteer.rollup.js b/config/jest-puppeteer.rollup.js index cc20c26..d0b1ebd 100644 --- a/config/jest-puppeteer.rollup.js +++ b/config/jest-puppeteer.rollup.js @@ -181,15 +181,14 @@ const setupRollupTest = async (rootDir, testPath, cacheDir, watch) => { rollupPluginServe({ contentBase: dist, historyApiFallback: `/${deploymentConfig.html.output}`, - port: 18080, + port: deploymentConfig.dev.servePort, onListening(server) { rollupServers.push(server); }, }), rollupPluginLivereload({ watch: dist, - verbose: true, - port: 28080, + port: deploymentConfig.dev.livereloadPort, }), ] : []), diff --git a/config/jest-test-server.js b/config/jest-test-server.js index ef9437f..8404adb 100644 --- a/config/jest-test-server.js +++ b/config/jest-test-server.js @@ -1,8 +1,7 @@ -const path = require('path'); const express = require('express'); +const deploymentConfig = require('./jest-puppeteer.rollup.config.js'); const app = express(); -app.use(express.static(path.join(__dirname, '../'))); - -app.listen(process.env.TEST_SERVER_PORT); +app.use(express.static(deploymentConfig.root)); +app.listen(deploymentConfig.port); diff --git a/config/jest-test-server.loader.js b/config/jest-test-server.loader.js index 880ea4b..33288d3 100644 --- a/config/jest-test-server.loader.js +++ b/config/jest-test-server.loader.js @@ -1,10 +1,10 @@ const path = require('path'); -const jestPuppeteerConfig = require('../jest-puppeteer.config.base'); +const deploymentConfig = require('./jest-puppeteer.rollup.config.js'); module.exports = { - process: (src, filePath, config) => { - const deploymentPath = path.relative(path.dirname(config.globals.baseConfig), filePath); + process: (src, filePath) => { + const deploymentPath = path.relative(deploymentConfig.root, filePath); const split = deploymentPath.split(path.sep); - return `module.exports = ${JSON.stringify(`http://localhost:${jestPuppeteerConfig.server.port}/${path.posix.join(...split)}`)}`; + return `module.exports = ${JSON.stringify(`http://localhost:${deploymentConfig.port}/${path.posix.join(...split)}`)}`; }, }; diff --git a/jest-puppeteer.config.base.js b/jest-puppeteer.config.base.js index 25cad94..2d78967 100644 --- a/jest-puppeteer.config.base.js +++ b/jest-puppeteer.config.base.js @@ -1,11 +1,8 @@ const path = require('path'); -const { TEST_SERVER_PORT } = process.env; -const port = TEST_SERVER_PORT ? Number(TEST_SERVER_PORT) : 8080; +const deploymentConfig = path.resolve(__dirname, './config/jest-puppeteer.rollup.config.js'); const testServerPath = path.resolve(__dirname, './config/jest-test-server.js'); -process.env.TEST_SERVER_PORT = port; - module.exports = { browser: 'chromium', browserContext: 'incognito', @@ -13,8 +10,8 @@ module.exports = { headless: false, }, server: { - command: `cross-env TEST_SERVER_PORT=${port} node ${testServerPath}`, - port, + command: `node ${testServerPath}`, + port: deploymentConfig.port, launchTimeout: 10000, }, }; diff --git a/jest.config.base.js b/jest.config.base.js index 06585ba..da31d49 100644 --- a/jest.config.base.js +++ b/jest.config.base.js @@ -2,9 +2,9 @@ const path = require('path'); const resolve = require('./resolve.config'); const puppeteerRollupConfig = require('./config/jest-puppeteer.rollup.config.js'); -const testEnvironmentPath = path.resolve(__dirname, './config/jest-puppeteer.env.js'); const testServerLoaderPath = path.resolve(__dirname, './config/jest-test-server.loader.js'); const jsdomSetupFile = path.resolve(__dirname, './config/jest-jsdom.setup.js'); +const puppeteerTestEnvironmentPath = path.resolve(__dirname, './config/jest-puppeteer.env.js'); const puppeteerSetupFile = path.resolve(__dirname, './config/jest-puppeteer.setup.js'); // For a detailed explanation regarding each configuration property, visit: @@ -17,9 +17,6 @@ const base = { moduleDirectories: resolve.directories, moduleFileExtensions: resolve.extensions.map((ext) => ext.replace(/\./, '')), testPathIgnorePatterns: ['\\\\node_modules\\\\'], - globals: { - baseConfig: __filename, - }, }; const pptrBase = { @@ -27,7 +24,7 @@ const pptrBase = { preset: 'jest-puppeteer', setupFilesAfterEnv: ['expect-puppeteer', puppeteerSetupFile], testMatch: ['**/tests/puppeteer/**/*.test.[jt]s?(x)'], - testEnvironment: testEnvironmentPath, + testEnvironment: puppeteerTestEnvironmentPath, coveragePathIgnorePatterns: ['/node_modules/', `/${puppeteerRollupConfig.build}/`], transform: { '^.+\\.[jt]sx?$': 'babel-jest', diff --git a/package.json b/package.json index 90ad517..48fe33a 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,6 @@ "bufferutil": "^4.0.1", "canvas": "^2.6.1", "core-js": "^3.6.5", - "cross-env": "^7.0.2", "del": "^5.1.0", "eslint": "^7.5.0", "eslint-config-airbnb": "^18.2.0", diff --git a/yarn.lock b/yarn.lock index aa26f95..39937fd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2634,13 +2634,6 @@ cosmiconfig@^6.0.0: path-type "^4.0.0" yaml "^1.7.2" -cross-env@^7.0.2: - version "7.0.2" - resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-7.0.2.tgz#bd5ed31339a93a3418ac4f3ca9ca3403082ae5f9" - integrity sha512-KZP/bMEOJEDCkDQAyRhu3RL2ZO/SUVrxQVI0G3YEQ+OLbRA3c6zgixe8Mq8a/z7+HKlNEjo8oiLUs8iRijY2Rw== - dependencies: - cross-spawn "^7.0.1" - cross-spawn@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-3.0.1.tgz#1256037ecb9f0c5f79e3d6ef135e30770184b982" @@ -2660,7 +2653,7 @@ cross-spawn@^6.0.0, cross-spawn@^6.0.5: shebang-command "^1.2.0" which "^1.2.9" -cross-spawn@^7.0.0, cross-spawn@^7.0.1, cross-spawn@^7.0.2: +cross-spawn@^7.0.0, cross-spawn@^7.0.2: version "7.0.3" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6" integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==