Run server on different port when running tests
This commit is contained in:
parent
6084c54e2e
commit
e9bfecace9
@ -4,13 +4,13 @@
|
||||
|
||||
## Start the dev server
|
||||
|
||||
docker run --rm --init -it -w /app -v $PWD:/app -p 8080:8080 node node dev-server.js
|
||||
docker run --rm --init -it -v $PWD:/usr/src/app -p 8080:8080 btroops
|
||||
|
||||
Visit `localhost:8080` to view.
|
||||
|
||||
## Run a test
|
||||
|
||||
You need chrome and chromedriver installed. The Dockerfile builds an image that does that. Then run the test with that image.
|
||||
You need chrome and chromedriver installed to run the integration tests. The Dockerfile builds an image that does that. Then run the test with that image.
|
||||
|
||||
`--network host` gives the container internet access. Necessary if tests make outside requests.
|
||||
|
||||
|
@ -1,13 +1,22 @@
|
||||
console.log('Starting server.');
|
||||
const { createServer } = require('esbuild-server');
|
||||
const server = createServer(
|
||||
{
|
||||
bundle: true,
|
||||
entryPoints: ['src/index.js'],
|
||||
},
|
||||
{
|
||||
static: 'public',
|
||||
...(process.argv.slice(2).includes('--test')) && { port: 3005 }
|
||||
}
|
||||
);
|
||||
|
||||
require('esbuild-server')
|
||||
.createServer(
|
||||
{
|
||||
bundle: true,
|
||||
entryPoints: ['src/index.js'],
|
||||
},
|
||||
{
|
||||
static: 'public'
|
||||
}
|
||||
)
|
||||
.start();
|
||||
const buildStart = Date.now();
|
||||
server
|
||||
.start()
|
||||
.then(() => {
|
||||
console.log(`Build completed in ${Date.now() - buildStart}ms`);
|
||||
})
|
||||
.catch(() => {
|
||||
console.error('Build failed');
|
||||
});
|
||||
console.log(`Development server running at ${server.url}`);
|
||||
|
3
jest.config.cjs
Normal file
3
jest.config.cjs
Normal file
@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
testPathIgnorePatterns: ["/node_modules/", "test/integration"]
|
||||
};
|
@ -15,8 +15,8 @@ console.log("Jest config file read.");
|
||||
// });
|
||||
|
||||
module.exports = {
|
||||
globalSetup: "./test/setup.cjs",
|
||||
globalTeardown: "./test/teardown.cjs",
|
||||
testPathIgnorePatterns: ["/node_modules/"],
|
||||
globalSetup: "./test/integration/setup.cjs",
|
||||
globalTeardown: "./test/integration/teardown.cjs",
|
||||
testPathIgnorePatterns: ["/node_modules/", "test/unit"],
|
||||
testTimeout: 5000
|
||||
};
|
||||
|
@ -10,6 +10,7 @@
|
||||
"svg-pan-zoom": "github:webdevcat-me/svg-pan-zoom"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "node dev-server.cjs",
|
||||
"test:integ": "jest --config jest.config.integ.cjs",
|
||||
"test": "jest"
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ beforeAll(async () => {
|
||||
});
|
||||
|
||||
it('loads the page', async () => {
|
||||
await driver.get("http://localhost:8080");
|
||||
await driver.get("http://localhost:3005");
|
||||
|
||||
expect(await driver.getTitle()).toEqual('Infantry Combat Solo Basic');
|
||||
});
|
@ -2,20 +2,12 @@ console.log("\nSpawning server process...");
|
||||
const { spawn } = require("child_process");
|
||||
|
||||
module.exports = async function () {
|
||||
const child = spawn("node", ["dev-server.cjs"]);
|
||||
const child = spawn("node", ["dev-server.cjs", "--test"]);
|
||||
|
||||
child.stdout.on('data', (data) => {
|
||||
console.log(`${data}`);
|
||||
});
|
||||
|
||||
// child.stderr.on('data', (data) => {
|
||||
// console.error(`stderr: ${data}`);
|
||||
// });
|
||||
|
||||
// child.on('close', (code) => {
|
||||
// console.log(`child process exited with code ${code}`);
|
||||
// });
|
||||
|
||||
globalThis.__INTEG_TEST_SERVER_PID__ = child.pid;
|
||||
|
||||
child.stderr.on("data", (data) => {
|
Loading…
x
Reference in New Issue
Block a user