Skip to content

Commit 70f7f66

Browse files
added gherkinDocument to hooks parameter (#40)
1 parent 5b9a1e3 commit 70f7f66

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
1414

1515
:microscope: - experimental
1616

17+
## [Unreleased]
18+
- :rocket: added `gherkinDocument` to hooks parameter
19+
1720
## [1.7.1]
1821
- :beetle: fixed `result` property in `After` and `AfterStep` hooks
1922

src/cucumber.spec.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { load } from './loader';
22
import type { TestInfo } from '@playwright/test';
3+
import type { ITestCaseHookParameter, ITestStepHookParameter } from '@cucumber/cucumber';
34

45
const { features, supportCodeLibrary } = load();
56

@@ -8,9 +9,9 @@ function getResult(testInfo: TestInfo) {
89
? testInfo.errors.map((err: any) => err.message).join('\n')
910
: undefined;
1011
return {
11-
duration: testInfo.duration,
12+
duration: testInfo.duration as any,
1213
message,
13-
status: testInfo.status,
14+
status: testInfo.status?.toUpperCase(),
1415
exception: testInfo.error
1516
};
1617
}
@@ -68,8 +69,9 @@ for (const feature of features) {
6869
await test.step(
6970
hookName,
7071
() => beforeHook.code.apply(world, [{
72+
gherkinDocument: feature.gherkinDocument,
7173
pickle: testCase
72-
}]),
74+
} as ITestCaseHookParameter]),
7375
location
7476
);
7577
}
@@ -103,6 +105,7 @@ for (const feature of features) {
103105
await test.step(
104106
'Before Step',
105107
() => beforeStep.code.apply(world, [{
108+
gherkinDocument: feature.gherkinDocument,
106109
pickle: testCase,
107110
pickleStep
108111
}]),
@@ -130,15 +133,18 @@ for (const feature of features) {
130133
await test.step(
131134
'After Step',
132135
() => afterStep.code.apply(world, [{
136+
gherkinDocument: feature.gherkinDocument,
137+
testCaseStartedId: '0',
138+
testStepId: '0',
133139
pickle: testCase,
134140
pickleStep,
135141
result: {
136-
duration: 0,
142+
duration: 0 as any,
137143
message: result.error?.message,
138-
status: result.status,
144+
status: result.status.toUpperCase(),
139145
exception: result.error
140146
}
141-
}]),
147+
} as ITestStepHookParameter]),
142148
location
143149
);
144150
}
@@ -163,9 +169,11 @@ for (const feature of features) {
163169
await test.step(
164170
hookName,
165171
() => afterHook.code.apply(world, [{
172+
gherkinDocument: feature.gherkinDocument,
173+
testCaseStartedId: '0',
166174
pickle: testCase,
167175
result: getResult(testInfo)
168-
}]),
176+
} as ITestCaseHookParameter]),
169177
location
170178
);
171179
}

src/loader.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export function loadFeatures(globPattern: string[]) {
3333
const gherkinDocument = parser.parse(readFileSync(filePath, 'utf-8'));
3434
return {
3535
feature: gherkinDocument.feature?.name,
36+
gherkinDocument,
3637
tests: duplicates(compile(gherkinDocument, file, uuidFn) as any)
3738
}
3839
});

test/step_definitions/steps.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,10 @@ Before(async function (this: ExtendedPlaywrightWorld, testCase: ITestCaseHookPar
100100
});
101101

102102
After(async function (this: ExtendedPlaywrightWorld, testCase: ITestCaseHookParameter) {
103+
this.expect(testCase.gherkinDocument).toBeTruthy();
103104
this.expect(testCase.pickle).toBeTruthy();
104105
this.expect(testCase.result).toBeTruthy();
105-
this.expect(testCase.result?.status).toEqual('passed');
106+
this.expect(testCase.result?.status).toEqual('PASSED');
106107
this.expect(testCase.result?.duration).toBeGreaterThan(0);
107108
});
108109

@@ -112,20 +113,22 @@ BeforeStep(async function (this: ExtendedPlaywrightWorld, testCase: ITestStepHoo
112113
});
113114

114115
AfterStep(async function (this: ExtendedPlaywrightWorld, testCase: ITestStepHookParameter) {
116+
this.expect(testCase.gherkinDocument).toBeTruthy();
115117
this.expect(testCase.pickle).toBeTruthy();
116118
this.expect(testCase.pickleStep).toBeTruthy();
117119
this.expect(testCase.result).toBeTruthy();
118-
this.expect(testCase.result?.status).toEqual('passed');
120+
this.expect(testCase.result?.status).toEqual('PASSED');
119121
});
120122

121123
Before({name: 'Named Before'}, async function (this: ExtendedPlaywrightWorld, testCase: ITestCaseHookParameter) {
122124
this.expect(testCase.pickle).toBeTruthy();
123125
});
124126

125127
After({name: 'Named After'}, async function (this: ExtendedPlaywrightWorld, testCase: ITestCaseHookParameter) {
128+
this.expect(testCase.gherkinDocument).toBeTruthy();
126129
this.expect(testCase.pickle).toBeTruthy();
127130
this.expect(testCase.result).toBeTruthy();
128-
this.expect(testCase.result?.status).toEqual('passed');
131+
this.expect(testCase.result?.status).toEqual('PASSED');
129132
this.expect(testCase.result?.duration).toBeGreaterThan(0);
130133
});
131134

0 commit comments

Comments
 (0)