Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xnpm2
-rw-r--r--package.json4
-rwxr-xr-xrun-shell3
-rwxr-xr-xrun-shell-test3
-rwxr-xr-xrun-test3
-rw-r--r--test/integration/page.test.js77
6 files changed, 23 insertions, 69 deletions
diff --git a/npm b/npm
index a97de73..1d3b623 100755
--- a/npm
+++ b/npm
@@ -1,3 +1,3 @@
#!/usr/bin/env bash
-docker run --rm --init -it -v $PWD:/usr/src/app -u $(id -u):$(id -u) -p 8080:8080 --name btroops-test btroops npm $@
+docker run --rm --init -it -v $PWD:/usr/src/app -u $(id -u):$(id -u) -p 8080:8080 btroops npm $@
diff --git a/package.json b/package.json
index 2cdee63..1e0f59f 100644
--- a/package.json
+++ b/package.json
@@ -11,8 +11,8 @@
},
"scripts": {
"start": "node dev-server.cjs",
- "test:integ": "DBUS_SESSION_BUS_ADDRESS=/dev/null node --trace-warnings ./node_modules/.bin/jest --detectOpenHandles --config jest.config.integ.cjs",
- "test:integ:debug": "NODE_INSPECT_RESUME_ON_START=1 DBUS_SESSION_BUS_ADDRESS=/dev/null node inspect ./node_modules/jest/bin/jest.js --config jest.config.integ.cjs --runInBand test/integration/page.test.js",
+ "test:integ": "node --trace-warnings ./node_modules/.bin/jest --detectOpenHandles --config jest.config.integ.cjs",
+ "test:integ:debug": "NODE_INSPECT_RESUME_ON_START=1 node inspect ./node_modules/jest/bin/jest.js --config jest.config.integ.cjs --runInBand test/integration/page.test.js",
"test": "jest"
}
}
diff --git a/run-shell b/run-shell
new file mode 100755
index 0000000..afd0141
--- /dev/null
+++ b/run-shell
@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+
+docker run --rm --init -it -v $PWD:/usr/src/app -p 8080:8080 btroops bash
diff --git a/run-shell-test b/run-shell-test
new file mode 100755
index 0000000..8d1edd7
--- /dev/null
+++ b/run-shell-test
@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+
+docker run --rm --init -it --hostname btroops-test -v $PWD:/usr/src/app -p 8080:8080 --name btroops-test btroops bash
diff --git a/run-test b/run-test
deleted file mode 100755
index 1722c8f..0000000
--- a/run-test
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/env bash
-
-docker run --rm --init -it -v $PWD:/usr/src/app -p 8080:8080 --name btroops-test btroops bash
diff --git a/test/integration/page.test.js b/test/integration/page.test.js
index 1e69db1..7a987f7 100644
--- a/test/integration/page.test.js
+++ b/test/integration/page.test.js
@@ -1,91 +1,42 @@
const { Builder, By } = require('selenium-webdriver'),
chrome = require('selenium-webdriver/chrome.js'),
- { Command } = require('selenium-webdriver/lib/command.js'),
{ expect, it } = require('@jest/globals'),
+ chromeOptions = new chrome.Options(),
{ mkdir, writeFile } = require('node:fs/promises'),
- path = require('path'),
- chromeOptions = new chrome.Options();
+ path = require('path');
chromeOptions.addArguments('--headless', '--disable-gpu', '--no-sandbox');
let driver;
-
-// beforeAll(async () => {
-// });
-
beforeEach(async () => {
- // console.log('setup');
- // driver = new Builder().forBrowser('chrome').setChromeOptions(chromeOptions).build();
driver = new Builder().forBrowser('chrome').setChromeOptions(chromeOptions).build();
+ await driver.get("http://localhost:3005");
});
-it.each(Array(100).fill(null))('looper', async () => {
-// it('looper', async () => {
- // console.log('test');
- // const driver = new Builder().forBrowser('chrome').setChromeOptions(chromeOptions).build();
- // await driver.get("http://localhost:3005").catch(e => console.log(e));;
- // await driver.quit();
- await driver.get("http://localhost:3005").catch(e => console.log(e));
- const title = await driver.getTitle();
-
- expect(title).toEqual('Infantry Combat Solo Basic');
- // await driver.switchTo().defaultContent();
-});
-
-it('debugger', async () => {
-// it.only('loads the page', async () => {
- // console.log('test');
- // const driver = new Builder().forBrowser('chrome').setChromeOptions(chromeOptions).build();
- // await driver.get("http://localhost:3005").catch(e => console.log(e));;
- // await driver.quit();
- await driver.get("http://localhost:3005").catch(e => console.log(e));
- const title = await driver.getTitle();
-
- expect(title).toEqual('Infantry Combat Solo Basic');
- // await driver.switchTo().defaultContent();
- debugger;
+it('loads the page', async () => {
+ expect(await driver.getTitle()).toEqual('Infantry Combat Solo Basic');
});
+it('selects an off-board soldier', async () => {
+ await driver.switchTo().frame(await driver.findElement(By.css('object')));
+ const selector = '.counter[data-allegiance="attacker"][data-number="1"]',
+ svg = await driver.findElement(By.css('svg')),
+ counter = await driver.findElement(By.css(selector), svg);
-// it.only.each(Array(10).fill(null))('selects an off-board soldier', async () => {
-// it('selects an off-board soldier', async () => {
-// await driver.switchTo().frame(await driver.findElement(By.css('object')));
-
-// const selector = '.counter[data-allegiance="attacker"][data-number="1"]',
-// svg = await driver.findElement(By.css('svg')),
-// counter = await driver.findElement(By.css(selector), svg);
-
-// await counter.click();
-// // await takeScreenshot(driver);
+ await counter.click();
-// expect(await counter.getAttribute('class')).toEqual(expect.stringContaining('selected'));
-// // await driver.switchTo().defaultContent();
-// });
+ expect(await counter.getAttribute('class')).toEqual(expect.stringContaining('selected'));
+});
afterEach(async () => {
- // console.log('teardown');
- // const session = await this.driver.getSession();
- // const sessionId = session.getId();
- // const executor = await this.driver.getExecutor();
- // await executor.execute(new Command('close').setParameter('sessionId', sessionId));
await driver.quit();
});
-// afterAll(async () => {
-// // console.log('executor', driver.getExecutor());
-// const session = await driver.getSession();
-// const sessionId = session.getId();
-// const executor = await driver.getExecutor();
-// await executor.execute(new Command('close').setParameter('sessionId', sessionId));
-// await driver.quit();
-// });
-
async function takeScreenshot(driver) {
const dir = './test/screenshots';
- const fileName = '"' + path.relative(process.cwd(), __filename) + ' ' + expect.getState().currentTestName + ` ${new Date()}".png`;
- // console.log(fileName.replaceAll('/', '-'));
+ const fileName = path.relative(process.cwd(), __filename) + ' "' + expect.getState().currentTestName + `" ${new Date().toISOString()}.png`;
const image = await driver.takeScreenshot();
await mkdir(dir, { recursive: true });
await writeFile(`${dir}/${fileName.replaceAll('/', '-')}`, image, 'base64');