diff --git a/integration-tests/mocha/mocha.spec.js b/integration-tests/mocha/mocha.spec.js index dac0a9e3bff..3fa11871204 100644 --- a/integration-tests/mocha/mocha.spec.js +++ b/integration-tests/mocha/mocha.spec.js @@ -1875,7 +1875,7 @@ describe('mocha CommonJS', function () { }) }) - context('flaky test retries', () => { + context('auto test retries', () => { it('retries failed tests automatically', (done) => { receiver.setSettings({ itr_enabled: false, @@ -1911,6 +1911,10 @@ describe('mocha CommonJS', function () { const failedAttempts = tests.filter(test => test.meta[TEST_STATUS] === 'fail') assert.equal(failedAttempts.length, 2) + failedAttempts.forEach((failedTest, index) => { + assert.include(failedTest.meta[ERROR_MESSAGE], `expected ${index + 1} to equal 3`) + }) + // The first attempt is not marked as a retry const retriedFailure = failedAttempts.filter(test => test.meta[TEST_IS_RETRY] === 'true') assert.equal(retriedFailure.length, 1) diff --git a/packages/datadog-instrumentations/src/mocha/utils.js b/packages/datadog-instrumentations/src/mocha/utils.js index a4da0762039..2b51fd6e73b 100644 --- a/packages/datadog-instrumentations/src/mocha/utils.js +++ b/packages/datadog-instrumentations/src/mocha/utils.js @@ -280,12 +280,12 @@ function getOnFailHandler (isMain) { } function getOnTestRetryHandler () { - return function (test) { + return function (test, err) { const asyncResource = getTestAsyncResource(test) if (asyncResource) { const isFirstAttempt = test._currentRetry === 0 asyncResource.runInAsyncScope(() => { - testRetryCh.publish(isFirstAttempt) + testRetryCh.publish({ isFirstAttempt, err }) }) } const key = getTestToArKey(test) diff --git a/packages/datadog-plugin-mocha/src/index.js b/packages/datadog-plugin-mocha/src/index.js index 30f6e88a9fc..0513a4a95d6 100644 --- a/packages/datadog-plugin-mocha/src/index.js +++ b/packages/datadog-plugin-mocha/src/index.js @@ -242,7 +242,7 @@ class MochaPlugin extends CiPlugin { } }) - this.addSub('ci:mocha:test:retry', (isFirstAttempt) => { + this.addSub('ci:mocha:test:retry', ({ isFirstAttempt, err }) => { const store = storage.getStore() const span = store?.span if (span) { @@ -250,6 +250,9 @@ class MochaPlugin extends CiPlugin { if (!isFirstAttempt) { span.setTag(TEST_IS_RETRY, 'true') } + if (err) { + span.setTag('error', err) + } const spanTags = span.context()._tags this.telemetry.ciVisEvent(