index : btroops | |
Virtual board game-aid for BattleTroops, an infantry combat simulator wargame published by FASA in 1989. |
aboutsummaryrefslogtreecommitdiff |
diff options
author | Catalin Mititiuc <webdevcat@proton.me> | 2024-05-28 17:46:32 -0700 |
---|---|---|
committer | Catalin Mititiuc <webdevcat@proton.me> | 2024-05-28 18:44:28 -0700 |
commit | 7e5aedeb0a1ffa727005c98d80044429bf20ff45 (patch) | |
tree | e50e71d53cf77f6cb850d3fab01d24e91c9551ae | |
parent | 2df718998a89cb622bb9a76655abdeafc33d9aa5 (diff) |
Move takeScreenshot() function into a test helper file
-rw-r--r-- | jest.config.integ.cjs | 1 | ||||
-rw-r--r-- | test/integration/helpers.cjs | 11 | ||||
-rw-r--r-- | test/integration/page.test.js | 12 | ||||
-rw-r--r-- | test/integration/select.test.js | 11 |
4 files changed, 14 insertions, 21 deletions
diff --git a/jest.config.integ.cjs b/jest.config.integ.cjs index 7a8028a..7e8af3c 100644 --- a/jest.config.integ.cjs +++ b/jest.config.integ.cjs @@ -3,6 +3,7 @@ console.log('Jest config file read.'); module.exports = { globalSetup: './test/integration/setup.cjs', globalTeardown: './test/integration/teardown.cjs', + setupFiles: ['./test/integration/helpers.cjs'], testPathIgnorePatterns: ['/node_modules/', 'test/unit'], testTimeout: 5000, }; diff --git a/test/integration/helpers.cjs b/test/integration/helpers.cjs new file mode 100644 index 0000000..5643bfd --- /dev/null +++ b/test/integration/helpers.cjs @@ -0,0 +1,11 @@ +const { mkdir, writeFile } = require('node:fs/promises') + , path = require('path') + ; + +global.takeScreenshot = async (driver) => { + const dir = './test/screenshots'; + const fileName = path.relative(process.cwd(), __filename) + ' "' + global.expect.getState().currentTestName + `" ${new Date().toISOString()}.png`; + const image = await driver.takeScreenshot(); + await mkdir(dir, { recursive: true }); + await writeFile(`${dir}/${fileName.replaceAll('/', '-')}`, image, 'base64'); +}; diff --git a/test/integration/page.test.js b/test/integration/page.test.js index db0bf0d..8bb703e 100644 --- a/test/integration/page.test.js +++ b/test/integration/page.test.js @@ -1,9 +1,7 @@ const { Builder } = require('selenium-webdriver'), chrome = require('selenium-webdriver/chrome.js'), chromeOptions = new chrome.Options(), - { expect, it } = require('@jest/globals'), - { mkdir, writeFile } = require('node:fs/promises'), - path = require('path'); + { expect, it } = require('@jest/globals'); chromeOptions.addArguments('--headless', '--disable-gpu', '--no-sandbox'); chromeOptions.enableBidi(); @@ -22,11 +20,3 @@ it('loads the page', async () => { afterEach(async () => { await driver.quit(); }); - -async function takeScreenshot(driver) { - const dir = './test/screenshots'; - 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'); -} diff --git a/test/integration/select.test.js b/test/integration/select.test.js index 69eea00..2594179 100644 --- a/test/integration/select.test.js +++ b/test/integration/select.test.js @@ -2,8 +2,7 @@ const { Builder, By, until } = require('selenium-webdriver'), chrome = require('selenium-webdriver/chrome.js'), chromeOptions = new chrome.Options(), { expect, it } = require('@jest/globals'), - { mkdir, writeFile, readFile } = require('node:fs/promises'), - path = require('path'), + { readFile } = require('node:fs/promises'), { HttpResponse } = require('selenium-webdriver/devtools/networkinterceptor'); chromeOptions.addArguments('--headless', '--disable-gpu', '--no-sandbox'); @@ -182,11 +181,3 @@ it('selects a trooper by clicking on its record and deselects it by clicking on afterEach(async () => { await driver.quit(); }); - -async function takeScreenshot(driver) { - const dir = './test/screenshots'; - 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'); -} |