Skip to content

Commit 851a146

Browse files
improved BeforeStep/AfterStep logging and fixed BeforeAll/AfterAll behavior (#21)
improved BeforeStep/AfterStep logging and fixed BeforeAll/AfterAll behavior
1 parent 42f5246 commit 851a146

File tree

5 files changed

+43
-34
lines changed

5 files changed

+43
-34
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
1010
:pencil: - chore
1111
:microscope: - experimental
1212

13+
## [1.1.0]
14+
- :rocket: improved BeforeStep/AfterStep logging
15+
- :beetle: fixed BeforeAll/AfterAll behavior
16+
1317
## [1.0.1]
1418
- :pencil: updated dependencies
1519
- :rocket: renamed adapter spec to cucumber.spec.ts

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@qavajs/playwright-runner-adapter",
3-
"version": "1.0.1",
3+
"version": "1.1.0",
44
"description": "adapter for playwright test runner",
55
"scripts": {
66
"build": "tsc",
@@ -16,7 +16,7 @@
1616
"devDependencies": {
1717
"@cucumber/cucumber": "^11.1.1",
1818
"@playwright/test": "^1.49.1",
19-
"@types/node": "^22.10.2",
19+
"@types/node": "^22.10.5",
2020
"typescript": "^5.7.2"
2121
}
2222
}

src/cucumber.spec.ts

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@ function attach(this: { test: any }, body: any, details: any) {
1515
const fixture = new supportCodeLibrary.World({});
1616
const test = fixture.test;
1717

18+
for (const beforeAllHook of supportCodeLibrary.beforeTestRunHookDefinitions) {
19+
test.beforeAll(() => beforeAllHook.code.apply({}));
20+
}
21+
1822
for (const feature of features) {
1923
const tests = feature.tests;
2024
test.describe(feature.feature as string, async () => {
21-
for (const beforeAllHook of supportCodeLibrary.beforeTestRunHookDefinitions) {
22-
test.beforeAll(async () => {
23-
await beforeAllHook.code.apply({});
24-
});
25-
}
26-
2725
const world = new supportCodeLibrary.World({
2826
log,
2927
attach,
@@ -39,28 +37,26 @@ for (const feature of features) {
3937
for (const beforeHook of supportCodeLibrary.beforeTestCaseHookDefinitions) {
4038
if (beforeHook.appliesToTestCase(testCase)) {
4139
const hookName = beforeHook.name ?? 'Before';
42-
await test.step(hookName, async () => {
43-
await beforeHook.code.apply(world, [{
44-
pickle: testCase
45-
}]);
46-
});
40+
await test.step(hookName, () => beforeHook.code.apply(world, [{
41+
pickle: testCase
42+
}]));
4743
}
4844
}
4945
for (const pickleStep of testCase.steps) {
5046
await test.step(pickleStep.text, async () => {
5147
for (const beforeStep of supportCodeLibrary.beforeTestStepHookDefinitions) {
5248
if (beforeStep.appliesToTestCase(testCase)) {
53-
await beforeStep.code.apply(world, [{
49+
await test.step('Before Step', () => beforeStep.code.apply(world, [{
5450
pickle: testCase,
5551
pickleStep
56-
}]);
52+
}]));
5753
}
5854
}
5955
const steps = supportCodeLibrary.stepDefinitions
6056
.filter(stepDefinition => stepDefinition.matchesStepName(pickleStep.text));
6157
if (steps.length === 0) throw new Error(`Step '${pickleStep.text}' is not defined`);
6258
if (steps.length > 1) throw new Error(`'${pickleStep.text}' matches multiple step definitions`);
63-
const [step] = steps;
59+
const [ step ] = steps;
6460
const { parameters} = await step.getInvocationParameters({
6561
step: {
6662
text: pickleStep.text,
@@ -76,11 +72,11 @@ for (const feature of features) {
7672
}
7773
for (const afterStep of supportCodeLibrary.afterTestStepHookDefinitions) {
7874
if (afterStep.appliesToTestCase(testCase)) {
79-
await afterStep.code.apply(world, [{
75+
await test.step('After Step', () => afterStep.code.apply(world, [{
8076
pickle: testCase,
8177
pickleStep,
8278
result
83-
}]);
79+
}]));
8480
}
8581
}
8682
if (result.error) throw result.error;
@@ -89,19 +85,16 @@ for (const feature of features) {
8985
for (const afterHook of supportCodeLibrary.afterTestCaseHookDefinitions) {
9086
if (afterHook.appliesToTestCase(testCase)) {
9187
const hookName = afterHook.name ?? 'After';
92-
await test.step(hookName, async () => {
93-
await afterHook.code.apply(world, [{
94-
pickle: testCase, result
95-
}]);
96-
});
88+
await test.step(hookName, () => afterHook.code.apply(world, [{
89+
pickle: testCase, result
90+
}]));
9791
}
9892
}
9993
})
10094
}
101-
for (const afterAllHook of supportCodeLibrary.afterTestRunHookDefinitions) {
102-
test.afterAll(async function () {
103-
await afterAllHook.code.apply({});
104-
});
105-
}
10695
});
10796
}
97+
98+
for (const afterAllHook of supportCodeLibrary.afterTestRunHookDefinitions) {
99+
test.afterAll(() => afterAllHook.code.apply({}));
100+
}

test/step_definitions/steps.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
After,
88
BeforeStep,
99
AfterStep,
10+
BeforeAll,
11+
AfterAll,
1012
ITestCaseHookParameter, ITestStepHookParameter
1113
} from '@cucumber/cucumber';
1214
import { test as base, expect as baseExpect, Page, Locator } from '@playwright/test';
@@ -114,4 +116,14 @@ Before({name: 'Named Before'}, async function (this: ExtendedPlaywrightWorld, te
114116
After({name: 'Named After'}, async function (this: ExtendedPlaywrightWorld, testCase: ITestCaseHookParameter) {
115117
this.expect(testCase.pickle).toBeTruthy();
116118
this.expect(testCase.result).toBeTruthy();
119+
});
120+
121+
BeforeAll(async function () {
122+
console.log('Before All');
123+
customExpect(1).toEqual(1);
124+
});
125+
126+
AfterAll(async function () {
127+
console.log('After All');
128+
customExpect(2).toEqual(2);
117129
});

0 commit comments

Comments
 (0)