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

Commit c8727cf

Browse files
authored
Add ability to pass timers to jestPlaywright tests (#678)
https://github.com/playwright-community/jest-playwright/discussions/672
1 parent c2b70ca commit c8727cf

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

src/extends.ts

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/* eslint-disable @typescript-eslint/no-explicit-any*/
33
import { getSkipFlag, deepMerge } from './utils'
44
import { SkipOption, TestPlaywrightConfigOptions } from '../types/global'
5+
import { DEBUG_TIMEOUT, DEFAULT_TEST_PLAYWRIGHT_TIMEOUT } from './constants'
56

67
type TestType = 'it' | 'describe'
78

@@ -14,20 +15,26 @@ const DEBUG_OPTIONS = {
1415

1516
const runDebugTest = (jestTestType: jest.It, ...args: any[]) => {
1617
const isConfigProvided = typeof args[0] === 'object'
18+
const lastArg = args[args.length - 1]
19+
const timer = typeof lastArg === 'number' ? lastArg : DEBUG_TIMEOUT
1720
// TODO Looks weird - need to be rewritten
1821
let options = DEBUG_OPTIONS as TestPlaywrightConfigOptions
1922
if (isConfigProvided) {
2023
options = deepMerge(DEBUG_OPTIONS, args[0])
2124
}
2225

23-
jestTestType(args[isConfigProvided ? 1 : 0], async () => {
24-
const envArgs = await jestPlaywright.configSeparateEnv(options, true)
25-
try {
26-
await args[isConfigProvided ? 2 : 1](envArgs)
27-
} finally {
28-
await envArgs.browser!.close()
29-
}
30-
})
26+
jestTestType(
27+
args[isConfigProvided ? 1 : 0],
28+
async () => {
29+
const envArgs = await jestPlaywright.configSeparateEnv(options, true)
30+
try {
31+
await args[isConfigProvided ? 2 : 1](envArgs)
32+
} finally {
33+
await envArgs.browser!.close()
34+
}
35+
},
36+
timer,
37+
)
3138
}
3239

3340
// @ts-ignore
@@ -48,14 +55,21 @@ const runConfigTest = (
4855
playwrightOptions: Partial<TestPlaywrightConfigOptions>,
4956
...args: any[]
5057
) => {
51-
jestTypeTest(args[0], async () => {
52-
const envArgs = await jestPlaywright.configSeparateEnv(playwrightOptions)
53-
try {
54-
await args[1](envArgs)
55-
} finally {
56-
await envArgs.browser!.close()
57-
}
58-
})
58+
const lastArg = args[args.length - 1]
59+
const timer =
60+
typeof lastArg === 'number' ? lastArg : DEFAULT_TEST_PLAYWRIGHT_TIMEOUT
61+
jestTypeTest(
62+
args[0],
63+
async () => {
64+
const envArgs = await jestPlaywright.configSeparateEnv(playwrightOptions)
65+
try {
66+
await args[1](envArgs)
67+
} finally {
68+
await envArgs.browser!.close()
69+
}
70+
},
71+
timer,
72+
)
5973
}
6074

6175
//@ts-ignore

0 commit comments

Comments
 (0)