Skip to content

Commit 42af622

Browse files
juan-fernandezleoromanovsky
authored andcommitted
fix(cucumber): support version 13.2 (#9456)
1 parent ddad680 commit 42af622

3 files changed

Lines changed: 30 additions & 11 deletions

File tree

packages/datadog-instrumentations/src/cucumber-worker-threads.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@ const appRequire = createRequire(path.join(process.cwd(), 'package.json'))
99

1010
try {
1111
// Cucumber v13 parallel workers start from an ESM worker.mjs entrypoint, which
12-
// statically imports the internal runtime Worker before it runs support-code
12+
// statically imports the internal runtime Worker/Executor before it runs support-code
1313
// requireModules. The regular module hook does not patch that internal worker
14-
// import, so this preload is injected into requireModules to patch the cached Worker
14+
// import, so this preload is injected into requireModules to patch the cached class
1515
// prototype before Cucumber constructs the worker instance.
16-
patchCucumberWorkerRunTestCase(appRequire('@cucumber/cucumber/lib/runtime/worker'), true)
16+
let runtimeExecutorPackage
17+
try {
18+
runtimeExecutorPackage = appRequire('@cucumber/cucumber/lib/runtime/executor')
19+
} catch {
20+
runtimeExecutorPackage = appRequire('@cucumber/cucumber/lib/runtime/worker')
21+
}
22+
patchCucumberWorkerRunTestCase(runtimeExecutorPackage, true)
1723
} catch {
1824
// Ignore preload failures so cucumber can keep running if its internals change.
1925
}

packages/datadog-instrumentations/src/cucumber.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,9 @@ function testCaseHook (TestCaseRunner, version) {
10361036
// Valid for old and new cucumber versions
10371037
function getCucumberOptions (adapterOrCoordinator) {
10381038
if (adapterOrCoordinator.adapter) {
1039-
return adapterOrCoordinator.adapter.worker?.options || adapterOrCoordinator.adapter.options
1039+
return adapterOrCoordinator.adapter.worker?.options ||
1040+
adapterOrCoordinator.adapter.executor?.options ||
1041+
adapterOrCoordinator.adapter.options
10401042
}
10411043
return adapterOrCoordinator.options
10421044
}
@@ -1434,13 +1436,14 @@ function getWrappedRunTestCase (runTestCaseFunction, isNewerCucumberVersion = fa
14341436
}
14351437
}
14361438

1437-
function patchCucumberWorkerRunTestCase (workerPackage, isWorker) {
1438-
const workerPrototype = workerPackage?.Worker?.prototype
1439-
if (!workerPrototype || patchedCucumberWorkers.has(workerPrototype)) return
1439+
function patchCucumberWorkerRunTestCase (runtimeExecutorPackage, isWorker) {
1440+
const runtimeExecutorPrototype =
1441+
runtimeExecutorPackage?.Worker?.prototype || runtimeExecutorPackage?.Executor?.prototype
1442+
if (!runtimeExecutorPrototype || patchedCucumberWorkers.has(runtimeExecutorPrototype)) return
14401443

1441-
patchedCucumberWorkers.add(workerPrototype)
1444+
patchedCucumberWorkers.add(runtimeExecutorPrototype)
14421445
shimmer.wrap(
1443-
workerPrototype,
1446+
runtimeExecutorPrototype,
14441447
'runTestCase',
14451448
runTestCase => getWrappedRunTestCase(runTestCase, true, isWorker)
14461449
)
@@ -1572,15 +1575,25 @@ addHook({
15721575
// `getWrappedRunTestCase` does two things:
15731576
// - generates suite start and finish events in the main process,
15741577
// - handles EFD in both the main process and the worker process.
1578+
// Shimmer is required because this wrapper may invoke the original test case multiple times and mutate runtime options.
15751579
addHook({
15761580
name: '@cucumber/cucumber',
1577-
versions: ['>=11.0.0'],
1581+
versions: ['>=11.0.0 <13.2.0'],
15781582
file: 'lib/runtime/worker.js',
15791583
}, (workerPackage) => {
15801584
patchCucumberWorkerRunTestCase(workerPackage, !!getEnvironmentVariable('CUCUMBER_WORKER_ID'))
15811585
return workerPackage
15821586
})
15831587

1588+
addHook({
1589+
name: '@cucumber/cucumber',
1590+
versions: ['>=13.2.0'],
1591+
file: 'lib/runtime/executor.js',
1592+
}, (executorPackage) => {
1593+
patchCucumberWorkerRunTestCase(executorPackage, !!getEnvironmentVariable('CUCUMBER_WORKER_ID'))
1594+
return executorPackage
1595+
})
1596+
15841597
// `getWrappedStart` generates session start and finish events
15851598
addHook({
15861599
name: '@cucumber/cucumber',

packages/dd-trace/test/plugins/versions/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"@babel/core": "7.29.0",
3333
"@babel/preset-typescript": "7.28.5",
3434
"@confluentinc/kafka-javascript": "1.10.0",
35-
"@cucumber/cucumber": "13.1.0",
35+
"@cucumber/cucumber": "13.2.0",
3636
"@datadog/openfeature-node-server": "2.0.0",
3737
"@elastic/elasticsearch": "9.4.0",
3838
"@elastic/transport": "9.3.5",

0 commit comments

Comments
 (0)