-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: show step locations in unused export and in duplicate steps …
…error (#113)
- Loading branch information
Showing
11 changed files
with
141 additions
and
62 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Feature: duplicate steps | ||
|
||
@duplicate-regular-steps | ||
Scenario: duplicate regular steps | ||
Given duplicate step | ||
|
||
@duplicate-decorator-steps | ||
Scenario: duplicate decorator steps | ||
Given duplicate decorator step | ||
|
||
@no-duplicates | ||
Scenario: no duplicates | ||
Given unique step |
This file was deleted.
Oops, something went wrong.
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,25 +1,49 @@ | ||
import { defineConfig } from '@playwright/test'; | ||
import { defineConfig, Project } from '@playwright/test'; | ||
import { defineBddConfig } from 'playwright-bdd'; | ||
|
||
const PROJECTS = (process.env.PROJECTS || '').split(','); | ||
|
||
export default defineConfig({ | ||
projects: [ | ||
{ | ||
name: 'no duplicate steps', | ||
testDir: defineBddConfig({ | ||
outputDir: `.features-gen/one`, | ||
paths: ['features/one.feature'], | ||
importTestFrom: 'steps/fixtures.ts', | ||
}), | ||
}, | ||
{ | ||
// important to have duplicate steps in the second project | ||
// that runs in a worker process | ||
name: 'duplicates', | ||
testDir: defineBddConfig({ | ||
outputDir: `.features-gen/two`, | ||
paths: ['features/two.feature'], | ||
importTestFrom: 'steps/fixtures.ts', | ||
}), | ||
}, | ||
...(PROJECTS.includes('no-duplicates') ? [noDuplicates()] : []), | ||
...(PROJECTS.includes('duplicate-regular-steps') ? [duplicateRegularSteps()] : []), | ||
...(PROJECTS.includes('duplicate-decorator-steps') ? [duplicateDecoratorSteps()] : []), | ||
], | ||
}); | ||
|
||
function noDuplicates(): Project { | ||
return { | ||
// this project must be first and is needed to run the second project in a worker | ||
name: 'no-duplicates', | ||
testDir: defineBddConfig({ | ||
outputDir: `.features-gen/no-duplicates`, | ||
paths: ['features/*.feature'], | ||
require: ['steps/steps.ts'], | ||
tags: '@no-duplicates', | ||
}), | ||
}; | ||
} | ||
|
||
function duplicateRegularSteps(): Project { | ||
return { | ||
name: 'duplicate-regular-steps', | ||
testDir: defineBddConfig({ | ||
outputDir: `.features-gen/regular`, | ||
paths: ['features/*.feature'], | ||
require: ['steps/steps.ts'], | ||
tags: '@duplicate-regular-steps', | ||
}), | ||
}; | ||
} | ||
|
||
function duplicateDecoratorSteps(): Project { | ||
return { | ||
name: 'duplicate-decorator-steps', | ||
testDir: defineBddConfig({ | ||
outputDir: `.features-gen/decorator`, | ||
paths: ['features/*.feature'], | ||
importTestFrom: 'steps/fixtures.ts', | ||
tags: '@duplicate-decorator-steps', | ||
}), | ||
}; | ||
} |
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,10 +1,6 @@ | ||
import { test as base } from 'playwright-bdd'; | ||
import { TodoPage } from './TodoPage'; | ||
|
||
type Fixtures = { | ||
todoPage: TodoPage; | ||
}; | ||
|
||
export const test = base.extend<Fixtures>({ | ||
export const test = base.extend<{ todoPage: TodoPage }>({ | ||
todoPage: ({}, use) => use(new TodoPage()), | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { createBdd } from 'playwright-bdd'; | ||
|
||
const { Given } = createBdd(); | ||
|
||
Given('unique step', async () => {}); | ||
Given('duplicate step', async () => {}); | ||
Given('duplicate step', async () => {}); | ||
Given(/duplicate step/, async () => {}); |
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,24 +1,49 @@ | ||
import { normalize } from 'node:path'; | ||
import { test, TestDir, execPlaywrightTestWithError, DEFAULT_CMD } from '../_helpers/index.mjs'; | ||
import { | ||
test, | ||
TestDir, | ||
normalize, | ||
execPlaywrightTestWithError, | ||
BDDGEN_CMD, | ||
} from '../_helpers/index.mjs'; | ||
|
||
const testDir = new TestDir(import.meta); | ||
const featureFile = normalize('features/sample.feature'); | ||
|
||
test(`${testDir.name} (main thread)`, () => { | ||
execPlaywrightTestWithError( | ||
testDir.name, | ||
DUPLICATE_STEPS_ERROR, | ||
`${DEFAULT_CMD} --project duplicates`, | ||
); | ||
test(`${testDir.name} (main thread - regular steps)`, () => { | ||
const error = [ | ||
`Multiple step definitions matched for text: "duplicate step" (${featureFile})`, | ||
` duplicate step - steps/steps.ts:6`, | ||
` duplicate step - steps/steps.ts:7`, | ||
` duplicate step - steps/steps.ts:8`, | ||
].join('\n'); | ||
execPlaywrightTestWithError(testDir.name, error, { | ||
cmd: BDDGEN_CMD, | ||
env: { PROJECTS: 'duplicate-regular-steps' }, | ||
}); | ||
}); | ||
|
||
test(`${testDir.name} (worker)`, () => { | ||
execPlaywrightTestWithError(testDir.name, DUPLICATE_STEPS_ERROR); | ||
test(`${testDir.name} (main thread - decorator steps)`, () => { | ||
const error = [ | ||
`Multiple step definitions matched for text: "duplicate decorator step" (${featureFile})`, | ||
` duplicate decorator step - steps/TodoPage.ts:7`, | ||
` duplicate decorator step - steps/TodoPage.ts:10`, | ||
` duplicate decorator step - steps/TodoPage.ts:13`, | ||
].join('\n'); | ||
execPlaywrightTestWithError(testDir.name, error, { | ||
cmd: BDDGEN_CMD, | ||
env: { PROJECTS: 'duplicate-decorator-steps' }, | ||
}); | ||
}); | ||
|
||
const DUPLICATE_STEPS_ERROR = [ | ||
`Multiple step definitions matched for text: "duplicate step" (${normalize( | ||
'features/two.feature', | ||
)})`, | ||
' duplicate step', | ||
' duplicate step', | ||
].join('\n'); | ||
test(`${testDir.name} (worker - regular steps)`, () => { | ||
const error = [ | ||
`Multiple step definitions matched for text: "duplicate step" (${featureFile})`, | ||
` duplicate step - steps/steps.ts:6`, | ||
` duplicate step - steps/steps.ts:7`, | ||
` duplicate step - steps/steps.ts:8`, | ||
].join('\n'); | ||
execPlaywrightTestWithError(testDir.name, error, { | ||
cmd: BDDGEN_CMD, | ||
env: { PROJECTS: 'no-duplicates,duplicate-regular-steps' }, | ||
}); | ||
}); |