diff --git a/test/1_serverCypress.js b/test/1_serverCypress.js index 9e46dbbf..caec96bb 100644 --- a/test/1_serverCypress.js +++ b/test/1_serverCypress.js @@ -3,6 +3,24 @@ import { exec } from 'node:child_process'; import * as http from 'node:http'; import { app } from '../app.js'; import { portNumber } from './_globals.js'; +const thirtyMinutesInMillis = 30 * 60 * 60 * 1000; +function runCypress(browser, done) { + let cypressCommand = `cypress run --config-file cypress.config.js --browser ${browser}`; + if ((process.env.CYPRESS_RECORD_KEY ?? '') !== '') { + cypressCommand += ` --tag "${browser},${process.version}" --record`; + } + const childProcess = exec(cypressCommand); + childProcess.stdout?.on('data', (data) => { + console.log(data); + }); + childProcess.stderr?.on('data', (data) => { + console.error(data); + }); + childProcess.on('exit', (code) => { + assert.ok(code === 0); + done(); + }); +} describe('lottery-licence-manager', () => { const httpServer = http.createServer(app); let serverStarted = false; @@ -23,22 +41,11 @@ describe('lottery-licence-manager', () => { assert.ok(serverStarted); }); describe('Cypress tests', () => { - it('should run Cypress tests', (done) => { - let cypressCommand = 'cypress run --config-file cypress.config.ts --browser chrome'; - if ((process.env.CYPRESS_RECORD_KEY ?? '') !== '') { - cypressCommand += ' --record'; - } - const childProcess = exec(cypressCommand); - childProcess.stdout?.on('data', (data) => { - console.log(data); - }); - childProcess.stderr?.on('data', (data) => { - console.error(data); - }); - childProcess.on('exit', (code) => { - assert.ok(code === 0); - done(); - }); - }).timeout(30 * 60 * 60 * 1000); - }); + it('Should run Cypress tests in Chrome', (done) => { + runCypress('chrome', done); + }).timeout(thirtyMinutesInMillis); + it('Should run Cypress tests in Firefox', (done) => { + runCypress('firefox', done); + }).timeout(thirtyMinutesInMillis); + }).timeout(thirtyMinutesInMillis); }); diff --git a/test/1_serverCypress.ts b/test/1_serverCypress.ts index 0328f6cf..1fec0ded 100644 --- a/test/1_serverCypress.ts +++ b/test/1_serverCypress.ts @@ -8,6 +8,33 @@ import { app } from '../app.js' import { portNumber } from './_globals.js' +// eslint-disable-next-line @typescript-eslint/no-magic-numbers +const thirtyMinutesInMillis = 30 * 60 * 60 * 1000 + +function runCypress(browser: 'chrome' | 'firefox', done: () => void): void { + let cypressCommand = `cypress run --config-file cypress.config.js --browser ${browser}` + + if ((process.env.CYPRESS_RECORD_KEY ?? '') !== '') { + cypressCommand += ` --tag "${browser},${process.version}" --record` + } + + // eslint-disable-next-line security/detect-child-process, sonarjs/os-command + const childProcess = exec(cypressCommand) + + childProcess.stdout?.on('data', (data) => { + console.log(data) + }) + + childProcess.stderr?.on('data', (data) => { + console.error(data) + }) + + childProcess.on('exit', (code) => { + assert.ok(code === 0) + done() + }) +} + describe('lottery-licence-manager', () => { const httpServer = http.createServer(app) @@ -34,28 +61,12 @@ describe('lottery-licence-manager', () => { }) describe('Cypress tests', () => { - it('should run Cypress tests', (done) => { - let cypressCommand = - 'cypress run --config-file cypress.config.ts --browser chrome' - - if ((process.env.CYPRESS_RECORD_KEY ?? '') !== '') { - cypressCommand += ' --record' - } - - const childProcess = exec(cypressCommand) + it('Should run Cypress tests in Chrome', (done) => { + runCypress('chrome', done) + }).timeout(thirtyMinutesInMillis) - childProcess.stdout?.on('data', (data) => { - console.log(data) - }) - - childProcess.stderr?.on('data', (data) => { - console.error(data) - }) - - childProcess.on('exit', (code) => { - assert.ok(code === 0) - done() - }) - }).timeout(30 * 60 * 60 * 1000) - }) + it('Should run Cypress tests in Firefox', (done) => { + runCypress('firefox', done) + }).timeout(thirtyMinutesInMillis) + }).timeout(thirtyMinutesInMillis) })