Skip to content

Commit

Permalink
Add beforeStep to support cucumber framework (#1759)
Browse files Browse the repository at this point in the history
* Add beforeStep to support cucumber framework

* Fix missing name in test

* Add @wdio/types as dev dependency
  • Loading branch information
jbblanchet authored Feb 12, 2025
1 parent b7a6f4a commit eba871d
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 7 deletions.
78 changes: 71 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"@types/jest": "^29.5.12",
"@types/lodash.isequal": "^4.5.8",
"@types/node": "^22.9.0",
"@wdio/types": "^9.9.0",
"@vitest/coverage-v8": "^3.0.5",
"@wdio/eslint": "^0.0.5",
"c8": "^10.1.2",
Expand Down
9 changes: 9 additions & 0 deletions src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ export class SnapshotService implements Services.ServiceInstance {
await this.#snapshotClient.startCurrentRun(test.file, test.fullTitle, this.#options)
}

async beforeStep(step: Frameworks.PickleStep, scenario: Frameworks.Scenario) {
const file = scenario.uri
const testName = `${scenario.name} > ${step.text}`

this.#currentFilePath = file
this.#currentTestName = testName
await this.#snapshotClient.startCurrentRun(file, testName, this.#options)
}

async after() {
const result = await this.#snapshotClient.finishCurrentRun()
if (!result) {
Expand Down
7 changes: 7 additions & 0 deletions test/file.feature.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Snapshot v1

exports[`Fake scenario > Fake step 1`] = `
{
"cucum": "ber",
}
`;
21 changes: 21 additions & 0 deletions test/snapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,24 @@ test('supports snapshot testing', async () => {
.then(() => true, () => false)
expect(expectedSnapfileExist).toBe(true)
})

test('supports cucumber snapshot testing', async () => {
await service.beforeStep({
text: 'Fake step',
} as Frameworks.PickleStep, {
name: 'Fake scenario',
uri: `${__dirname}/file.feature`,
} as Frameworks.Scenario)

const exp = expectExport
expect(exp).toBeDefined()
expect(exp({}).toMatchSnapshot).toBeDefined()
expect(exp({}).toMatchInlineSnapshot).toBeDefined()
await exp({ cucum: 'ber' }).toMatchSnapshot()
await service.after()

const expectedSnapfileExist = await fs.access(path.resolve(__dirname, 'file.feature.snap'))
.then(() => true, () => false)
expect(expectedSnapfileExist).toBe(true)
})

0 comments on commit eba871d

Please sign in to comment.