Skip to content

Commit

Permalink
snippets: improve location display
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalets committed Oct 19, 2024
1 parent 4d5f6ba commit f38ce93
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 16 deletions.
10 changes: 3 additions & 7 deletions src/snippets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
5 changes: 3 additions & 2 deletions src/snippets/snippet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ export class Snippet {
const stepFn = this.getStepFunction();
return [
`${stepType}(${pattern}, ${stepFn}`, // prettier-ignore
` // ...`,
` // {step}`,
` // {location}`,
'});',
].join('\n');
}

private buildDecoratorCode() {
const stepType = this.getStepType();
const pattern = this.getPattern();
return `@${stepType}(${pattern})`;
return `@${stepType}(${pattern}); // {location}`;
}

private getStepType() {
Expand Down
2 changes: 1 addition & 1 deletion test/decorators-snippets/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
6 changes: 2 additions & 4 deletions test/decorators-snippets/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
]),
);
2 changes: 1 addition & 1 deletion test/snippets-cucumber-style/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {`,
]),
);
2 changes: 1 addition & 1 deletion test/snippets-playwright-style/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {`,
Expand Down

0 comments on commit f38ce93

Please sign in to comment.