diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index b886c014..3a269727 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -35,10 +35,12 @@ jobs: playwrightVersion: ${{ fromJson(needs.get-playwright-versions.outputs.versions) }} cucumberVersion: ['9'] include: - # there were breaking changes in cucumber 10.1 -> test on both 10.0 and 10 + # there were breaking changes in cucumber 10.x -> test on 10.0 and 10.1 - playwrightVersion: '1.37' cucumberVersion: '10.0' - playwrightVersion: '1.38' + cucumberVersion: '10.1' + - playwrightVersion: '1.39' cucumberVersion: '10' steps: - uses: actions/checkout@v3 diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ea615b4..2197e52b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,10 @@ # Changelog +## 5.7.1 +* support Cucumber 10.2 + ## 5.7.0 -* suppport Cucumber 10.1, [#80](https://github.com/vitalets/playwright-bdd/issues/80) +* support Cucumber 10.1, [#80](https://github.com/vitalets/playwright-bdd/issues/80) ## 5.6.0 * support component tests, [#57](https://github.com/vitalets/playwright-bdd/issues/57) diff --git a/docs/ide-integration.md b/docs/ide-integration.md index 4233b71e..5c98503b 100644 --- a/docs/ide-integration.md +++ b/docs/ide-integration.md @@ -9,8 +9,8 @@ Playwright-bdd provides support for all Playwright IDE integrations, because gen * [Cucumber autocomplete extension](https://marketplace.visualstudio.com/items?itemName=alexkrechik.cucumberautocomplete) works as usual: -## Intellij Idea / Aqua +## IntelliJ IDE / Aqua Built-in Playwright support works as usual: -> You may need to set path to Playwright executable in [Run Configuration Template](https://www.jetbrains.com/help/idea/run-debug-configuration.html#change-template) to avoid popup window before every test run \ No newline at end of file +> You may need to set path to Playwright executable in [Run Configuration Template](https://www.jetbrains.com/help/idea/run-debug-configuration.html#change-template) to avoid popup window before every test run diff --git a/docs/index.md b/docs/index.md index 238011a9..7e83d7d7 100644 --- a/docs/index.md +++ b/docs/index.md @@ -56,7 +56,7 @@ test.describe('Playwright site', () => { ``` ### Phase 2: Run tests -CLI commmand `npx playwright test` runs generated test files with Playwright runner. +CLI command `npx playwright test` runs generated test files with Playwright runner. Playwright-bdd makes Playwright API available in step definitions (`page`, `browser`, etc): ```js @@ -73,4 +73,4 @@ Then('I see in title {string}', async ({ page }, text) => { }); ``` -Proceed to [installation guide](installation.md) to try it in action! \ No newline at end of file +Proceed to [installation guide](installation.md) to try it in action! diff --git a/docs/installation.md b/docs/installation.md index bd63cbe9..69ee9774 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -8,7 +8,7 @@ npm i -D playwright-bdd This package uses `@playwright/test` and `@cucumber/cucumber` as a peer dependencies. For brand new projects they will be installed automatically with `playwright-bdd`. -For existing projects you may need to update them to the latest verions: +For existing projects you may need to update them to the latest versions: ``` npm i -D @playwright/test @cucumber/cucumber @@ -18,4 +18,4 @@ After installing/updating Playwright you need to [install browsers](https://play ``` npx playwright install -``` \ No newline at end of file +``` diff --git a/docs/writing-features.md b/docs/writing-features.md index 988602e8..0c19e864 100644 --- a/docs/writing-features.md +++ b/docs/writing-features.md @@ -60,7 +60,7 @@ It can be not reliable for reporters that keep track of test history, because on There are 3 ways to set consistent title for examples. #### 1. Use scenario name as a template -You can add column names like `` to the scenario name. In that case sceanrio name will be used as a title template for generated examples. E.g.: +You can add column names like `` to the scenario name. In that case scenario name will be used as a title template for generated examples. E.g.: ```gherkin Feature: Localization @@ -194,7 +194,7 @@ Strictly use only the following step definitions: {steps list from bddgen export} ``` -> Feel free to imporve that template and share the results +> Feel free to improve that template and share the results Filled prompt for Todo app: ``` diff --git a/docs/writing-steps.md b/docs/writing-steps.md index af070a30..ecc1803c 100644 --- a/docs/writing-steps.md +++ b/docs/writing-steps.md @@ -4,7 +4,7 @@ There are two ways of writing step definitions: 2. **Cucumber-style** - recommended for migrating existing CucumberJS projects to Playwright runner ## Playwright-style -Playwright-style allows you to write step definitions like a regular playwright tests. +Playwright-style allows you to write step definitions like regular Playwright tests. You get all benefits of [built-in fixtures](https://playwright.dev/docs/test-fixtures#built-in-fixtures) as well as [custom fixtures](https://playwright.dev/docs/test-fixtures#with-fixtures). Playwright-style highlights: @@ -306,7 +306,7 @@ When('I open todo page', async function () { ``` For **TypeScript** you can pass `typeof test` as a second generic parameter to `BddWorld` -to get propper typing: +to get proper typing: ```ts type MyWorld = BddWorld; diff --git a/package-lock.json b/package-lock.json index ef603399..bf002840 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "playwright-bdd", - "version": "5.7.0", + "version": "5.7.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "playwright-bdd", - "version": "5.7.0", + "version": "5.7.1", "license": "MIT", "dependencies": { "commander": "^11.1.0", diff --git a/package.json b/package.json index 8ab3990c..20437af2 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "playwright-bdd", "description": "BDD Testing with Playwright runner and CucumberJS", - "version": "5.7.0", + "version": "5.7.1", "type": "commonjs", "bin": { "bddgen": "./dist/cli/index.js" diff --git a/src/cucumber/buildStepDefinition.ts b/src/cucumber/buildStepDefinition.ts index ddbb3aff..30eac434 100644 --- a/src/cucumber/buildStepDefinition.ts +++ b/src/cucumber/buildStepDefinition.ts @@ -6,7 +6,7 @@ import { IdGenerator } from '@cucumber/messages'; import { CucumberExpression, RegularExpression } from '@cucumber/cucumber-expressions'; import { GherkinStepKeyword } from '@cucumber/cucumber/lib/models/gherkin_step_keyword'; import StepDefinition from '@cucumber/cucumber/lib/models/step_definition'; -import { ISupportCodeLibrary } from '@cucumber/cucumber/api'; +import { ISupportCodeLibrary } from './types'; /* eslint-disable @typescript-eslint/no-explicit-any */ diff --git a/src/cucumber/loadSnippetBuilder.ts b/src/cucumber/loadSnippetBuilder.ts index 925f2ec4..672681cb 100644 --- a/src/cucumber/loadSnippetBuilder.ts +++ b/src/cucumber/loadSnippetBuilder.ts @@ -4,8 +4,8 @@ */ import { FormatterBuilder } from '@cucumber/cucumber'; -import { ISupportCodeLibrary } from '@cucumber/cucumber/api'; import { SnippetInterface } from '@cucumber/cucumber/lib/formatter/step_definition_snippet_builder/snippet_syntax'; +import { ISupportCodeLibrary } from './types'; export async function loadSnippetBuilder( supportCodeLibrary: ISupportCodeLibrary, @@ -16,6 +16,8 @@ export async function loadSnippetBuilder( cwd: process.cwd(), snippetInterface, snippetSyntax, + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore it's safe to use our ISupportCodeLibrary because only .parameterTypeRegistry is used supportCodeLibrary, }); } diff --git a/src/cucumber/loadSteps.ts b/src/cucumber/loadSteps.ts index 62017cd3..e58cacc0 100644 --- a/src/cucumber/loadSteps.ts +++ b/src/cucumber/loadSteps.ts @@ -1,7 +1,7 @@ import { IRunConfiguration, IRunEnvironment, loadSupport } from '@cucumber/cucumber/api'; -import { ISupportCodeLibrary } from '@cucumber/cucumber/lib/support_code_library_builder/types'; import { installTransform } from '../playwright/transform'; import { exit } from '../utils/exit'; +import { ISupportCodeLibrary } from './types'; const cache = new Map>(); @@ -16,7 +16,9 @@ export async function loadSteps( // use Playwright's built-in hook to compile TypeScript steps // eslint-disable-next-line @typescript-eslint/no-empty-function const uninstall = !hasTsNodeRegister(runConfiguration) ? installTransform() : () => {}; - lib = loadSupport(runConfiguration, environment).finally(() => uninstall()); + lib = loadSupport(runConfiguration, environment).finally(() => + uninstall(), + ) as Promise; cache.set(cacheKey, lib); } diff --git a/src/cucumber/types.ts b/src/cucumber/types.ts new file mode 100644 index 00000000..82abfa77 --- /dev/null +++ b/src/cucumber/types.ts @@ -0,0 +1,22 @@ +/** + * Cucumber types. + * Use types from here to be independent from changes in Cucumber. + * + * See: https://github.com/cucumber/cucumber-js/blob/main/src/support_code_library_builder/types.ts#L153 + */ +import type { ParameterTypeRegistry } from '@cucumber/cucumber-expressions'; +import type StepDefinition from '@cucumber/cucumber/lib/models/step_definition'; + +export interface ISupportCodeLibrary { + parameterTypeRegistry: ParameterTypeRegistry; + stepDefinitions: StepDefinition[]; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + World: any; + originalCoordinates: ISupportCodeCoordinates; +} + +interface ISupportCodeCoordinates { + requireModules: string[]; + requirePaths: string[]; + importPaths: string[]; +} diff --git a/src/gen/index.ts b/src/gen/index.ts index e6d67bec..33b7340c 100644 --- a/src/gen/index.ts +++ b/src/gen/index.ts @@ -9,7 +9,6 @@ import { TestFile } from './testFile'; import { loadConfig as loadCucumberConfig } from '../cucumber/loadConfig'; import { loadFeatures } from '../cucumber/loadFeatures'; import { hasTsNodeRegister, loadSteps } from '../cucumber/loadSteps'; -import { ISupportCodeLibrary } from '@cucumber/cucumber/lib/support_code_library_builder/types'; import { extractCucumberConfig, BDDConfig } from '../config'; import { Snippets } from '../snippets'; import { IRunConfiguration } from '@cucumber/cucumber/api'; @@ -20,6 +19,7 @@ import { Logger } from '../utils/logger'; import parseTagsExpression from '@cucumber/tag-expressions'; import { exit, withExitHandler } from '../utils/exit'; import { hasCustomTest } from '../stepDefinitions/createBdd'; +import { ISupportCodeLibrary } from '../cucumber/types'; /* eslint-disable @typescript-eslint/no-non-null-assertion */ diff --git a/src/gen/testFile.ts b/src/gen/testFile.ts index 26ec47a6..ebbf72fd 100644 --- a/src/gen/testFile.ts +++ b/src/gen/testFile.ts @@ -22,7 +22,6 @@ import fs from 'node:fs'; import path from 'node:path'; import { Formatter } from './formatter'; import { KeywordsMap, getKeywordsMap } from './i18n'; -import { ISupportCodeLibrary } from '@cucumber/cucumber/lib/support_code_library_builder/types'; import { findStepDefinition } from '../cucumber/loadSteps'; import { BDDConfig } from '../config'; import { KeywordType, getStepKeywordType } from '@cucumber/cucumber/lib/formatter/helpers/index'; @@ -38,6 +37,7 @@ import StepDefinition from '@cucumber/cucumber/lib/models/step_definition'; import { hasScenarioHooks, getScenarioHooksFixtures } from '../hooks/scenario'; import { getWorkerHooksFixtures } from '../hooks/worker'; import { LANG_EN, isEnglish } from '../config/lang'; +import { ISupportCodeLibrary } from '../cucumber/types'; type TestFileOptions = { doc: GherkinDocument; diff --git a/src/run/bddFixtures.ts b/src/run/bddFixtures.ts index b17a1d93..b6d05cfd 100644 --- a/src/run/bddFixtures.ts +++ b/src/run/bddFixtures.ts @@ -9,8 +9,9 @@ import { appendDecoratorSteps } from '../stepDefinitions/decorators/steps'; import { getPlaywrightConfigDir } from '../config/dir'; import { runScenarioHooks } from '../hooks/scenario'; import { runWorkerHooks } from '../hooks/worker'; -import { IRunConfiguration, ISupportCodeLibrary } from '@cucumber/cucumber/api'; +import { IRunConfiguration } from '@cucumber/cucumber/api'; import { StepInvoker } from './StepInvoker'; +import { ISupportCodeLibrary } from '../cucumber/types'; // BDD fixtures prefixed with '$' to avoid collision with user's fixtures. diff --git a/src/run/bddWorld.ts b/src/run/bddWorld.ts index 70f0f4e1..cde65fd7 100644 --- a/src/run/bddWorld.ts +++ b/src/run/bddWorld.ts @@ -1,7 +1,7 @@ import { APIRequestContext, Browser, BrowserContext, Page, TestInfo } from '@playwright/test'; import { World as CucumberWorld, IWorldOptions } from '@cucumber/cucumber'; -import { ISupportCodeLibrary } from '@cucumber/cucumber/lib/support_code_library_builder/types'; import { Fixtures, TestTypeCommon } from '../playwright/types'; +import { ISupportCodeLibrary } from '../cucumber/types'; export type BddWorldFixtures = { page: Page; diff --git a/src/snippets/index.ts b/src/snippets/index.ts index c922962f..1d8be413 100644 --- a/src/snippets/index.ts +++ b/src/snippets/index.ts @@ -3,12 +3,14 @@ */ import { pathToFileURL } from 'node:url'; -import { IRunConfiguration, ISupportCodeLibrary } from '@cucumber/cucumber/api'; +import { IRunConfiguration } from '@cucumber/cucumber/api'; import { loadSnippetBuilder } from '../cucumber/loadSnippetBuilder'; import { TestFile, UndefinedStep } from '../gen/testFile'; import StepDefinitionSnippetBuilder from '@cucumber/cucumber/lib/formatter/step_definition_snippet_builder'; +import { SnippetInterface } from '@cucumber/cucumber/lib/formatter/step_definition_snippet_builder/snippet_syntax'; import { logger } from '../utils/logger'; import { getStepConfig, isDecorator, isPlaywrightStyle } from '../stepDefinitions/stepConfig'; +import { ISupportCodeLibrary } from '../cucumber/types'; export class Snippets { private snippetBuilder!: StepDefinitionSnippetBuilder; @@ -30,13 +32,15 @@ export class Snippets { } private async createSnippetBuilder() { - const { snippetInterface } = this.runConfiguration.formats.options; + const snippetInterface = this.runConfiguration.formats.options.snippetInterface as + | SnippetInterface + | undefined; const snippetSyntax = this.getSnippetSyntax(); return loadSnippetBuilder(this.supportCodeLibrary, snippetInterface, snippetSyntax); } private getSnippetSyntax() { - const { snippetSyntax } = this.runConfiguration.formats.options; + const snippetSyntax = this.runConfiguration.formats.options.snippetSyntax as string | undefined; if (!snippetSyntax && this.isPlaywrightStyle()) { this.bddBuiltInSyntax = true; const filePath = this.isDecorators() diff --git a/src/stepDefinitions/decorators/steps.ts b/src/stepDefinitions/decorators/steps.ts index 2ed19294..b323177d 100644 --- a/src/stepDefinitions/decorators/steps.ts +++ b/src/stepDefinitions/decorators/steps.ts @@ -5,15 +5,13 @@ /* eslint-disable @typescript-eslint/ban-types */ import { isBddAutoInjectFixture } from '../../run/bddFixtures'; -import { - DefineStepPattern, - ISupportCodeLibrary, -} from '@cucumber/cucumber/lib/support_code_library_builder/types'; +import { DefineStepPattern } from '@cucumber/cucumber/lib/support_code_library_builder/types'; import { buildStepDefinition } from '../../cucumber/buildStepDefinition'; import { GherkinStepKeyword } from '@cucumber/cucumber/lib/models/gherkin_step_keyword'; import { StepConfig } from '../stepConfig'; import { buildCucumberStepCode } from '../defineStep'; import { PomNode } from './class'; +import { ISupportCodeLibrary } from '../../cucumber/types'; // initially we sotre step data inside method, // and then extract it in @Fixture decorator call