Skip to content

Commit 80365fb

Browse files
committed
fix(cucumber): contain detached finalizer failures
An ignored finally promise can reject with either the original test failure or a finalizer error. Running the finalizer as both promise handlers preserves the original returned promise while containing finalizer failures.
1 parent efc0d0f commit 80365fb

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

packages/datadog-instrumentations/src/cucumber.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -793,8 +793,7 @@ function wrapRun (pl, isLatestVersion, version) {
793793
testFnCh.runStores(ctx, () => {
794794
promise = run.apply(this, args)
795795
})
796-
// eslint-disable-next-line unicorn/no-async-promise-finally -- Detached finalizer preserves Cucumber's result.
797-
promise.finally(async () => {
796+
const finalize = async () => {
798797
if (!canAwaitRetries) {
799798
this.eventBroadcaster.removeListener('envelope', onEnvelope)
800799
}
@@ -967,6 +966,9 @@ function wrapRun (pl, isLatestVersion, version) {
967966
...attemptCtx.currentStore,
968967
finalStatus,
969968
})
969+
}
970+
promise.then(finalize, finalize).catch(error => {
971+
log.error('Cucumber test finalization error', error)
970972
})
971973
return promise
972974
} catch (err) {

0 commit comments

Comments
 (0)