Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

jestPlaywright helpers skip and only #246

Merged
merged 2 commits into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions extends.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const DEBUG_OPTIONS = {
},
}

it.jestPlaywrightDebug = (...args) => {
const runDebugTest = (jestTestType, ...args) => {
const isConfigProvided = typeof args[0] === 'object'
// TODO Looks wierd - need to be rewritten
let options = DEBUG_OPTIONS
Expand All @@ -19,6 +19,7 @@ it.jestPlaywrightDebug = (...args) => {
launchOptions = {},
launchType = DEBUG_OPTIONS.launchType,
} = args[0]
// TODO Add function for deep objects merging
options = {
...DEBUG_OPTIONS,
launchType,
Expand All @@ -27,7 +28,7 @@ it.jestPlaywrightDebug = (...args) => {
}
}

it(args[isConfigProvided ? 1 : 0], async () => {
jestTestType(args[isConfigProvided ? 1 : 0], async () => {
const { browser, context, page } = await jestPlaywright._configSeparateEnv(
options,
true,
Expand All @@ -40,11 +41,23 @@ it.jestPlaywrightDebug = (...args) => {
})
}

it.jestPlaywrightConfig = (playwrightOptions, ...args) => {
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 {
it(args[0], async () => {
jestTypeTest(args[0], async () => {
const {
browser,
context,
Expand All @@ -59,6 +72,18 @@ it.jestPlaywrightConfig = (playwrightOptions, ...args) => {
}
}

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) {
Expand Down
1 change: 1 addition & 0 deletions src/PlaywrightEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export const getPlaywrightEnv = (basicEnv = 'node'): unknown => {
resultBrowserConfig = config
resultContextOptions = contextOptions
} else {
// TODO Add function for deep objects merging
resultBrowserConfig = {
...this._jestPlaywrightConfig,
launchType,
Expand Down
1 change: 1 addition & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export const readConfig = async (

const localConfig = await require(absConfigPath)
validateConfig(localConfig)
// TODO Add function for deep objects merging
return {
...DEFAULT_CONFIG,
...localConfig,
Expand Down
29 changes: 18 additions & 11 deletions types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ type SkipOption = {

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

interface JestParams<T> {
(options: T, name: string, fn?: jest.ProvidesCallback, timeout?: number): void
}

interface JestPlaywright {
/**
* Reset global.page
Expand Down Expand Up @@ -83,6 +79,22 @@ interface JestPlaywright {
saveCoverage: (page: Page) => Promise<void>
}

interface JestParams<T> {
(options: T, name: string, fn?: jest.ProvidesCallback, timeout?: number): void
}

// TODO Replace any
interface JestPlaywrightDebug extends JestParams<any> {
(name: string, fn?: jest.ProvidesCallback, timeout?: number): void
skip: JestParams<any> | JestPlaywrightDebug
only: JestParams<any> | JestPlaywrightDebug
}

interface JestPlaywrightConfig extends JestParams<any> {
skip: JestParams<any> | JestPlaywrightConfig
only: JestParams<any> | JestPlaywrightConfig
}

declare global {
const browserName: BrowserType
const deviceName: string | null
Expand All @@ -93,13 +105,8 @@ declare global {
namespace jest {
interface It {
jestPlaywrightSkip: JestParams<SkipOption>
jestPlaywrightDebug: (
name: string,
fn?: jest.ProvidesCallback,
timeout?: number,
) => void
// TODO Replace any
jestPlaywrightConfig: JestParams<any>
jestPlaywrightDebug: JestPlaywrightDebug
jestPlaywrightConfig: JestPlaywrightConfig
}
}
}