From 42e9c95d21d94cbe0a3827fd874b4903ad2abe01 Mon Sep 17 00:00:00 2001 From: Maksim Markelov Date: Fri, 24 Jul 2020 16:05:23 +0300 Subject: [PATCH] jestPlaywright helpers skip and only (#246) * jestPlaywright helpers skip and only * Added some TODOs for merging ongects util function --- extends.js | 33 +++++++++++++++++++++++++++++---- src/PlaywrightEnvironment.ts | 1 + src/utils.ts | 1 + types/global.d.ts | 29 ++++++++++++++++++----------- 4 files changed, 49 insertions(+), 15 deletions(-) diff --git a/extends.js b/extends.js index 8b468874..cd43d264 100644 --- a/extends.js +++ b/extends.js @@ -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 @@ -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, @@ -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, @@ -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, @@ -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) { diff --git a/src/PlaywrightEnvironment.ts b/src/PlaywrightEnvironment.ts index 034e491e..70fff27c 100644 --- a/src/PlaywrightEnvironment.ts +++ b/src/PlaywrightEnvironment.ts @@ -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, diff --git a/src/utils.ts b/src/utils.ts index 9aaf0fe1..e07c7821 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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, diff --git a/types/global.d.ts b/types/global.d.ts index 28b0d905..06a4b596 100644 --- a/types/global.d.ts +++ b/types/global.d.ts @@ -21,10 +21,6 @@ type SkipOption = { type ContextOptions = Parameters[0] -interface JestParams { - (options: T, name: string, fn?: jest.ProvidesCallback, timeout?: number): void -} - interface JestPlaywright { /** * Reset global.page @@ -83,6 +79,22 @@ interface JestPlaywright { saveCoverage: (page: Page) => Promise } +interface JestParams { + (options: T, name: string, fn?: jest.ProvidesCallback, timeout?: number): void +} + +// TODO Replace any +interface JestPlaywrightDebug extends JestParams { + (name: string, fn?: jest.ProvidesCallback, timeout?: number): void + skip: JestParams | JestPlaywrightDebug + only: JestParams | JestPlaywrightDebug +} + +interface JestPlaywrightConfig extends JestParams { + skip: JestParams | JestPlaywrightConfig + only: JestParams | JestPlaywrightConfig +} + declare global { const browserName: BrowserType const deviceName: string | null @@ -93,13 +105,8 @@ declare global { namespace jest { interface It { jestPlaywrightSkip: JestParams - jestPlaywrightDebug: ( - name: string, - fn?: jest.ProvidesCallback, - timeout?: number, - ) => void - // TODO Replace any - jestPlaywrightConfig: JestParams + jestPlaywrightDebug: JestPlaywrightDebug + jestPlaywrightConfig: JestPlaywrightConfig } } }