Skip to content

Commit 8e7a36b

Browse files
better naming
1 parent b0f79f9 commit 8e7a36b

File tree

15 files changed

+103
-118
lines changed

15 files changed

+103
-118
lines changed

packages/datadog-instrumentations/src/cucumber.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const skippableSuitesCh = channel('ci:cucumber:test-suite:skippable')
2525
const sessionStartCh = channel('ci:cucumber:session:start')
2626
const sessionFinishCh = channel('ci:cucumber:session:finish')
2727
const testManagementTestsCh = channel('ci:cucumber:test-management-tests')
28-
const impactedTestsCh = channel('ci:cucumber:modified-tests')
28+
const modifiedFilesCh = channel('ci:cucumber:modified-tests')
2929
const isModifiedCh = channel('ci:cucumber:is-modified-test')
3030

3131
const workerReportTraceCh = channel('ci:cucumber:worker-report:trace')
@@ -80,7 +80,7 @@ let isTestManagementTestsEnabled = false
8080
let isImpactedTestsEnabled = false
8181
let testManagementAttemptToFixRetries = 0
8282
let testManagementTests = {}
83-
let modifiedTests = {}
83+
let modifiedFiles = {}
8484
let numTestRetries = 0
8585
let knownTests = {}
8686
let skippedSuites = []
@@ -537,9 +537,9 @@ function getWrappedStart (start, frameworkVersion, isParallel = false, isCoordin
537537
}
538538

539539
if (isImpactedTestsEnabled) {
540-
const impactedTestsResponse = await getChannelPromise(impactedTestsCh)
540+
const impactedTestsResponse = await getChannelPromise(modifiedFilesCh)
541541
if (!impactedTestsResponse.err) {
542-
modifiedTests = impactedTestsResponse.modifiedTests
542+
modifiedFiles = impactedTestsResponse.modifiedFiles
543543
}
544544
}
545545

