Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.

Commit a06f2af

Browse files
authored
Increase jest timeout for PWDEBUG option (#596)
1 parent 71454ea commit a06f2af

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,16 @@ module.exports = {
234234

235235
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).
236236

237-
## Put in debug mode
237+
## Debug mode
238238

239-
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.
239+
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:
240+
241+
- Playwright give you [ability](https://playwright.dev/docs/debug/#run-in-debug-mode) to configure the browser for debugging with the `PWDEBUG` environment variable:
242+
```js
243+
PWDEBUG=1 jest
244+
```
245+
246+
- Jest Playwright exposes a method `jestPlaywright.debug()` that suspends test execution and gives you opportunity to see what's going on in the browser.
240247

241248
```js
242249
await jestPlaywright.debug()

src/PlaywrightEnvironment.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import type {
2121
import {
2222
CHROMIUM,
2323
CONFIG_ENVIRONMENT_NAME,
24+
DEBUG_TIMEOUT,
2425
DEFAULT_CONFIG,
2526
FIREFOX,
2627
IMPORT_KIND_PLAYWRIGHT,
@@ -396,8 +397,7 @@ export const getPlaywrightEnv = (basicEnv = 'node'): unknown => {
396397
event.name === 'add_test' &&
397398
event.fn?.toString().includes('jestPlaywright.debug()')
398399
) {
399-
// Set timeout to 4 days
400-
state.testTimeout = 4 * 24 * 60 * 60 * 1000
400+
state.testTimeout = DEBUG_TIMEOUT
401401
}
402402
}
403403

src/PlaywrightRunner.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
generateKey,
3333
} from './utils'
3434
import {
35+
DEBUG_TIMEOUT,
3536
DEFAULT_TEST_PLAYWRIGHT_TIMEOUT,
3637
CONFIG_ENVIRONMENT_NAME,
3738
SERVER,
@@ -95,15 +96,22 @@ const getDevices = (
9596
return resultDevices
9697
}
9798

99+
const getJestTimeout = (configTimeout?: number) => {
100+
if (configTimeout) {
101+
return configTimeout
102+
}
103+
return process.env.PWDEBUG ? DEBUG_TIMEOUT : DEFAULT_TEST_PLAYWRIGHT_TIMEOUT
104+
}
105+
98106
class PlaywrightRunner extends JestRunner {
99107
browser2Server: Partial<Record<string, BrowserServer>>
100108
constructor(
101109
globalConfig: JestConfig.GlobalConfig,
102110
context: TestRunnerContext,
103111
) {
104112
const config = { ...globalConfig }
105-
// Set default timeout to 15s
106-
config.testTimeout = config.testTimeout || DEFAULT_TEST_PLAYWRIGHT_TIMEOUT
113+
// Set testTimeout
114+
config.testTimeout = getJestTimeout(config.testTimeout)
107115
super(config, context)
108116
this.browser2Server = {}
109117
}

src/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,7 @@ export const DEFAULT_CONFIG: JestPlaywrightConfig = {
2323
}
2424

2525
export const DEFAULT_TEST_PLAYWRIGHT_TIMEOUT = 15000
26+
// Set timeout to 4 days
27+
export const DEBUG_TIMEOUT = 4 * 24 * 60 * 60 * 1000
2628

2729
export const PACKAGE_NAME = 'jest-playwright-preset'

0 commit comments

Comments
 (0)