Skip to content

Commit 2b8601e

Browse files
Mariovidotlhunter
authored andcommitted
[test-optimization] [SDTEST-2522] Fix incident with Jest and EFD (#6313)
1 parent 4d3ce15 commit 2b8601e

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

integration-tests/jest/jest.spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,7 +1802,7 @@ describe('jest CommonJS', () => {
18021802
it('retries flaky tests', (done) => {
18031803
receiver.setInfoResponse({ endpoints: ['/evp_proxy/v4'] })
18041804
// Tests from ci-visibility/test/occasionally-failing-test will be considered new
1805-
receiver.setKnownTests({})
1805+
receiver.setKnownTests({ jest: {} })
18061806

18071807
const NUM_RETRIES_EFD = 5
18081808
receiver.setSettings({
@@ -1866,7 +1866,7 @@ describe('jest CommonJS', () => {
18661866
it('does not retry new tests that are skipped', (done) => {
18671867
receiver.setInfoResponse({ endpoints: ['/evp_proxy/v4'] })
18681868
// Tests from ci-visibility/test/skipped-and-todo-test will be considered new
1869-
receiver.setKnownTests({})
1869+
receiver.setKnownTests({ jest: {} })
18701870

18711871
const NUM_RETRIES_EFD = 5
18721872
receiver.setSettings({
@@ -2036,7 +2036,7 @@ describe('jest CommonJS', () => {
20362036
it('retries flaky tests and sets exit code to 0 as long as one attempt passes', (done) => {
20372037
receiver.setInfoResponse({ endpoints: ['/evp_proxy/v4'] })
20382038
// Tests from ci-visibility/test/occasionally-failing-test will be considered new
2039-
receiver.setKnownTests({})
2039+
receiver.setKnownTests({ jest: {} })
20402040

20412041
const NUM_RETRIES_EFD = 3
20422042
receiver.setSettings({
@@ -2110,7 +2110,7 @@ describe('jest CommonJS', () => {
21102110
receiver.setInfoResponse({ endpoints: ['/evp_proxy/v4'] })
21112111
// Tests from ci-visibility/test-early-flake-detection/jest-snapshot.js will be considered new
21122112
// but we don't retry them because they have snapshots
2113-
receiver.setKnownTests({})
2113+
receiver.setKnownTests({ jest: {} })
21142114

21152115
const NUM_RETRIES_EFD = 3
21162116
receiver.setSettings({
@@ -2164,7 +2164,7 @@ describe('jest CommonJS', () => {
21642164
it('bails out of EFD if the percentage of new tests is too high', (done) => {
21652165
receiver.setInfoResponse({ endpoints: ['/evp_proxy/v4'] })
21662166
// Tests from ci-visibility/test/ci-visibility-test* will be considered new
2167-
receiver.setKnownTests({})
2167+
receiver.setKnownTests({ jest: {} })
21682168

21692169
const NUM_RETRIES_EFD = 3
21702170
receiver.setSettings({
@@ -3774,7 +3774,7 @@ describe('jest CommonJS', () => {
37743774

37753775
context('test is new', () => {
37763776
it('should be retried and marked both as new and modified', (done) => {
3777-
receiver.setKnownTests({})
3777+
receiver.setKnownTests({ jest: {} })
37783778
receiver.setSettings({
37793779
impacted_tests_enabled: true,
37803780
early_flake_detection: {

packages/datadog-instrumentations/src/jest.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
166166
this.knownTestsForThisSuite = hasKnownTests
167167
? (knownTests?.jest?.[this.testSuite] || [])
168168
: this.getKnownTestsForSuite(this.testEnvironmentOptions._ddKnownTests)
169+
log.debug(`this.knownTestsForThisSuite is an array: ${Array.isArray(this.knownTestsForThisSuite)}`)
170+
log.debug(`this.knownTestsForThisSuite is null: ${this.knownTestsForThisSuite === null}`)
171+
log.debug(`this.knownTestsForThisSuite is undefined: ${this.knownTestsForThisSuite === undefined}`)
169172
} catch {
170173
// If there has been an error parsing the tests, we'll disable Early Flake Deteciton
171174
this.isEarlyFlakeDetectionEnabled = false
@@ -469,7 +472,10 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
469472
}
470473
}
471474
if (this.isKnownTestsEnabled) {
472-
const isNew = !this.knownTestsForThisSuite?.includes(originalTestName)
475+
// Check if knownTestsForThisSuite is an array, since the worker may not have provided this information.
476+
// If it's null or undefined, we can't determine if the test is new.
477+
const isNew = Array.isArray(this.knownTestsForThisSuite) &&
478+
!this.knownTestsForThisSuite.includes(originalTestName)
473479
if (isNew && !isSkipped && !retriedTestsToNumAttempts.has(originalTestName)) {
474480
retriedTestsToNumAttempts.set(originalTestName, 0)
475481
if (this.isEarlyFlakeDetectionEnabled) {

0 commit comments

Comments
 (0)