Integration test running with test server
This commit is contained in:
parent
24e2bd5821
commit
23967fe2f5
@ -18,6 +18,10 @@ You need chrome and chromedriver installed. The Dockerfile builds an image that
|
|||||||
|
|
||||||
TODO add firefox and geckodriver
|
TODO add firefox and geckodriver
|
||||||
|
|
||||||
|
The container can access the outside without setting a port or a network. The network or port is only necessary when wanting to connect the host machine to the docker container. You can run a test that spawns a test server and uses the webdriver to load the page like this:
|
||||||
|
|
||||||
|
docker run --rm -it -v $PWD:/usr/src/app btroops npm run test:integ
|
||||||
|
|
||||||
## Rough way to save the SVG map generated by JavaScript client-side
|
## Rough way to save the SVG map generated by JavaScript client-side
|
||||||
|
|
||||||
const XMLS = new XMLSerializer();
|
const XMLS = new XMLSerializer();
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
console.log('Starting server.');
|
||||||
|
|
||||||
require('esbuild-server')
|
require('esbuild-server')
|
||||||
.createServer(
|
.createServer(
|
||||||
{
|
{
|
||||||
@ -5,7 +7,7 @@ require('esbuild-server')
|
|||||||
entryPoints: ['src/index.js'],
|
entryPoints: ['src/index.js'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
static: 'public',
|
static: 'public'
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.start();
|
.start();
|
@ -1,22 +0,0 @@
|
|||||||
import { Builder } from 'selenium-webdriver';
|
|
||||||
import chrome from 'selenium-webdriver/chrome.js';
|
|
||||||
|
|
||||||
console.log("Start the browser.")
|
|
||||||
|
|
||||||
let chromeOptions = new chrome.Options();
|
|
||||||
chromeOptions.addArguments('--headless', '--disable-gpu', '--no-sandbox');
|
|
||||||
|
|
||||||
let driver = new Builder()
|
|
||||||
.forBrowser('chrome')
|
|
||||||
.setChromeOptions(chromeOptions)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
console.log("Done!")
|
|
||||||
|
|
||||||
console.log("Open Google.")
|
|
||||||
await driver.get("https://google.com");
|
|
||||||
console.log("Done!")
|
|
||||||
|
|
||||||
const html = await driver.getPageSource();
|
|
||||||
|
|
||||||
driver.quit()
|
|
22
jest.config.integ.cjs
Normal file
22
jest.config.integ.cjs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
console.log("Jest config file read.");
|
||||||
|
|
||||||
|
// const { spawn } = require("child_process");
|
||||||
|
|
||||||
|
// const ls = spawn('ls', ['-lh', './test']);
|
||||||
|
|
||||||
|
// ls.stdout.on('data', (data) => { console.log(`stdout: ${data}`); });
|
||||||
|
|
||||||
|
// ls.stderr.on('data', (data) => {
|
||||||
|
// console.error(`stderr: ${data}`);
|
||||||
|
// });
|
||||||
|
|
||||||
|
// ls.on('close', (code) => {
|
||||||
|
// console.log(`child process exited with code ${code}`);
|
||||||
|
// });
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
globalSetup: "./test/setup.cjs",
|
||||||
|
globalTeardown: "./test/teardown.cjs",
|
||||||
|
testPathIgnorePatterns: ["/node_modules/"],
|
||||||
|
testTimeout: 5000
|
||||||
|
};
|
3529
package-lock.json
generated
3529
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -3,9 +3,14 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"esbuild": "^0.20.2",
|
"esbuild": "^0.20.2",
|
||||||
"esbuild-server": "^0.3.0",
|
"esbuild-server": "^0.3.0",
|
||||||
|
"jest": "^29.7.0",
|
||||||
"selenium-webdriver": "^4.19.0"
|
"selenium-webdriver": "^4.19.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"svg-pan-zoom": "github:webdevcat-me/svg-pan-zoom"
|
"svg-pan-zoom": "github:webdevcat-me/svg-pan-zoom"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test:integ": "jest --config jest.config.integ.cjs",
|
||||||
|
"test": "jest"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
18
test/google.test.js
Normal file
18
test/google.test.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
const { Builder } = require('selenium-webdriver'),
|
||||||
|
chrome = require('selenium-webdriver/chrome.js'),
|
||||||
|
{ expect, it } = require('@jest/globals'),
|
||||||
|
chromeOptions = new chrome.Options();
|
||||||
|
|
||||||
|
let driver;
|
||||||
|
|
||||||
|
chromeOptions.addArguments('--headless', '--disable-gpu', '--no-sandbox');
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
driver = new Builder().forBrowser('chrome').setChromeOptions(chromeOptions).build();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('loads the page', async () => {
|
||||||
|
await driver.get("http://localhost:8080");
|
||||||
|
|
||||||
|
expect(await driver.getTitle()).toEqual('Infantry Combat Solo Basic');
|
||||||
|
});
|
28
test/setup.cjs
Normal file
28
test/setup.cjs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
console.log("\nSpawning server process...");
|
||||||
|
const { spawn } = require("child_process");
|
||||||
|
|
||||||
|
module.exports = async function () {
|
||||||
|
const child = spawn("node", ["dev-server.cjs"]);
|
||||||
|
|
||||||
|
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) => {
|
||||||
|
const str = data.toString();
|
||||||
|
console.log("[server]", str);
|
||||||
|
if (str.includes("localhost:3005")) {
|
||||||
|
setTimeout(resolve, 200);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
5
test/teardown.cjs
Normal file
5
test/teardown.cjs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
console.log('Stopping server.')
|
||||||
|
|
||||||
|
module.exports = function teardown() {
|
||||||
|
process.kill(globalThis.__INTEG_TEST_SERVER_PID__);
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user