diff --git a/src/snippets/index.ts b/src/snippets/index.ts index c90995d9..7797a784 100644 --- a/src/snippets/index.ts +++ b/src/snippets/index.ts @@ -54,13 +54,9 @@ export class Snippets { // use snippet code as unique key if (this.snippets.has(snippet.code)) return; const { uri, line, column } = missingStep.location; - const snippetWithLocation = snippet.code.replace( - '// ...', - [ - `// Step: ${missingStep.textWithKeyword}`, // prettier-ignore - `// File: ${uri}:${line}:${column}`, - ].join('\n '), - ); + const snippetWithLocation = snippet.code + .replace('{step}', `Step: ${missingStep.textWithKeyword}`) + .replace('{location}', `From: ${uri}:${line}:${column}`); this.snippets.set(snippet.code, snippetWithLocation); } diff --git a/src/snippets/snippet.ts b/src/snippets/snippet.ts index 1269cd3f..204edf7c 100644 --- a/src/snippets/snippet.ts +++ b/src/snippets/snippet.ts @@ -31,7 +31,8 @@ export class Snippet { const stepFn = this.getStepFunction(); return [ `${stepType}(${pattern}, ${stepFn}`, // prettier-ignore - ` // ...`, + ` // {step}`, + ` // {location}`, '});', ].join('\n'); } @@ -39,7 +40,7 @@ export class Snippet { private buildDecoratorCode() { const stepType = this.getStepType(); const pattern = this.getPattern(); - return `@${stepType}(${pattern})`; + return `@${stepType}(${pattern}); // {location}`; } private getStepType() { diff --git a/test/decorators-snippets/playwright.config.ts b/test/decorators-snippets/playwright.config.ts index 0c51d9d8..507ba2ed 100644 --- a/test/decorators-snippets/playwright.config.ts +++ b/test/decorators-snippets/playwright.config.ts @@ -2,8 +2,8 @@ import { defineConfig } from '@playwright/test'; import { defineBddConfig } from 'playwright-bdd'; const testDir = defineBddConfig({ + features: '*.feature', steps: 'steps/index.ts', - paths: ['*.feature'], }); export default defineConfig({ diff --git a/test/decorators-snippets/test.mjs b/test/decorators-snippets/test.mjs index 05cb7737..599e52d7 100644 --- a/test/decorators-snippets/test.mjs +++ b/test/decorators-snippets/test.mjs @@ -4,10 +4,8 @@ const testDir = new TestDir(import.meta); test(testDir.name, () => execPlaywrightTestWithError(testDir.name, [ - `// 1. Missing step definition for "sample.feature:5:5"`, - `@When('I add todo {string}')`, - `// 2. Missing step definition for "sample.feature:7:5"`, - `@Then('visible todos count is {int}')`, `Missing step definitions: 2`, + `@When('I add todo {string}'); // From: sample.feature:5:5`, + `@Then('visible todos count is {int}'); // From: sample.feature:7:5`, ]), ); diff --git a/test/snippets-cucumber-style/test.mjs b/test/snippets-cucumber-style/test.mjs index f54952c7..c9b5818b 100644 --- a/test/snippets-cucumber-style/test.mjs +++ b/test/snippets-cucumber-style/test.mjs @@ -7,7 +7,7 @@ test(testDir.name, () => `Missing step definitions: 2`, `Given('Step without parameters', async function () {`, `// Step: Given Step without parameters`, - `// File: sample.feature:4:5`, + `// From: sample.feature:4:5`, `Given('Step with one string parameter {string}', async function (arg: string) {`, ]), ); diff --git a/test/snippets-playwright-style/test.mjs b/test/snippets-playwright-style/test.mjs index e1831a36..d5f2b892 100644 --- a/test/snippets-playwright-style/test.mjs +++ b/test/snippets-playwright-style/test.mjs @@ -8,7 +8,7 @@ test(testDir.name, () => `Given('Step without parameters', async ({}) => {`, `// Step: Given Step without parameters`, - `// File: ${normalize('features/one.feature:4:5')}`, + `// From: ${normalize('features/one.feature:4:5')}`, `Given('Step with one string parameter {string}', async ({}, arg: string) => {`, `Given('Step with two string parameters {string} and {string}', async ({}, arg: string, arg1: string) => {`,