@@ -655,7 +655,7 @@ function getWrappedRunTestCase (runTestCaseFunction, isNewerCucumberVersion = fa
655655
isModifiedCh.publish({
656656
scenarios,
657657
testFileAbsolutePath: gherkinDocument.uri,
658-
modifiedTests,
658+
modifiedFiles,
659659
stepIds,
660660
stepDefinitions: this.supportCodeLibrary.stepDefinitions,
661661
setIsModified
@@ -1000,7 +1000,7 @@ addHook({
10001000

10011001
if (isImpactedTestsEnabled) {
10021002
this.options.worldParameters._ddImpactedTestsEnabled = isImpactedTestsEnabled
1003-
this.options.worldParameters._ddModifiedTests = modifiedTests
1003+
this.options.worldParameters._ddModifiedFiles = modifiedFiles
10041004
}
10051005

10061006
return startWorker.apply(this, arguments)
@@ -1036,7 +1036,7 @@ addHook({
10361036
}
10371037
isImpactedTestsEnabled = !!this.options.worldParameters._ddImpactedTestsEnabled
10381038
if (isImpactedTestsEnabled) {
1039-
modifiedTests = this.options.worldParameters._ddModifiedTests
1039+
modifiedFiles = this.options.worldParameters._ddModifiedFiles
10401040
}
10411041
}
10421042
)

packages/datadog-instrumentations/src/jest.js

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const skippableSuitesCh = channel('ci:jest:test-suite:skippable')
4646
const libraryConfigurationCh = channel('ci:jest:library-configuration')
4747
const knownTestsCh = channel('ci:jest:known-tests')
4848
const testManagementTestsCh = channel('ci:jest:test-management-tests')
49-
const impactedTestsCh = channel('ci:jest:modified-tests')
49+
const modifiedFilesCh = channel('ci:jest:modified-files')
5050

5151
const itrSkippedSuitesCh = channel('ci:jest:itr:skipped-suites')
5252

@@ -78,7 +78,7 @@ let isTestManagementTestsEnabled = false
7878
let testManagementTests = {}
7979
let testManagementAttemptToFixRetries = 0
8080
let isImpactedTestsEnabled = false
81-
let modifiedTests = {}
81+
let modifiedFiles = {}
8282

8383
const testContexts = new WeakMap()
8484
const originalTestFns = new WeakMap()
@@ -197,10 +197,9 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
197197

198198
if (this.isImpactedTestsEnabled) {
199199
try {
200-
const hasImpactedTests = Object.keys(modifiedTests).length > 0
201-
this.modifiedTestsForThisSuite = hasImpactedTests
202-
? this.getModifiedTestForThisSuite(modifiedTests)
203-
: this.getModifiedTestForThisSuite(this.testEnvironmentOptions._ddModifiedTests)
200+
const hasImpactedTests = Object.keys(modifiedFiles).length > 0
201+
// TODO: check if `this.testEnvironmentOptions._ddModifiedFiles` is serialized to JSON
202+
this.modifiedFiles = hasImpactedTests ? modifiedFiles : this.testEnvironmentOptions._ddModifiedFiles
204203
} catch (e) {
205204
log.error('Error parsing impacted tests', e)
206205
this.isImpactedTestsEnabled = false
@@ -290,19 +289,6 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
290289
return result
291290
}
292291

293-
getModifiedTestForThisSuite (modifiedTests) {
294-
if (this.modifiedTestsForThisSuite) {
295-
return this.modifiedTestsForThisSuite
296-
}
297-
let modifiedTestsForThisSuite = modifiedTests
298-
// If jest is using workers, modified tests are serialized to json.
299-
// If jest runs in band, they are not.
300-
if (typeof modifiedTestsForThisSuite === 'string') {
301-
modifiedTestsForThisSuite = JSON.parse(modifiedTestsForThisSuite)
302-
}
303-
return modifiedTestsForThisSuite
304-
}
305-
306292
// Generic function to handle test retries
307293
retryTest ({
308294
jestEvent,
@@ -378,7 +364,7 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
378364
this.testSourceFile,
379365
testStartLine,
380366
testEndLine,
381-
this.modifiedTestsForThisSuite,
367+
this.modifiedFiles,
382368
'jest'
383369
)
384370
}
@@ -465,7 +451,7 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
465451
this.testSourceFile,
466452
testStartLine,
467453
testEndLine,
468-
this.modifiedTestsForThisSuite,
454+
this.modifiedFiles,
469455
'jest'
470456
)
471457
if (isModified && !retriedTestsToNumAttempts.has(testFullName) && this.isEarlyFlakeDetectionEnabled) {
@@ -831,12 +817,12 @@ function getCliWrapper (isNewJestVersion) {
831817
onDone = resolve
832818
})
833819

834-
impactedTestsCh.publish({ onDone })
820+
modifiedFilesCh.publish({ onDone })
835821

836822
try {
837-
const { err, modifiedTests: receivedModifiedTests } = await impactedTestsPromise
823+
const { err, modifiedFiles: receivedModifiedFiles } = await impactedTestsPromise
838824
if (!err) {
839-
modifiedTests = receivedModifiedTests
825+
modifiedFiles = receivedModifiedFiles
840826
}
841827
} catch (err) {
842828
log.error('Jest impacted tests error', err)
@@ -1237,7 +1223,7 @@ addHook({
12371223
_ddIsTestManagementTestsEnabled,
12381224
_ddTestManagementTests,
12391225
_ddTestManagementAttemptToFixRetries,
1240-
_ddModifiedTests,
1226+
_ddModifiedFiles,
12411227
...restOfTestEnvironmentOptions
12421228
} = testEnvironmentOptions
12431229

@@ -1365,17 +1351,15 @@ function sendWrapper (send) {
13651351

13661352
const suiteTestManagementTests = testManagementTests?.jest?.suites?.[testSuite]?.tests || {}
13671353

1368-
const suiteModifiedTests = Object.keys(modifiedTests).length > 0
1369-
? modifiedTests
1370-
: {}
1371-
13721354
args[0].config = {
13731355
...config,
13741356
testEnvironmentOptions: {
13751357
...config.testEnvironmentOptions,
13761358
_ddKnownTests: suiteKnownTests,
13771359
_ddTestManagementTests: suiteTestManagementTests,
1378-
_ddModifiedTests: suiteModifiedTests
1360+
// TODO: figure out if we can reduce the size of the modified files object
1361+
// Can we use `testSuite` (it'd have to be relative to repository root though)
1362+
_ddModifiedFiles: modifiedFiles
13791363
}
13801364
}
13811365
}

packages/datadog-instrumentations/src/mocha/main.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const skippableSuitesCh = channel('ci:mocha:test-suite:skippable')
6868
const mochaGlobalRunCh = channel('ci:mocha:global:run')
6969

7070
const testManagementTestsCh = channel('ci:mocha:test-management-tests')
71-
const impactedTestsCh = channel('ci:mocha:modified-tests')
71+
const modifiedFilesCh = channel('ci:mocha:modified-files')
7272
const workerReportTraceCh = channel('ci:mocha:worker-report:trace')
7373
const testSessionStartCh = channel('ci:mocha:session:start')
7474
const testSessionFinishCh = channel('ci:mocha:session:finish')
@@ -233,12 +233,12 @@ function getExecutionConfiguration (runner, isParallel, frameworkVersion, onFini
233233
})
234234
}
235235

236-
const onReceivedImpactedTests = ({ err, modifiedTests: receivedModifiedTests }) => {
236+
const onReceivedImpactedTests = ({ err, modifiedFiles: receivedModifiedFiles }) => {
237237
if (err) {
238-
config.modifiedTests = []
238+
config.modifiedFiles = []
239239
config.isImpactedTestsEnabled = false
240240
} else {
241-
config.modifiedTests = receivedModifiedTests
241+
config.modifiedFiles = receivedModifiedFiles
242242
}
243243
if (config.isSuitesSkippingEnabled) {
244244
ctx.onDone = onReceivedSkippableSuites
@@ -260,7 +260,7 @@ function getExecutionConfiguration (runner, isParallel, frameworkVersion, onFini
260260
}
261261
if (config.isImpactedTestsEnabled) {
262262
ctx.onDone = onReceivedImpactedTests
263-
impactedTestsCh.runStores(ctx, () => {})
263+
modifiedFilesCh.runStores(ctx, () => {})
264264
} else if (config.isSuitesSkippingEnabled) {
265265
ctx.onDone = onReceivedSkippableSuites
266266
skippableSuitesCh.runStores(ctx, () => {})
@@ -284,7 +284,7 @@ function getExecutionConfiguration (runner, isParallel, frameworkVersion, onFini
284284
testManagementTestsCh.runStores(ctx, () => {})
285285
} if (config.isImpactedTestsEnabled) {
286286
ctx.onDone = onReceivedImpactedTests
287-
impactedTestsCh.runStores(ctx, () => {})
287+
modifiedFilesCh.runStores(ctx, () => {})
288288
} else if (config.isSuitesSkippingEnabled) {
289289
ctx.onDone = onReceivedSkippableSuites
290290
skippableSuitesCh.runStores(ctx, () => {})
@@ -321,7 +321,7 @@ function getExecutionConfiguration (runner, isParallel, frameworkVersion, onFini
321321
testManagementTestsCh.runStores(ctx, () => {})
322322
} else if (config.isImpactedTestsEnabled) {
323323
ctx.onDone = onReceivedImpactedTests
324-
impactedTestsCh.runStores(ctx, () => {})
324+
modifiedFilesCh.runStores(ctx, () => {})
325325
} else if (config.isSuitesSkippingEnabled) {
326326
ctx.onDone = onReceivedSkippableSuites
327327
skippableSuitesCh.runStores(ctx, () => {})
@@ -696,9 +696,8 @@ addHook({
696696
}
697697

698698
if (config.isImpactedTestsEnabled) {
699-
const testSuiteImpactedTests = config.modifiedTests || {}
700699
newWorkerArgs._ddIsImpactedTestsEnabled = true
701-
newWorkerArgs._ddModifiedTests = testSuiteImpactedTests
700+
newWorkerArgs._ddModifiedFiles = config.modifiedFiles || {}
702701
}
703702

704703
// We pass the known tests for the test file to the worker

packages/datadog-instrumentations/src/mocha/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ function getRunTestsWrapper (runTests, config) {
446446
if (config.isImpactedTestsEnabled) {
447447
suite.tests.forEach((test) => {
448448
isModifiedCh.publish({
449-
modifiedTests: config.modifiedTests,
449+
modifiedFiles: config.modifiedFiles,
450450
file: suite.file,
451451
onDone: (isModified) => {
452452
if (isModified) {

packages/datadog-instrumentations/src/mocha/worker.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ addHook({
3636
}
3737
if (this.options._ddIsImpactedTestsEnabled) {
3838
config.isImpactedTestsEnabled = true
39-
config.modifiedTests = this.options._ddModifiedTests
39+
config.modifiedFiles = this.options._ddModifiedFiles
4040
delete this.options._ddIsImpactedTestsEnabled
41-
delete this.options._ddModifiedTests
41+
delete this.options._ddModifiedFiles
4242
}
4343
if (this.options._ddIsTestManagementTestsEnabled) {
4444
config.isTestManagementTestsEnabled = true

packages/datadog-instrumentations/src/playwright.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const testSessionFinishCh = channel('ci:playwright:session:finish')
2121
const libraryConfigurationCh = channel('ci:playwright:library-configuration')
2222
const knownTestsCh = channel('ci:playwright:known-tests')
2323
const testManagementTestsCh = channel('ci:playwright:test-management-tests')
24-
const impactedTestsCh = channel('ci:playwright:modified-tests')
24+
const modifiedFilesCh = channel('ci:playwright:modified-files')
2525
const isModifiedCh = channel('ci:playwright:test:is-modified')
2626

2727
const testSuiteStartCh = channel('ci:playwright:test-suite:start')
@@ -59,7 +59,7 @@ let isTestManagementTestsEnabled = false
5959
let testManagementAttemptToFixRetries = 0
6060
let testManagementTests = {}
6161
let isImpactedTestsEnabled = false
62-
let modifiedTests = {}
62+
let modifiedFiles = {}
6363
const quarantinedOrDisabledTestsAttemptToFix = []
6464
let quarantinedButNotAttemptToFixFqns = new Set()
6565
let rootDir = ''
@@ -593,11 +593,11 @@ function runAllTestsWrapper (runAllTests, playwrightVersion) {
593593

594594
if (isImpactedTestsEnabled && satisfies(playwrightVersion, MINIMUM_SUPPORTED_VERSION_RANGE_EFD)) {
595595
try {
596-
const { err, modifiedTests: receivedModifiedTests } = await getChannelPromise(impactedTestsCh)
596+
const { err, modifiedFiles: receivedModifiedFiles } = await getChannelPromise(modifiedFilesCh)
597597
if (err) {
598598
isImpactedTestsEnabled = false
599599
} else {
600-
modifiedTests = receivedModifiedTests
600+
modifiedFiles = receivedModifiedFiles
601601
}
602602
} catch (err) {
603603
isImpactedTestsEnabled = false
@@ -819,7 +819,7 @@ addHook({
819819
await Promise.all(allTests.map(async (test) => {
820820
const { isModified } = await getChannelPromise(isModifiedCh, {
821821
filePath: test._requireFile,
822-
modifiedTests
822+
modifiedFiles
823823
})
824824
if (isModified) {
825825
test._ddIsModified = true

packages/datadog-instrumentations/src/vitest.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const libraryConfigurationCh = channel('ci:vitest:library-configuration')
3232
const knownTestsCh = channel('ci:vitest:known-tests')
3333
const isEarlyFlakeDetectionFaultyCh = channel('ci:vitest:is-early-flake-detection-faulty')
3434
const testManagementTestsCh = channel('ci:vitest:test-management-tests')
35-
const impactedTestsCh = channel('ci:vitest:modified-tests')
35+
const modifiedFilesCh = channel('ci:vitest:modified-files')
3636

3737
const workerReportTraceCh = channel('ci:vitest:worker-report:trace')
3838
const workerReportLogsCh = channel('ci:vitest:worker-report:logs')
@@ -92,7 +92,7 @@ function getProvidedContext () {
9292
_ddTestManagementTests: testManagementTests,
9393
_ddIsFlakyTestRetriesEnabled: isFlakyTestRetriesEnabled,
9494
_ddIsImpactedTestsEnabled: isImpactedTestsEnabled,
95-
_ddModifiedTests: modifiedTests
95+
_ddModifiedFiles: modifiedFiles
9696
} = globalThis.__vitest_worker__.providedContext
9797

9898
return {
@@ -106,7 +106,7 @@ function getProvidedContext () {
106106
testManagementTests,
107107
isFlakyTestRetriesEnabled,
108108
isImpactedTestsEnabled,
109-
modifiedTests
109+
modifiedFiles
110110
}
111111
} catch {
112112
log.error('Vitest workers could not parse provided context, so some features will not work.')
@@ -121,7 +121,7 @@ function getProvidedContext () {
121121
testManagementTests: {},
122122
isFlakyTestRetriesEnabled: false,
123123
isImpactedTestsEnabled: false,
124-
modifiedTests: {}
124+
modifiedFiles: {}
125125
}
126126
}
127127
}
@@ -316,14 +316,14 @@ function getSortWrapper (sort, frameworkVersion) {
316316
}
317317

318318
if (isImpactedTestsEnabled) {
319-
const { err, modifiedTests } = await getChannelPromise(impactedTestsCh)
319+
const { err, modifiedFiles } = await getChannelPromise(modifiedFilesCh)
320320
if (err) {
321321
log.error('Could not get modified tests.')
322322
} else {
323323
try {
324324
const workspaceProject = this.ctx.getCoreWorkspaceProject()
325325
workspaceProject._provided._ddIsImpactedTestsEnabled = isImpactedTestsEnabled
326-
workspaceProject._provided._ddModifiedTests = modifiedTests
326+
workspaceProject._provided._ddModifiedFiles = modifiedFiles
327327
} catch {
328328
log.warn('Could not send modified tests to workers so Impacted Tests will not work.')
329329
}
@@ -464,7 +464,7 @@ addHook({
464464
testManagementAttemptToFixRetries,
465465
testManagementTests,
466466
isImpactedTestsEnabled,
467-
modifiedTests
467+
modifiedFiles
468468
} = getProvidedContext()
469469

470470
if (isTestManagementTestsEnabled) {
@@ -499,7 +499,7 @@ addHook({
499499

500500
if (isImpactedTestsEnabled) {
501501
isModifiedCh.publish({
502-
modifiedTests,
502+
modifiedFiles,
503503
testSuiteAbsolutePath: task.file.filepath,
504504
onDone: (isImpacted) => {
505505
if (isImpacted) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ class CucumberPlugin extends CiPlugin {
407407
this.addSub('ci:cucumber:is-modified-test', ({
408408
scenarios,
409409
testFileAbsolutePath,
410-
modifiedTests,
410+
modifiedFiles,
411411
stepIds,
412412
stepDefinitions,
413413
setIsModified
@@ -418,7 +418,7 @@ class CucumberPlugin extends CiPlugin {
418418
testScenarioPath,
419419
scenario.location.line,
420420
scenario.steps[scenario.steps.length - 1].location.line,
421-
modifiedTests,
421+
modifiedFiles,
422422
'cucumber'
423423
)
424424
if (isModified) {
@@ -436,7 +436,7 @@ class CucumberPlugin extends CiPlugin {
436436
stepDefinition.uri,
437437
testStartLineStep,
438438
testEndLineStep,
439-
modifiedTests,
439+
modifiedFiles,
440440
'cucumber'
441441
)
442442
if (isModified) {

0 commit comments

Comments
 (0)