simplify test server setup

This commit is contained in:
Rene
2021-01-09 01:58:21 +01:00
parent 219c218f44
commit 2f80cac9e5
8 changed files with 23 additions and 31 deletions
+8
View File
@@ -1,4 +1,8 @@
const path = require('path');
module.exports = { module.exports = {
port: 8080,
root: path.join(__dirname, '../'),
build: '.build', build: '.build',
html: { html: {
input: 'index.html', input: 'index.html',
@@ -8,4 +12,8 @@ module.exports = {
input: 'index.browser', input: 'index.browser',
output: 'build', output: 'build',
}, },
dev: {
servePort: 18080,
livereloadPort: 28080,
},
}; };
+2 -3
View File
@@ -181,15 +181,14 @@ const setupRollupTest = async (rootDir, testPath, cacheDir, watch) => {
rollupPluginServe({ rollupPluginServe({
contentBase: dist, contentBase: dist,
historyApiFallback: `/${deploymentConfig.html.output}`, historyApiFallback: `/${deploymentConfig.html.output}`,
port: 18080, port: deploymentConfig.dev.servePort,
onListening(server) { onListening(server) {
rollupServers.push(server); rollupServers.push(server);
}, },
}), }),
rollupPluginLivereload({ rollupPluginLivereload({
watch: dist, watch: dist,
verbose: true, port: deploymentConfig.dev.livereloadPort,
port: 28080,
}), }),
] ]
: []), : []),
+3 -4
View File
@@ -1,8 +1,7 @@
const path = require('path');
const express = require('express'); const express = require('express');
const deploymentConfig = require('./jest-puppeteer.rollup.config.js');
const app = express(); const app = express();
app.use(express.static(path.join(__dirname, '../'))); app.use(express.static(deploymentConfig.root));
app.listen(deploymentConfig.port);
app.listen(process.env.TEST_SERVER_PORT);
+4 -4
View File
@@ -1,10 +1,10 @@
const path = require('path'); const path = require('path');
const jestPuppeteerConfig = require('../jest-puppeteer.config.base'); const deploymentConfig = require('./jest-puppeteer.rollup.config.js');
module.exports = { module.exports = {
process: (src, filePath, config) => { process: (src, filePath) => {
const deploymentPath = path.relative(path.dirname(config.globals.baseConfig), filePath); const deploymentPath = path.relative(deploymentConfig.root, filePath);
const split = deploymentPath.split(path.sep); 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)}`)}`;
}, },
}; };
+3 -6
View File
@@ -1,11 +1,8 @@
const path = require('path'); const path = require('path');
const { TEST_SERVER_PORT } = process.env; const deploymentConfig = path.resolve(__dirname, './config/jest-puppeteer.rollup.config.js');
const port = TEST_SERVER_PORT ? Number(TEST_SERVER_PORT) : 8080;
const testServerPath = path.resolve(__dirname, './config/jest-test-server.js'); const testServerPath = path.resolve(__dirname, './config/jest-test-server.js');
process.env.TEST_SERVER_PORT = port;
module.exports = { module.exports = {
browser: 'chromium', browser: 'chromium',
browserContext: 'incognito', browserContext: 'incognito',
@@ -13,8 +10,8 @@ module.exports = {
headless: false, headless: false,
}, },
server: { server: {
command: `cross-env TEST_SERVER_PORT=${port} node ${testServerPath}`, command: `node ${testServerPath}`,
port, port: deploymentConfig.port,
launchTimeout: 10000, launchTimeout: 10000,
}, },
}; };
+2 -5
View File
@@ -2,9 +2,9 @@ const path = require('path');
const resolve = require('./resolve.config'); const resolve = require('./resolve.config');
const puppeteerRollupConfig = require('./config/jest-puppeteer.rollup.config.js'); 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 testServerLoaderPath = path.resolve(__dirname, './config/jest-test-server.loader.js');
const jsdomSetupFile = path.resolve(__dirname, './config/jest-jsdom.setup.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'); const puppeteerSetupFile = path.resolve(__dirname, './config/jest-puppeteer.setup.js');
// For a detailed explanation regarding each configuration property, visit: // For a detailed explanation regarding each configuration property, visit:
@@ -17,9 +17,6 @@ const base = {
moduleDirectories: resolve.directories, moduleDirectories: resolve.directories,
moduleFileExtensions: resolve.extensions.map((ext) => ext.replace(/\./, '')), moduleFileExtensions: resolve.extensions.map((ext) => ext.replace(/\./, '')),
testPathIgnorePatterns: ['\\\\node_modules\\\\'], testPathIgnorePatterns: ['\\\\node_modules\\\\'],
globals: {
baseConfig: __filename,
},
}; };
const pptrBase = { const pptrBase = {
@@ -27,7 +24,7 @@ const pptrBase = {
preset: 'jest-puppeteer', preset: 'jest-puppeteer',
setupFilesAfterEnv: ['expect-puppeteer', puppeteerSetupFile], setupFilesAfterEnv: ['expect-puppeteer', puppeteerSetupFile],
testMatch: ['**/tests/puppeteer/**/*.test.[jt]s?(x)'], testMatch: ['**/tests/puppeteer/**/*.test.[jt]s?(x)'],
testEnvironment: testEnvironmentPath, testEnvironment: puppeteerTestEnvironmentPath,
coveragePathIgnorePatterns: ['/node_modules/', `/${puppeteerRollupConfig.build}/`], coveragePathIgnorePatterns: ['/node_modules/', `/${puppeteerRollupConfig.build}/`],
transform: { transform: {
'^.+\\.[jt]sx?$': 'babel-jest', '^.+\\.[jt]sx?$': 'babel-jest',
-1
View File
@@ -25,7 +25,6 @@
"bufferutil": "^4.0.1", "bufferutil": "^4.0.1",
"canvas": "^2.6.1", "canvas": "^2.6.1",
"core-js": "^3.6.5", "core-js": "^3.6.5",
"cross-env": "^7.0.2",
"del": "^5.1.0", "del": "^5.1.0",
"eslint": "^7.5.0", "eslint": "^7.5.0",
"eslint-config-airbnb": "^18.2.0", "eslint-config-airbnb": "^18.2.0",
+1 -8
View File
@@ -2634,13 +2634,6 @@ cosmiconfig@^6.0.0:
path-type "^4.0.0" path-type "^4.0.0"
yaml "^1.7.2" 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: cross-spawn@^3.0.0:
version "3.0.1" version "3.0.1"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-3.0.1.tgz#1256037ecb9f0c5f79e3d6ef135e30770184b982" 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" shebang-command "^1.2.0"
which "^1.2.9" 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" version "7.0.3"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6"
integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w== integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==