This repository was archived by the owner on Feb 23, 2024. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathextends.js
More file actions
91 lines (78 loc) · 2.16 KB
/
Copy pathextends.js
File metadata and controls
91 lines (78 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* global jestPlaywright, browserName, deviceName */
// TODO Rewrite with TS?
const { getSkipFlag, deepMerge } = require('./lib/utils')
const DEBUG_OPTIONS = {
launchOptions: {
headless: false,
devtools: true,
},
}
const runDebugTest = (jestTestType, ...args) => {
const isConfigProvided = typeof args[0] === 'object'
// TODO Looks wierd - need to be rewritten
let options = DEBUG_OPTIONS
if (isConfigProvided) {
options = deepMerge(DEBUG_OPTIONS, args[0])
}
jestTestType(args[isConfigProvided ? 1 : 0], async () => {
const { browser, context, page } = await jestPlaywright._configSeparateEnv(
options,
true,
)
try {
await args[isConfigProvided ? 2 : 1]({ browser, context, page })
} finally {
await browser.close()
}
})
}
it.jestPlaywrightDebug = (...args) => {
runDebugTest(it, ...args)
}
it.jestPlaywrightDebug.only = (...args) => {
runDebugTest(it.only, ...args)
}
it.jestPlaywrightDebug.skip = (...args) => {
runDebugTest(it.skip, ...args)
}
const runConfigTest = (jestTypeTest, playwrightOptions, ...args) => {
if (playwrightOptions.browser && playwrightOptions.browser !== browserName) {
it.skip(...args)
} else {
jestTypeTest(args[0], async () => {
const {
browser,
context,
page,
} = await jestPlaywright._configSeparateEnv(playwrightOptions)
try {
await args[1]({ browser, context, page })
} finally {
await browser.close()
}
})
}
}
it.jestPlaywrightConfig = (playwrightOptions, ...args) => {
runConfigTest(it, playwrightOptions, ...args)
}
it.jestPlaywrightConfig.only = (...args) => {
runConfigTest(it.only, ...args)
}
it.jestPlaywrightConfig.skip = (...args) => {
runConfigTest(it.skip, ...args)
}
const customSkip = (skipOption, type, ...args) => {
const skipFlag = getSkipFlag(skipOption, browserName, deviceName)
if (skipFlag) {
global[type].skip(...args)
} else {
global[type](...args)
}
}
it.jestPlaywrightSkip = (skipOption, ...args) => {
customSkip(skipOption, 'it', ...args)
}
describe.jestPlaywrightSkip = (skipOption, ...args) => {
customSkip(skipOption, 'describe', ...args)
}