Skip to content

Commit d5805b3

Browse files
[test optimization] Do not report jest test suites as failed if a module import failed (#6924)
1 parent 4ff4de8 commit d5805b3

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

integration-tests/jest/jest.spec.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,31 +1055,32 @@ describe(`jest@${JEST_VERSION} commonJS`, () => {
10551055
const suites = events.filter(event => event.type === 'test_suite_end')
10561056
// this is not retried by the jest worker, so it's just 3 suites
10571057
assert.equal(suites.length, 3)
1058-
const failedTestSuites = suites.filter(
1058+
const badImportTestSuites = suites.filter(
10591059
suite => suite.content.meta[TEST_SUITE] ===
10601060
'ci-visibility/jest-bad-import-torn-down/jest-bad-import-test.js'
10611061
)
1062-
assert.equal(failedTestSuites.length, 1)
1063-
const [failedTestSuite] = failedTestSuites
1062+
assert.equal(badImportTestSuites.length, 1)
1063+
const [badImportTestSuite] = badImportTestSuites
10641064

1065-
assert.equal(failedTestSuite.content.meta[TEST_STATUS], 'fail')
1065+
// jest still reports the test suite as passing
1066+
assert.equal(badImportTestSuite.content.meta[TEST_STATUS], 'pass')
10661067
assert.include(
1067-
failedTestSuite.content.meta[ERROR_MESSAGE],
1068+
badImportTestSuite.content.meta[ERROR_MESSAGE],
10681069
'a file after the Jest environment has been torn down'
10691070
)
10701071
assert.include(
1071-
failedTestSuite.content.meta[ERROR_MESSAGE],
1072+
badImportTestSuite.content.meta[ERROR_MESSAGE],
10721073
'From ci-visibility/jest-bad-import-torn-down/jest-bad-import-test.js'
10731074
)
10741075
// This is the error message that jest should show. We check that we don't mess it up.
1075-
assert.include(failedTestSuite.content.meta[ERROR_MESSAGE], 'off-timing-import')
1076-
assert.include(failedTestSuite.content.meta[ERROR_MESSAGE], 'afterAll')
1077-
assert.include(failedTestSuite.content.meta[ERROR_MESSAGE], 'nextTick')
1076+
assert.include(badImportTestSuite.content.meta[ERROR_MESSAGE], 'off-timing-import')
1077+
assert.include(badImportTestSuite.content.meta[ERROR_MESSAGE], 'afterAll')
1078+
assert.include(badImportTestSuite.content.meta[ERROR_MESSAGE], 'nextTick')
10781079

10791080
const passedTestSuites = suites.filter(
10801081
suite => suite.content.meta[TEST_STATUS] === 'pass'
10811082
)
1082-
assert.equal(passedTestSuites.length, 2)
1083+
assert.equal(passedTestSuites.length, 3)
10831084
})
10841085

10851086
childProcess = exec(runTestsCommand, {

packages/datadog-plugin-jest/src/index.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,7 @@ class JestPlugin extends CiPlugin {
282282
log.warn('"ci:jest:test-suite:finish": no span found for test suite absolute path %s', testSuiteAbsolutePath)
283283
return
284284
}
285-
const hasStatus = testSuiteSpan.context()._tags[TEST_STATUS]
286-
if (!hasStatus) {
287-
// The status may have been set in 'ci:jest:test-suite:error'
288-
testSuiteSpan.setTag(TEST_STATUS, status)
289-
}
285+
testSuiteSpan.setTag(TEST_STATUS, status)
290286
if (error) {
291287
testSuiteSpan.setTag('error', error)
292288
testSuiteSpan.setTag(TEST_STATUS, 'fail')
@@ -323,7 +319,6 @@ class JestPlugin extends CiPlugin {
323319
} else if (errorMessage) {
324320
runningTestSuiteSpan.setTag('error', new Error(errorMessage))
325321
}
326-
runningTestSuiteSpan.setTag(TEST_STATUS, 'fail')
327322
})
328323

329324
/**

0 commit comments

Comments
 (0)