Skip to content

Commit 76f3361

Browse files
added logic to process duplicates (#8)
1 parent 7b81f5c commit 76f3361

File tree

9 files changed

+81
-10
lines changed

9 files changed

+81
-10
lines changed

.github/workflows/pull-request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ jobs:
2424
uses: mikepenz/action-junit-report@v4
2525
if: always()
2626
with:
27-
report_paths: './test/results.xml'
27+
report_paths: './test/report/results.xml'
2828
fail_on_failure: true

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules/
22
adapter/
33
playwright-report/
44
test-results/
5+
test/report/

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
1212

1313
## [0.3.0]
1414
- :rocket: added _defineCucumber_ util function
15-
15+
- :rocket: added logic to process duplicates
16+
1617
## [0.2.0]
1718
- :rocket: updated fixture implementation
1819

src/adapter.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ for (const feature of features) {
3131
test.beforeEach(world.init);
3232

3333
for (const testCase of tests) {
34-
const tag = testCase.tags.map(tag => tag.name);
34+
const tag = testCase.tags.map((tag: { name: string }) => tag.name);
3535
test(testCase.name, { tag }, async () => {
3636
for (const beforeHook of supportCodeLibrary.beforeTestCaseHookDefinitions) {
3737
if (beforeHook.appliesToTestCase(testCase)) {

src/loader.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,29 @@ const builder = new AstBuilder(uuidFn)
1111
const matcher = new GherkinClassicTokenMatcher();
1212
const parser = new Parser(builder, matcher)
1313

14+
function duplicates(tests: any[]) {
15+
const counts: Record<string, number> = {};
16+
return tests.map(item => {
17+
const name = item.name;
18+
if (!counts[name]) {
19+
counts[name] = 0;
20+
}
21+
if (counts[name]) {
22+
item.name = `${item.name} #${counts[item.name] + 1}`;
23+
}
24+
counts[item.name]++;
25+
return item;
26+
})
27+
}
28+
1429
export function loadFeatures(globPattern: string[]) {
1530
const files = globSync(globPattern);
1631
return files.map(file => {
1732
const filePath = resolve(file);
1833
const gherkinDocument = parser.parse(readFileSync(filePath, 'utf-8'));
1934
return {
2035
feature: gherkinDocument.feature?.name,
21-
tests: compile(gherkinDocument, file, uuidFn)
36+
tests: duplicates(compile(gherkinDocument, file, uuidFn) as any)
2237
}
2338
});
2439
}

test/features/feature.feature

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,9 @@ Feature: test feature
3131

3232
Scenario: attach
3333
Given attach
34+
35+
Scenario: duplicate
36+
Given log
37+
38+
Scenario: duplicate
39+
Given log

test/features/feature2.feature

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Feature: test feature 2
2+
3+
Background:
4+
Given simple step
5+
6+
Scenario: simple scenario
7+
Given open 'https://google.com' url
8+
9+
Scenario Outline: simple scenario <example>
10+
Given open '<example>' url
11+
12+
Examples:
13+
| example |
14+
| https://www.wikipedia.org/ |
15+
| https://www.saucedemo.com/ |
16+
17+
Scenario: data table
18+
Given data table step
19+
| 1 |
20+
| 2 |
21+
22+
Scenario: multiline
23+
Given multiline step
24+
"""
25+
first
26+
second
27+
"""
28+
29+
Scenario: log
30+
Given log
31+
32+
Scenario: attach
33+
Given attach
34+
35+
Scenario: duplicate
36+
Given log
37+
38+
Scenario: duplicate
39+
Given log

test/playwright-e2e.config.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
import {defineConfig, devices} from '@playwright/test';
2-
import {resolve} from 'node:path';
1+
import { defineConfig, devices } from '@playwright/test';
2+
import { resolve } from 'node:path';
3+
import { defineCucumber } from '../src/defineCucumber';
34

4-
process.env.CONFIG = 'test/cucumber.ts';
5-
process.env.PROFILE = 'default';
5+
defineCucumber({
6+
config: 'test/cucumber.ts',
7+
profile: 'default'
8+
});
69

710
/**
811
* Read environment variables from file.
@@ -24,7 +27,10 @@ export default defineConfig({
2427
/* Opt out of parallel tests on CI. */
2528
workers: process.env.CI ? 1 : undefined,
2629
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
27-
reporter: [['junit', { outputFile: 'results.xml' }]],
30+
reporter: [
31+
['html', { outputFolder: 'report' }],
32+
['junit', { outputFile: 'report/report.xml' }]
33+
],
2834
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
2935
use: {
3036
/* Base URL to use in actions like `await page.goto('/')`. */

test/playwright.config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ export default defineConfig({
2121
/* Opt out of parallel tests on CI. */
2222
workers: process.env.CI ? 1 : 1,
2323
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
24-
reporter: 'html',
24+
reporter: [
25+
['html', { outputFolder: 'report' }],
26+
['junit', { outputFile: 'report/report.xml' }]
27+
],
2528
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
2629
use: {
2730
/* Base URL to use in actions like `await page.goto('/')`. */

0 commit comments

Comments
 (0)