Skip to content

Commit

Permalink
duplicate steps: improve message
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalets committed Oct 24, 2024
1 parent a9b55f4 commit 3238898
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
5 changes: 2 additions & 3 deletions src/steps/finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ export function formatDuplicateStepsMessage(
});

return [
`Multiple step definitions found!`,
`Step: ${stepTextWithKeyword}`,
`File: ${stepLocation}`,
`Multiple definitions (${matchedSteps.length}) matched scenario step!`,
`Step: ${stepTextWithKeyword} # ${stepLocation}`,
...stepLines,
].join('\n');
}
15 changes: 6 additions & 9 deletions test/duplicate-steps/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ const testDir = new TestDir(import.meta);

test(`${testDir.name} (main thread - regular steps)`, () => {
const error = [
`Multiple step definitions found`,
`Step: Given duplicate step`,
`File: ${normalize('features/sample.feature:5:5')}`,
`Multiple definitions (3) matched scenario step`,
`Step: Given duplicate step # ${normalize('features/sample.feature:5:5')}`,
` - Given 'duplicate step' # ${normalize('steps/steps.ts')}:6`,
` - Given 'duplicate step' # ${normalize('steps/steps.ts')}:7`,
` - Given 'duplicate step' # ${normalize('steps/steps.ts')}:8`,
Expand All @@ -25,9 +24,8 @@ test(`${testDir.name} (main thread - regular steps)`, () => {

test(`${testDir.name} (main thread - decorator steps)`, () => {
const error = [
`Multiple step definitions found`,
`Step: Given duplicate decorator step`,
`File: ${normalize('features/sample.feature:9:5')}`,
`Multiple definitions (3) matched scenario step`,
`Step: Given duplicate decorator step # ${normalize('features/sample.feature:9:5')}`,
` - Given 'duplicate decorator step' # ${normalize('steps/TodoPage.ts')}:7`,
` - Given 'duplicate decorator step' # ${normalize('steps/TodoPage.ts')}:10`,
` - Given 'duplicate decorator step' # ${normalize('steps/TodoPage.ts')}:13`,
Expand All @@ -40,9 +38,8 @@ test(`${testDir.name} (main thread - decorator steps)`, () => {

test(`${testDir.name} (worker - regular steps)`, () => {
const error = [
`Multiple step definitions found`,
`Step: Given duplicate step`,
`File: ${normalize('features/sample.feature:5:5')}`,
`Multiple definitions (3) matched scenario step`,
`Step: Given duplicate step # ${normalize('features/sample.feature:5:5')}`,
` - Given 'duplicate step' # ${normalize('steps/steps.ts')}:6`,
` - Given 'duplicate step' # ${normalize('steps/steps.ts')}:7`,
` - Given 'duplicate step' # ${normalize('steps/steps.ts')}:8`,
Expand Down
9 changes: 4 additions & 5 deletions test/match-keywords/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ test(`${testDir.name} (fail)`, () => {
execPlaywrightTestWithError(
testDir.name,
[
`Multiple step definitions found`, // prettier-ignore
`Step: Given duplicate step 1`,
`File: ${normalize('features/fail/sample.feature:4:5')}`,
`Given 'duplicate step 1' # ${normalize('features/fail/steps.ts:5')}`,
`Given 'duplicate step {int}' # ${normalize('features/fail/steps.ts:6')}`,
`Multiple definitions (2) matched scenario step`, // prettier-ignore
`Step: Given duplicate step 1 # ${normalize('features/fail/sample.feature:4:5')}`,
`- Given 'duplicate step 1' # ${normalize('features/fail/steps.ts:5')}`,
`- Given 'duplicate step {int}' # ${normalize('features/fail/steps.ts:6')}`,
],
{ env: { PROJECT: 'fail' } },
);
Expand Down

0 comments on commit 3238898

Please sign in to comment.