Skip to content

Commit

Permalink
Enable world proxy in parameter transformers (#2465)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjgoss authored Jan 8, 2025
1 parent f0ef001 commit 18988fd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
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

0 comments on commit 18988fd

Please sign in to comment.