Skip to content

Commit

Permalink
[test-visibility] Fix mocha plugin tests flakiness (#4545)
Browse files Browse the repository at this point in the history
  • Loading branch information
juan-fernandez committed Aug 5, 2024
1 parent 679e7e2 commit e3673d7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 7 additions & 3 deletions packages/datadog-instrumentations/src/mocha/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,13 @@ addHook({
}

const asyncResource = testFileToSuiteAr.get(suite.file)
asyncResource.runInAsyncScope(() => {
testSuiteFinishCh.publish(status)
})
if (asyncResource) {
asyncResource.runInAsyncScope(() => {
testSuiteFinishCh.publish(status)
})
} else {
log.warn(() => `No AsyncResource found for suite ${suite.file}`)
}
})

return run.apply(this, arguments)
Expand Down
10 changes: 5 additions & 5 deletions packages/datadog-plugin-mocha/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,15 +480,15 @@ describe('Plugin', () => {
})
})

Promise.all(assertionPromises)
.then(() => done())
.catch(done)

const mocha = new Mocha({
reporter: function () {} // silent on internal tests
})
mocha.addFile(testFilePath)
mocha.run()
mocha.run().on('end', () => {
Promise.all(assertionPromises)
.then(() => done())
.catch(done)
})
})

it('works when skipping suites', function (done) {
Expand Down

0 comments on commit e3673d7

Please sign in to comment.