Skip to content

[BUG]: Test Failures Are Not Reported Correctly When Using Mocha in Parallel Mode #6078

@eoneapp

Description

@eoneapp

Tracer Version(s)

5.52.0

Node.js Version(s)

22.2.0

Bug Report

I'm having an issue with reporting in Datadog when running mocha in parallel mode programmatically or from the CLI and allowing retries. It shows all the tests as passing and sometimes marks them as flakey even when i have them failing on purpose.

It also only shows the final run/retry of a test as having a failure, and shows the initial tries as passing as shown below.

Image Image

Reproduction Code

programmatic_test.js

import { default as Mocha } from 'mocha'

const mochaRunner = new Mocha({
color: true,
parallel: true,
jobs: 8,
retries: 3,
timeout: 100000,
bail: false,
failZero: true,
allowUncaught: false,
forbidOnly: true,
fullTrace: true,
})

mochaRunner.addFile('test-refactor/train_tests/_examples/example_1.js')
mochaRunner.addFile('test-refactor/train_tests/_examples/example_2.js')

mochaRunner.run(failures => {
if (failures > 0) {
console.error(Test run failed with ${failures} failures.)
process.exit(1)
} else {
console.log('All tests passed successfully.')
process.exit(0)
}
})


test_file_1.js

describe('File 1', function () {
it('Ex 1: Fail in Immediate Throw', async function () {
await new Promise(resolve => setTimeout(resolve, 2000))
console.log('Throwing error')
throw new Error('Failed in Immediate Throw')
})
})


test_file_2.js

describe('File 2', function () {
it('Ex 2: Fail in Immediate Throw', async function () {
await new Promise(resolve => setTimeout(resolve, 2000))
console.log('Throwing error')
throw new Error('Failed in Immediate Throw')
})
})

Tracer Config

DD_TRACE_SAMPLE_RATE=1.0
DD_INSIDE_CI=true
DD_HOSTNAME: "none"
DD_AGENT_HOST: "datadog-agent"
DD_LOGS_INJECTION: "true"

Operating System

Amazon Linux Runner

Bundling

No Bundling

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions