Skip to content

Commit 3d1ef2f

Browse files
make params in hooks closer to cucumber types (#16)
1 parent 2ad2cc5 commit 3d1ef2f

File tree

5 files changed

+42
-16
lines changed

5 files changed

+42
-16
lines changed

CHANGELOG.md

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

13+
## [0.6.1]
14+
- :beetle: make params in hooks closer to cucumber types
15+
1316
## [0.6.0]
1417
- :rocket: added test case accessor to BeforeStep/AfterStep hooks
1518

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@qavajs/playwright-runner-adapter",
3-
"version": "0.6.0",
3+
"version": "0.6.1",
44
"description": "adapter for playwright test runner",
55
"scripts": {
66
"build": "tsc",

src/adapter.spec.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,20 @@ for (const feature of features) {
3838
for (const beforeHook of supportCodeLibrary.beforeTestCaseHookDefinitions) {
3939
if (beforeHook.appliesToTestCase(testCase)) {
4040
await test.step('Before', async () => {
41-
await beforeHook.code.apply(world, [testCase]);
41+
await beforeHook.code.apply(world, [{
42+
pickle: testCase
43+
}]);
4244
});
4345
}
4446
}
4547
for (const pickleStep of testCase.steps) {
4648
await test.step(pickleStep.text, async () => {
4749
for (const beforeStep of supportCodeLibrary.beforeTestStepHookDefinitions) {
4850
if (beforeStep.appliesToTestCase(testCase)) {
49-
await beforeStep.code.apply(world, [testCase]);
51+
await beforeStep.code.apply(world, [{
52+
pickle: testCase,
53+
pickleStep
54+
}]);
5055
}
5156
}
5257
const steps = supportCodeLibrary.stepDefinitions
@@ -69,7 +74,11 @@ for (const feature of features) {
6974
}
7075
for (const afterStep of supportCodeLibrary.afterTestStepHookDefinitions) {
7176
if (afterStep.appliesToTestCase(testCase)) {
72-
await afterStep.code.apply(world, [{...testCase, result}]);
77+
await afterStep.code.apply(world, [{
78+
pickle: testCase,
79+
pickleStep,
80+
result
81+
}]);
7382
}
7483
}
7584
if (result.error) throw result.error;
@@ -78,7 +87,9 @@ for (const feature of features) {
7887
for (const afterHook of supportCodeLibrary.afterTestCaseHookDefinitions) {
7988
if (afterHook.appliesToTestCase(testCase)) {
8089
await test.step('After', async () => {
81-
await afterHook.code.apply(world, [{...testCase, result}]);
90+
await afterHook.code.apply(world, [{
91+
pickle: testCase, result
92+
}]);
8293
});
8394
}
8495
}

test/step_definitions/steps.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
import { Given, When, setWorldConstructor, DataTable, Before, After, BeforeStep, AfterStep } from '@cucumber/cucumber';
1+
import {
2+
Given,
3+
When,
4+
setWorldConstructor,
5+
DataTable,
6+
Before,
7+
After,
8+
BeforeStep,
9+
AfterStep,
10+
ITestCaseHookParameter, ITestStepHookParameter
11+
} from '@cucumber/cucumber';
212
import { test as base, expect as baseExpect, Page, Locator } from '@playwright/test';
313
import { PlaywrightWorld } from '../../src/PlaywrightWorld';
414

@@ -69,20 +79,22 @@ When('custom expect', async function (this: ExtendedPlaywrightWorld) {
6979
this.expect(this.page.locator('body')).toAlwaysPass();
7080
});
7181

72-
Before(async function (this: ExtendedPlaywrightWorld, testCase) {
73-
this.expect(testCase).toBeTruthy();
82+
Before(async function (this: ExtendedPlaywrightWorld, testCase: ITestCaseHookParameter) {
83+
this.expect(testCase.pickle).toBeTruthy();
7484
});
7585

76-
After(async function (this: ExtendedPlaywrightWorld, testCase) {
77-
this.expect(testCase).toBeTruthy();
86+
After(async function (this: ExtendedPlaywrightWorld, testCase: ITestCaseHookParameter) {
87+
this.expect(testCase.pickle).toBeTruthy();
7888
this.expect(testCase.result).toBeTruthy();
7989
});
8090

81-
BeforeStep(async function (this: ExtendedPlaywrightWorld, testCase) {
82-
this.expect(testCase).toBeTruthy();
91+
BeforeStep(async function (this: ExtendedPlaywrightWorld, testCase: ITestStepHookParameter) {
92+
this.expect(testCase.pickle).toBeTruthy();
93+
this.expect(testCase.pickleStep).toBeTruthy();
8394
});
8495

85-
AfterStep(async function (this: ExtendedPlaywrightWorld, testCase) {
86-
this.expect(testCase).toBeTruthy();
96+
AfterStep(async function (this: ExtendedPlaywrightWorld, testCase: ITestStepHookParameter) {
97+
this.expect(testCase.pickle).toBeTruthy();
98+
this.expect(testCase.pickleStep).toBeTruthy();
8799
this.expect(testCase.result).toBeTruthy();
88100
});

0 commit comments

Comments
 (0)