Skip to content

Commit

Permalink
jestPlaywright helpers skip and only (#246)
Browse files Browse the repository at this point in the history
* jestPlaywright helpers skip and only

* Added some TODOs for merging ongects util function
  • Loading branch information
mmarkelov committed Jul 24, 2020
1 parent 6758a9e commit 42e9c95
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 15 deletions.
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
}
}
}

0 comments on commit 42e9c95

Please sign in to comment.