-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
preserve arg types in call-step-from-step functions (#243)
- Loading branch information
Showing
15 changed files
with
102 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,32 @@ | ||
import { Given as GivenC, When as WhenC, Then as ThenC } from '@cucumber/cucumber'; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import * as cucumber from '@cucumber/cucumber'; | ||
import { test as base, createBdd } from 'playwright-bdd'; | ||
|
||
const isPlaywrightRun = Boolean(process.env.PLAYWRIGHT_BDD_CONFIGS); | ||
|
||
export const test = base.extend({ | ||
world: ({}, use, testInfo) => use({ testInfo }), | ||
}); | ||
const pwBdd = createBdd(test, { worldFixture: 'world' }); | ||
|
||
const isPlaywrightRun = Boolean(process.env.PLAYWRIGHT_BDD_CONFIGS); | ||
type StepFn = (this: Record<string, any>, ...args: any[]) => unknown; | ||
|
||
export const Given = function (pattern: string, fn: StepFn) { | ||
return isPlaywrightRun ? pwBdd.Given(pattern, fn) : cucumber.Given(pattern, fn); | ||
}; | ||
|
||
export const When = function (pattern: string, fn: StepFn) { | ||
return isPlaywrightRun ? pwBdd.When(pattern, fn) : cucumber.When(pattern, fn); | ||
}; | ||
|
||
export const Then = function (pattern: string, fn: StepFn) { | ||
return isPlaywrightRun ? pwBdd.Then(pattern, fn) : cucumber.Then(pattern, fn); | ||
}; | ||
|
||
export const { Given, When, Then } = isPlaywrightRun | ||
? createBdd(test, { worldFixture: 'world' }) | ||
: { Given: GivenC, When: WhenC, Then: ThenC }; | ||
export const Before = function (options: any, fn: StepFn) { | ||
return isPlaywrightRun ? pwBdd.Before(options, fn) : cucumber.Before(options, fn); | ||
}; | ||
|
||
export const { Before, After } = createBdd(test, { worldFixture: 'world' }); | ||
export const After = function (options: any, fn: StepFn) { | ||
return isPlaywrightRun ? pwBdd.After(options, fn) : cucumber.After(options, fn); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
Feature: call step from step | ||
Feature: reuse step fn | ||
|
||
@success | ||
Scenario: create todos | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,23 @@ | ||
import { createBdd, DataTable } from 'playwright-bdd'; | ||
import { test } from './fixtures'; | ||
import { test, World } from './fixtures'; | ||
import { expect } from '@playwright/test'; | ||
import { expectTypeOf } from 'expect-type'; | ||
|
||
const { When, Then } = createBdd(test, { worldFixture: 'world' }); | ||
|
||
const createTodo = When('I create todo {string}', async function (text: string) { | ||
this.todos.push(`${this.testInfo.title} - ${text}`); | ||
}); | ||
|
||
expectTypeOf(createTodo).toBeFunction(); | ||
expectTypeOf(createTodo).thisParameter.toEqualTypeOf<World>(); | ||
expectTypeOf(createTodo).parameter(0).toEqualTypeOf<string>(); | ||
|
||
When('I create 2 todos {string} and {string}', async function (text1: string, text2: string) { | ||
await createTodo.call(this, text1); | ||
await createTodo.call(this, text2); | ||
}); | ||
|
||
When( | ||
'I incorrectly create 2 todos {string} and {string}', | ||
async function (_text1: string, _text2: string) { | ||
// TS automatically blocks these invalid calls! | ||
// await createTodo(text1); | ||
// await createTodo.call({}, text2); | ||
}, | ||
); | ||
|
||
Then('I see todos:', async function (data: DataTable) { | ||
expect(this.todos).toEqual(data.rows().flat()); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters