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
|
## 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.
|
Visit `localhost:8080` to view.
|
||||||
|
|
||||||
## Run a test
|
## 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.
|
`--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')
|
const buildStart = Date.now();
|
||||||
.createServer(
|
server
|
||||||
{
|
.start()
|
||||||
bundle: true,
|
.then(() => {
|
||||||
entryPoints: ['src/index.js'],
|
console.log(`Build completed in ${Date.now() - buildStart}ms`);
|
||||||
},
|
})
|
||||||
{
|
.catch(() => {
|
||||||
static: 'public'
|
console.error('Build failed');
|
||||||
}
|
});
|
||||||
)
|
console.log(`Development server running at ${server.url}`);
|
||||||
.start();
|
|
||||||
|
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 = {
|
module.exports = {
|
||||||
globalSetup: "./test/setup.cjs",
|
globalSetup: "./test/integration/setup.cjs",
|
||||||
globalTeardown: "./test/teardown.cjs",
|
globalTeardown: "./test/integration/teardown.cjs",
|
||||||
testPathIgnorePatterns: ["/node_modules/"],
|
testPathIgnorePatterns: ["/node_modules/", "test/unit"],
|
||||||
testTimeout: 5000
|
testTimeout: 5000
|
||||||
};
|
};
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
"svg-pan-zoom": "github:webdevcat-me/svg-pan-zoom"
|
"svg-pan-zoom": "github:webdevcat-me/svg-pan-zoom"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"start": "node dev-server.cjs",
|
||||||
"test:integ": "jest --config jest.config.integ.cjs",
|
"test:integ": "jest --config jest.config.integ.cjs",
|
||||||
"test": "jest"
|
"test": "jest"
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ beforeAll(async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('loads the page', 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');
|
expect(await driver.getTitle()).toEqual('Infantry Combat Solo Basic');
|
||||||
});
|
});
|
@ -2,20 +2,12 @@ console.log("\nSpawning server process...");
|
|||||||
const { spawn } = require("child_process");
|
const { spawn } = require("child_process");
|
||||||
|
|
||||||
module.exports = async function () {
|
module.exports = async function () {
|
||||||
const child = spawn("node", ["dev-server.cjs"]);
|
const child = spawn("node", ["dev-server.cjs", "--test"]);
|
||||||
|
|
||||||
child.stdout.on('data', (data) => {
|
child.stdout.on('data', (data) => {
|
||||||
console.log(`${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;
|
globalThis.__INTEG_TEST_SERVER_PID__ = child.pid;
|
||||||
|
|
||||||
child.stderr.on("data", (data) => {
|
child.stderr.on("data", (data) => {
|
Loading…
x
Reference in New Issue
Block a user