diff --git a/README.md b/README.md index f069d02d..b367fada 100644 --- a/README.md +++ b/README.md @@ -234,9 +234,16 @@ module.exports = { All of them are available globally in each Jest test. If you are using ESLint and JavaScript, its recommend to use it in combination with the [eslint-plugin-jest-playwright](https://github.com/playwright-community/eslint-plugin-jest-playwright). -## Put in debug mode +## Debug mode -Debugging tests can be hard sometimes and it is very useful to be able to pause tests in order to inspect the browser. Jest Playwright exposes a method `jestPlaywright.debug()` that suspends test execution and gives you opportunity to see what's going on in the browser. +Debugging tests can be hard sometimes and it is very useful to be able to pause tests in order to inspect the browser. There are two ways to put your tests in debug mode: + +- Playwright give you [ability](https://playwright.dev/docs/debug/#run-in-debug-mode) to configure the browser for debugging with the `PWDEBUG` environment variable: +```js +PWDEBUG=1 jest +``` + +- Jest Playwright exposes a method `jestPlaywright.debug()` that suspends test execution and gives you opportunity to see what's going on in the browser. ```js await jestPlaywright.debug() diff --git a/src/PlaywrightEnvironment.ts b/src/PlaywrightEnvironment.ts index 15dfefa4..bfb8b517 100644 --- a/src/PlaywrightEnvironment.ts +++ b/src/PlaywrightEnvironment.ts @@ -21,6 +21,7 @@ import type { import { CHROMIUM, CONFIG_ENVIRONMENT_NAME, + DEBUG_TIMEOUT, DEFAULT_CONFIG, FIREFOX, IMPORT_KIND_PLAYWRIGHT, @@ -396,8 +397,7 @@ export const getPlaywrightEnv = (basicEnv = 'node'): unknown => { event.name === 'add_test' && event.fn?.toString().includes('jestPlaywright.debug()') ) { - // Set timeout to 4 days - state.testTimeout = 4 * 24 * 60 * 60 * 1000 + state.testTimeout = DEBUG_TIMEOUT } } diff --git a/src/PlaywrightRunner.ts b/src/PlaywrightRunner.ts index e3453bb1..8fa1aca7 100644 --- a/src/PlaywrightRunner.ts +++ b/src/PlaywrightRunner.ts @@ -32,6 +32,7 @@ import { generateKey, } from './utils' import { + DEBUG_TIMEOUT, DEFAULT_TEST_PLAYWRIGHT_TIMEOUT, CONFIG_ENVIRONMENT_NAME, SERVER, @@ -95,6 +96,13 @@ const getDevices = ( return resultDevices } +const getJestTimeout = (configTimeout?: number) => { + if (configTimeout) { + return configTimeout + } + return process.env.PWDEBUG ? DEBUG_TIMEOUT : DEFAULT_TEST_PLAYWRIGHT_TIMEOUT +} + class PlaywrightRunner extends JestRunner { browser2Server: Partial> constructor( @@ -102,8 +110,8 @@ class PlaywrightRunner extends JestRunner { context: TestRunnerContext, ) { const config = { ...globalConfig } - // Set default timeout to 15s - config.testTimeout = config.testTimeout || DEFAULT_TEST_PLAYWRIGHT_TIMEOUT + // Set testTimeout + config.testTimeout = getJestTimeout(config.testTimeout) super(config, context) this.browser2Server = {} } diff --git a/src/constants.ts b/src/constants.ts index 354ee981..af6cd744 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -23,5 +23,7 @@ export const DEFAULT_CONFIG: JestPlaywrightConfig = { } export const DEFAULT_TEST_PLAYWRIGHT_TIMEOUT = 15000 +// Set timeout to 4 days +export const DEBUG_TIMEOUT = 4 * 24 * 60 * 60 * 1000 export const PACKAGE_NAME = 'jest-playwright-preset'