Skip to content

Commit eba871d

Browse files
authored
Add beforeStep to support cucumber framework (#1759)
* Add beforeStep to support cucumber framework * Fix missing name in test * Add @wdio/types as dev dependency
1 parent b7a6f4a commit eba871d

File tree

5 files changed

+109
-7
lines changed

5 files changed

+109
-7
lines changed

package-lock.json

Lines changed: 71 additions & 7 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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"@types/jest": "^29.5.12",
6969
"@types/lodash.isequal": "^4.5.8",
7070
"@types/node": "^22.9.0",
71+
"@wdio/types": "^9.9.0",
7172
"@vitest/coverage-v8": "^3.0.5",
7273
"@wdio/eslint": "^0.0.5",
7374
"c8": "^10.1.2",

src/snapshot.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ export class SnapshotService implements Services.ServiceInstance {
8282
await this.#snapshotClient.startCurrentRun(test.file, test.fullTitle, this.#options)
8383
}
8484

85+
async beforeStep(step: Frameworks.PickleStep, scenario: Frameworks.Scenario) {
86+
const file = scenario.uri
87+
const testName = `${scenario.name} > ${step.text}`
88+
89+
this.#currentFilePath = file
90+
this.#currentTestName = testName
91+
await this.#snapshotClient.startCurrentRun(file, testName, this.#options)
92+
}
93+
8594
async after() {
8695
const result = await this.#snapshotClient.finishCurrentRun()
8796
if (!result) {

test/file.feature.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Snapshot v1
2+
3+
exports[`Fake scenario > Fake step 1`] = `
4+
{
5+
"cucum": "ber",
6+
}
7+
`;

test/snapshot.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,24 @@ test('supports snapshot testing', async () => {
3333
.then(() => true, () => false)
3434
expect(expectedSnapfileExist).toBe(true)
3535
})
36+
37+
test('supports cucumber snapshot testing', async () => {
38+
await service.beforeStep({
39+
text: 'Fake step',
40+
} as Frameworks.PickleStep, {
41+
name: 'Fake scenario',
42+
uri: `${__dirname}/file.feature`,
43+
} as Frameworks.Scenario)
44+
45+
const exp = expectExport
46+
expect(exp).toBeDefined()
47+
expect(exp({}).toMatchSnapshot).toBeDefined()
48+
expect(exp({}).toMatchInlineSnapshot).toBeDefined()
49+
await exp({ cucum: 'ber' }).toMatchSnapshot()
50+
await service.after()
51+
52+
const expectedSnapfileExist = await fs.access(path.resolve(__dirname, 'file.feature.snap'))
53+
.then(() => true, () => false)
54+
expect(expectedSnapfileExist).toBe(true)
55+
})
56+

0 commit comments

Comments
 (0)