Skip to content

Commit 42e9c95

Browse files
authored
jestPlaywright helpers skip and only (#246)
* jestPlaywright helpers skip and only * Added some TODOs for merging ongects util function
1 parent 6758a9e commit 42e9c95

File tree

4 files changed

+49
-15
lines changed

4 files changed

+49
-15
lines changed

extends.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const DEBUG_OPTIONS = {
99
},
1010
}
1111

12-
it.jestPlaywrightDebug = (...args) => {
12+
const runDebugTest = (jestTestType, ...args) => {
1313
const isConfigProvided = typeof args[0] === 'object'
1414
// TODO Looks wierd - need to be rewritten
1515
let options = DEBUG_OPTIONS
@@ -19,6 +19,7 @@ it.jestPlaywrightDebug = (...args) => {
1919
launchOptions = {},
2020
launchType = DEBUG_OPTIONS.launchType,
2121
} = args[0]
22+
// TODO Add function for deep objects merging
2223
options = {
2324
...DEBUG_OPTIONS,
2425
launchType,
@@ -27,7 +28,7 @@ it.jestPlaywrightDebug = (...args) => {
2728
}
2829
}
2930

30-
it(args[isConfigProvided ? 1 : 0], async () => {
31+
jestTestType(args[isConfigProvided ? 1 : 0], async () => {
3132
const { browser, context, page } = await jestPlaywright._configSeparateEnv(
3233
options,
3334
true,
@@ -40,11 +41,23 @@ it.jestPlaywrightDebug = (...args) => {
4041
})
4142
}
4243

43-
it.jestPlaywrightConfig = (playwrightOptions, ...args) => {
44+
it.jestPlaywrightDebug = (...args) => {
45+
runDebugTest(it, ...args)
46+
}
47+
48+
it.jestPlaywrightDebug.only = (...args) => {
49+
runDebugTest(it.only, ...args)
50+
}
51+
52+
it.jestPlaywrightDebug.skip = (...args) => {
53+
runDebugTest(it.skip, ...args)
54+
}
55+
56+
const runConfigTest = (jestTypeTest, playwrightOptions, ...args) => {
4457
if (playwrightOptions.browser && playwrightOptions.browser !== browserName) {
4558
it.skip(...args)
4659
} else {
47-
it(args[0], async () => {
60+
jestTypeTest(args[0], async () => {
4861
const {
4962
browser,
5063
context,
@@ -59,6 +72,18 @@ it.jestPlaywrightConfig = (playwrightOptions, ...args) => {
5972
}
6073
}
6174

75+
it.jestPlaywrightConfig = (playwrightOptions, ...args) => {
76+
runConfigTest(it, playwrightOptions, ...args)
77+
}
78+
79+
it.jestPlaywrightConfig.only = (...args) => {
80+
runConfigTest(it.only, ...args)
81+
}
82+
83+
it.jestPlaywrightConfig.skip = (...args) => {
84+
runConfigTest(it.skip, ...args)
85+
}
86+
6287
const customSkip = (skipOption, type, ...args) => {
6388
const skipFlag = getSkipFlag(skipOption, browserName, deviceName)
6489
if (skipFlag) {

src/PlaywrightEnvironment.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ export const getPlaywrightEnv = (basicEnv = 'node'): unknown => {
181181
resultBrowserConfig = config
182182
resultContextOptions = contextOptions
183183
} else {
184+
// TODO Add function for deep objects merging
184185
resultBrowserConfig = {
185186
...this._jestPlaywrightConfig,
186187
launchType,

src/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ export const readConfig = async (
202202

203203
const localConfig = await require(absConfigPath)
204204
validateConfig(localConfig)
205+
// TODO Add function for deep objects merging
205206
return {
206207
...DEFAULT_CONFIG,
207208
...localConfig,

types/global.d.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ type SkipOption = {
2121

2222
type ContextOptions = Parameters<GenericBrowser['connect']>[0]
2323

24-
interface JestParams<T> {
25-
(options: T, name: string, fn?: jest.ProvidesCallback, timeout?: number): void
26-
}
27-
2824
interface JestPlaywright {
2925
/**
3026
* Reset global.page
@@ -83,6 +79,22 @@ interface JestPlaywright {
8379
saveCoverage: (page: Page) => Promise<void>
8480
}
8581

82+
interface JestParams<T> {
83+
(options: T, name: string, fn?: jest.ProvidesCallback, timeout?: number): void
84+
}
85+
86+
// TODO Replace any
87+
interface JestPlaywrightDebug extends JestParams<any> {
88+
(name: string, fn?: jest.ProvidesCallback, timeout?: number): void
89+
skip: JestParams<any> | JestPlaywrightDebug
90+
only: JestParams<any> | JestPlaywrightDebug
91+
}
92+
93+
interface JestPlaywrightConfig extends JestParams<any> {
94+
skip: JestParams<any> | JestPlaywrightConfig
95+
only: JestParams<any> | JestPlaywrightConfig
96+
}
97+
8698
declare global {
8799
const browserName: BrowserType
88100
const deviceName: string | null
@@ -93,13 +105,8 @@ declare global {
93105
namespace jest {
94106
interface It {
95107
jestPlaywrightSkip: JestParams<SkipOption>
96-
jestPlaywrightDebug: (
97-
name: string,
98-
fn?: jest.ProvidesCallback,
99-
timeout?: number,
100-
) => void
101-
// TODO Replace any
102-
jestPlaywrightConfig: JestParams<any>
108+
jestPlaywrightDebug: JestPlaywrightDebug
109+
jestPlaywrightConfig: JestPlaywrightConfig
103110
}
104111
}
105112
}

0 commit comments

Comments
 (0)