diff --git a/src/PlaywrightEnvironment.ts b/src/PlaywrightEnvironment.ts index c8b5ca12..28d3f017 100644 --- a/src/PlaywrightEnvironment.ts +++ b/src/PlaywrightEnvironment.ts @@ -30,6 +30,19 @@ const resetBrowserCloseWatchdog = (): void => { if (browserShutdownTimeout) clearTimeout(browserShutdownTimeout) } +const logMessage = ({ + message, + action, +}: { + message: string + action: string +}): void => { + console.log('') + console.error(message) + console.error(`\n☝️ You ${action} in jest-playwright.config.js`) + process.exit(1) +} + // Since there are no per-worker hooks, we have to setup a timer to // close the browser. // @@ -68,19 +81,6 @@ class PlaywrightEnvironment extends NodeEnvironment { super(config) this._config = config } - // Jest is not available here, so we have to reverse engineer - // the setTimeout function, see https://github.com/facebook/jest/blob/v23.1.0/packages/jest-runtime/src/index.js#L823 - setTimeout(timeout: number): void { - if (this.global.jasmine) { - // eslint-disable-next-line @typescript-eslint/ban-ts-ignore - // @ts-ignore - this.global.jasmine.DEFAULT_TIMEOUT_INTERVAL = timeout - } else { - // eslint-disable-next-line @typescript-eslint/ban-ts-ignore - // @ts-ignore - this.global[Symbol.for('TEST_TIMEOUT_SYMBOL')] = timeout - } - } async setup(): Promise { resetBrowserCloseWatchdog() @@ -104,20 +104,16 @@ class PlaywrightEnvironment extends NodeEnvironment { await setup(config.server) } catch (error) { if (error.code === ERROR_TIMEOUT) { - console.log('') - console.error(error.message) - console.error( - `\n☝️ You can set "server.launchTimeout" in jest-playwright.config.js`, - ) - process.exit(1) + logMessage({ + message: error.message, + action: 'can set "server.launchTimeout"', + }) } if (error.code === ERROR_NO_COMMAND) { - console.log('') - console.error(error.message) - console.error( - `\n☝️ You must set "server.command" in jest-playwright.config.js`, - ) - process.exit(1) + logMessage({ + message: error.message, + action: 'must set "server.command"', + }) } throw error } @@ -135,9 +131,6 @@ class PlaywrightEnvironment extends NodeEnvironment { this.global.page.on('pageerror', handleError) this.global.jestPlaywright = { debug: async (): Promise => { - // eslint-disable-next-line no-eval - // Set timeout to 4 days - this.setTimeout(345600000) // Run a debugger (in case Playwright has been launched with `{ devtools: true }`) await this.global.page.evaluate(() => { // eslint-disable-next-line no-debugger diff --git a/src/bin/testProcess.ts b/src/bin/testProcess.ts index d9f22b39..060df60d 100644 --- a/src/bin/testProcess.ts +++ b/src/bin/testProcess.ts @@ -5,7 +5,7 @@ import { readConfig, readPackage, } from '../utils' -import { checkCommand, getExitCode, getLogMessage } from './utils' +import { checkCommand, getDisplayName, getExitCode } from './utils' import { BrowserType, CORE, PARALLEL, PLAYWRIGHT } from '../constants' const getSpawnOptions = ( @@ -34,23 +34,26 @@ const exec = ({ }): Promise => new Promise(resolve => { const options = getSpawnOptions(browser, device) + const displayName = getDisplayName(browser, device) if (sequence === PARALLEL) { const process = spawn( 'node', - [`node_modules/jest/bin/jest.js ${params}`], + [ + `node_modules/jest/bin/jest.js --displayName="${displayName}" ${params}`, + ], options, ) process.on('close', status => { - console.log(getLogMessage(browser, status, device)) resolve(status) }) } else { const { status } = spawnSync( 'node', - [`node_modules/jest/bin/jest.js ${params}`], + [ + `node_modules/jest/bin/jest.js --displayName="${displayName}" ${params}`, + ], options, ) - console.log(getLogMessage(browser, status, device)) resolve(status) } }) diff --git a/src/bin/utils.test.ts b/src/bin/utils.test.ts index ae53f9b9..b2f5efb6 100644 --- a/src/bin/utils.test.ts +++ b/src/bin/utils.test.ts @@ -1,9 +1,4 @@ -import { - checkCommand, - getResultByStatus, - getLogMessage, - getExitCode, -} from './utils' +import { checkCommand, getDisplayName, getExitCode } from './utils' import { BrowserType } from '../constants' describe('checkCommand', () => { @@ -18,30 +13,14 @@ describe('checkCommand', () => { }) }) -describe('getResultByStatus', () => { - it('should return "Failed" if passed null', () => { - expect(getResultByStatus(null)).toBe('Failed') +describe('getDisplayName', () => { + it('should return right display name for passed browser', () => { + expect(getDisplayName('chromium', null)).toBe('browser: chromium') }) - it('should return "Failed" if passed code 1', () => { - expect(getResultByStatus(1)).toBe('Failed') - }) - - it('should return "Passed" if passed code 0', () => { - expect(getResultByStatus(0)).toBe('Passed') - }) -}) - -describe('getLogMessage', () => { - it('should return right log', () => { - expect(getLogMessage('chromium', 0, null)).toBe( - 'Passed tests for browser: chromium \n\n', - ) - }) - - it('should return right log', () => { - expect(getLogMessage('chromium', 1, 'iPhone 6')).toBe( - 'Failed tests for browser: chromium and device: iPhone 6\n\n', + it('should return right display name for passed browser and device', () => { + expect(getDisplayName('chromium', 'iPhone 6')).toBe( + 'browser: chromium device: iPhone 6', ) }) }) diff --git a/src/bin/utils.ts b/src/bin/utils.ts index 74f5a5e1..2f96f341 100644 --- a/src/bin/utils.ts +++ b/src/bin/utils.ts @@ -15,18 +15,11 @@ export const checkCommand = ( // devices.forEach(checkDeviceEnv) } -export const getResultByStatus = (status: number | null): string => { - return status !== 0 ? 'Failed' : 'Passed' -} - -export const getLogMessage = ( +export const getDisplayName = ( browser: BrowserType, - status: number | null, device: string | null, ): string => { - return `${getResultByStatus(status)} tests for browser: ${browser} ${ - device ? `and device: ${device}` : '' - }\n\n` + return `browser: ${browser}${device ? ` device: ${device}` : ''}` } export const getExitCode = (exitCodes: (number | null)[]): void => {