Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable world proxy in parameter transformers #2465

Merged
merged 3 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ Please see [CONTRIBUTING.md](./CONTRIBUTING.md) on how to contribute to Cucumber
- `Hook` message now includes `type` ([#2463](https://github.com/cucumber/cucumber-js/pull/2463))
- `TestRunStarted` message now includes `id`; `TestCase` and `TestRunFinished` messages reference it in `testRunStartedId` ([#2463](https://github.com/cucumber/cucumber-js/pull/2463))

### Fixed
- Enable world proxy in parameter transformers ([#2465](https://github.com/cucumber/cucumber-js/pull/2465))

## [11.1.1] - 2024-12-11
### Fixed
- Correctly report error in publish plugin ([#2454](https://github.com/cucumber/cucumber-js/pull/2454))
Expand Down
23 changes: 20 additions & 3 deletions features/scope_proxies.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Feature: Scope proxies
"""
Feature: some feature
Scenario: some scenario
Given a step
Given somebody called Lucy
"""
And a file named "features/support/world.js" with:
"""
Expand All @@ -28,11 +28,28 @@ Feature: Scope proxies
Scenario: world and context can be used from appropriate scopes
Given a file named "features/step_definitions/cucumber_steps.js" with:
"""
const {BeforeAll,Given,BeforeStep,Before,world,context} = require('@cucumber/cucumber')
const {defineParameterType,BeforeAll,Given,BeforeStep,Before,world,context} = require('@cucumber/cucumber')
const assert = require('node:assert/strict')

class Person {
#name;

constructor(name) {
this.#name = name
}
}

defineParameterType({
name: 'person',
regexp: /\w+/,
transformer: name => {
assert(world.isWorld())
return new Person(name);
}
})

BeforeAll(() => assert.equal(context.parameters.a, 1))
Given('a step', () => assert(world.isWorld()))
Given('somebody called {person}', (person) => assert(world.isWorld()))
BeforeStep(() => assert(world.isWorld()))
Before(() => assert(world.isWorld()))
"""
Expand Down
10 changes: 6 additions & 4 deletions src/runtime/step_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ export async function run({
let error: any, result: any, invocationData: IGetInvocationDataResponse

try {
invocationData = await stepDefinition.getInvocationParameters({
hookParameter,
step,
world,
await runInTestCaseScope({ world }, async () => {
invocationData = await stepDefinition.getInvocationParameters({
hookParameter,
step,
world,
})
})
} catch (err) {
error = err
Expand Down
Loading