Skip to content

Commit 18988fd

Browse files
authored
Enable world proxy in parameter transformers (#2465)
1 parent f0ef001 commit 18988fd

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ Please see [CONTRIBUTING.md](./CONTRIBUTING.md) on how to contribute to Cucumber
1313
- `Hook` message now includes `type` ([#2463](https://github.com/cucumber/cucumber-js/pull/2463))
1414
- `TestRunStarted` message now includes `id`; `TestCase` and `TestRunFinished` messages reference it in `testRunStartedId` ([#2463](https://github.com/cucumber/cucumber-js/pull/2463))
1515

16+
### Fixed
17+
- Enable world proxy in parameter transformers ([#2465](https://github.com/cucumber/cucumber-js/pull/2465))
18+
1619
## [11.1.1] - 2024-12-11
1720
### Fixed
1821
- Correctly report error in publish plugin ([#2454](https://github.com/cucumber/cucumber-js/pull/2454))

features/scope_proxies.feature

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Feature: Scope proxies
55
"""
66
Feature: some feature
77
Scenario: some scenario
8-
Given a step
8+
Given somebody called Lucy
99
"""
1010
And a file named "features/support/world.js" with:
1111
"""
@@ -28,11 +28,28 @@ Feature: Scope proxies
2828
Scenario: world and context can be used from appropriate scopes
2929
Given a file named "features/step_definitions/cucumber_steps.js" with:
3030
"""
31-
const {BeforeAll,Given,BeforeStep,Before,world,context} = require('@cucumber/cucumber')
31+
const {defineParameterType,BeforeAll,Given,BeforeStep,Before,world,context} = require('@cucumber/cucumber')
3232
const assert = require('node:assert/strict')
3333
34+
class Person {
35+
#name;
36+
37+
constructor(name) {
38+
this.#name = name
39+
}
40+
}
41+
42+
defineParameterType({
43+
name: 'person',
44+
regexp: /\w+/,
45+
transformer: name => {
46+
assert(world.isWorld())
47+
return new Person(name);
48+
}
49+
})
50+
3451
BeforeAll(() => assert.equal(context.parameters.a, 1))
35-
Given('a step', () => assert(world.isWorld()))
52+
Given('somebody called {person}', (person) => assert(world.isWorld()))
3653
BeforeStep(() => assert(world.isWorld()))
3754
Before(() => assert(world.isWorld()))
3855
"""

src/runtime/step_runner.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ export async function run({
3232
let error: any, result: any, invocationData: IGetInvocationDataResponse
3333

3434
try {
35-
invocationData = await stepDefinition.getInvocationParameters({
36-
hookParameter,
37-
step,
38-
world,
35+
await runInTestCaseScope({ world }, async () => {
36+
invocationData = await stepDefinition.getInvocationParameters({
37+
hookParameter,
38+
step,
39+
world,
40+
})
3941
})
4042
} catch (err) {
4143
error = err

0 commit comments

Comments
 (0)