Skip to content

Commit b4cfa7f

Browse files
authored
[test-optimization] [SDTEST-2163] Check framework version in capabilities tagging (#5876)
1 parent 024282b commit b4cfa7f

File tree

9 files changed

+87
-28
lines changed

9 files changed

+87
-28
lines changed

integration-tests/playwright/playwright.spec.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,12 +1363,20 @@ versions.forEach((version) => {
13631363
assert.isNotEmpty(metadataDicts)
13641364
metadataDicts.forEach(metadata => {
13651365
assert.equal(metadata.test[DD_CAPABILITIES_TEST_IMPACT_ANALYSIS], undefined)
1366-
assert.equal(metadata.test[DD_CAPABILITIES_EARLY_FLAKE_DETECTION], '1')
13671366
assert.equal(metadata.test[DD_CAPABILITIES_AUTO_TEST_RETRIES], '1')
1368-
assert.equal(metadata.test[DD_CAPABILITIES_IMPACTED_TESTS], '1')
1369-
assert.equal(metadata.test[DD_CAPABILITIES_TEST_MANAGEMENT_QUARANTINE], '1')
1370-
assert.equal(metadata.test[DD_CAPABILITIES_TEST_MANAGEMENT_DISABLE], '1')
1371-
assert.equal(metadata.test[DD_CAPABILITIES_TEST_MANAGEMENT_ATTEMPT_TO_FIX], '4')
1367+
if (satisfies(version, '>=1.38.0') || version === 'latest') {
1368+
assert.equal(metadata.test[DD_CAPABILITIES_EARLY_FLAKE_DETECTION], '1')
1369+
assert.equal(metadata.test[DD_CAPABILITIES_IMPACTED_TESTS], '1')
1370+
assert.equal(metadata.test[DD_CAPABILITIES_TEST_MANAGEMENT_QUARANTINE], '1')
1371+
assert.equal(metadata.test[DD_CAPABILITIES_TEST_MANAGEMENT_DISABLE], '1')
1372+
assert.equal(metadata.test[DD_CAPABILITIES_TEST_MANAGEMENT_ATTEMPT_TO_FIX], '4')
1373+
} else {
1374+
assert.equal(metadata.test[DD_CAPABILITIES_EARLY_FLAKE_DETECTION], undefined)
1375+
assert.equal(metadata.test[DD_CAPABILITIES_IMPACTED_TESTS], undefined)
1376+
assert.equal(metadata.test[DD_CAPABILITIES_TEST_MANAGEMENT_QUARANTINE], undefined)
1377+
assert.equal(metadata.test[DD_CAPABILITIES_TEST_MANAGEMENT_DISABLE], undefined)
1378+
assert.equal(metadata.test[DD_CAPABILITIES_TEST_MANAGEMENT_ATTEMPT_TO_FIX], undefined)
1379+
}
13721380
// capabilities logic does not overwrite test session name
13731381
assert.equal(metadata.test[TEST_SESSION_NAME], 'my-test-session-name')
13741382
})

packages/datadog-instrumentations/src/cucumber.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ function getErrorFromCucumberResult (cucumberResult) {
157157
return error
158158
}
159159

160-
function getChannelPromise (channelToPublishTo, isParallel = false) {
160+
function getChannelPromise (channelToPublishTo, isParallel = false, frameworkVersion = null) {
161161
return new Promise(resolve => {
162-
channelToPublishTo.publish({ onDone: resolve, isParallel })
162+
channelToPublishTo.publish({ onDone: resolve, isParallel, frameworkVersion })
163163
})
164164
}
165165

@@ -451,7 +451,7 @@ function getWrappedStart (start, frameworkVersion, isParallel = false, isCoordin
451451
}
452452
let errorSkippableRequest
453453

454-
const configurationResponse = await getChannelPromise(libraryConfigurationCh, isParallel)
454+
const configurationResponse = await getChannelPromise(libraryConfigurationCh, isParallel, frameworkVersion)
455455

456456
isEarlyFlakeDetectionEnabled = configurationResponse.libraryConfig?.isEarlyFlakeDetectionEnabled
457457
earlyFlakeDetectionNumRetries = configurationResponse.libraryConfig?.earlyFlakeDetectionNumRetries

packages/datadog-instrumentations/src/jest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ function getCliWrapper (isNewJestVersion) {
726726
return runCLI.apply(this, arguments)
727727
}
728728

729-
libraryConfigurationCh.publish({ onDone })
729+
libraryConfigurationCh.publish({ onDone, frameworkVersion: jestVersion })
730730

731731
try {
732732
const { err, libraryConfig } = await configurationPromise

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,10 @@ function getOnEndHandler (isParallel) {
201201
}
202202
}
203203

204-
function getExecutionConfiguration (runner, isParallel, onFinishRequest) {
204+
function getExecutionConfiguration (runner, isParallel, frameworkVersion, onFinishRequest) {
205205
const ctx = {
206-
isParallel
206+
isParallel,
207+
frameworkVersion
207208
}
208209

209210
const onReceivedSkippableSuites = ({ err, skippableSuites, itrCorrelationId: responseItrCorrelationId }) => {
@@ -343,7 +344,7 @@ addHook({
343344
name: 'mocha',
344345
versions: ['>=5.2.0'],
345346
file: 'lib/mocha.js'
346-
}, (Mocha) => {
347+
}, (Mocha, frameworkVersion) => {
347348
shimmer.wrap(Mocha.prototype, 'run', run => function () {
348349
// Workers do not need to request any data, just run the tests
349350
if (!testFinishCh.hasSubscribers || getEnvironmentVariable('MOCHA_WORKER_ID') || this.options.parallel) {
@@ -363,7 +364,7 @@ addHook({
363364
}
364365
})
365366

366-
getExecutionConfiguration(runner, false, () => {
367+
getExecutionConfiguration(runner, false, frameworkVersion, () => {
367368
if (config.isKnownTestsEnabled) {
368369
const testSuites = this.files.map(file => getTestSuitePath(file, process.cwd()))
369370
const isFaulty = getIsFaultyEarlyFlakeDetection(
@@ -616,7 +617,7 @@ addHook({
616617
this.once('start', getOnStartHandler(true, frameworkVersion))
617618
this.once('end', getOnEndHandler(true))
618619

619-
getExecutionConfiguration(this, true, () => {
620+
getExecutionConfiguration(this, true, frameworkVersion, () => {
620621
if (config.isKnownTestsEnabled) {
621622
const testSuites = files.map(file => getTestSuitePath(file, process.cwd()))
622623
const isFaulty = getIsFaultyEarlyFlakeDetection(

packages/datadog-instrumentations/src/playwright.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,10 @@ function runnerHook (runnerExport, playwrightVersion) {
516516
testSessionStartCh.publish({ command, frameworkVersion: playwrightVersion, rootDir })
517517

518518
try {
519-
const { err, libraryConfig } = await getChannelPromise(libraryConfigurationCh)
519+
const { err, libraryConfig } = await getChannelPromise(
520+
libraryConfigurationCh,
521+
{ frameworkVersion: playwrightVersion }
522+
)
520523
if (!err) {
521524
isKnownTestsEnabled = libraryConfig.isKnownTestsEnabled
522525
isEarlyFlakeDetectionEnabled = libraryConfig.isEarlyFlakeDetectionEnabled

packages/datadog-instrumentations/src/vitest.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ function isBaseSequencer (vitestPackage) {
113113
return vitestPackage.b?.name === 'BaseSequencer'
114114
}
115115

116-
function getChannelPromise (channelToPublishTo) {
116+
function getChannelPromise (channelToPublishTo, frameworkVersion) {
117117
return new Promise(resolve => {
118-
channelToPublishTo.publish({ onDone: resolve })
118+
channelToPublishTo.publish({ onDone: resolve, frameworkVersion })
119119
})
120120
}
121121

@@ -173,7 +173,7 @@ function getTestName (task) {
173173
return testName
174174
}
175175

176-
function getSortWrapper (sort) {
176+
function getSortWrapper (sort, frameworkVersion) {
177177
return async function () {
178178
if (!testSessionFinishCh.hasSubscribers) {
179179
return sort.apply(this, arguments)
@@ -193,7 +193,7 @@ function getSortWrapper (sort) {
193193
let isDiEnabled = false
194194

195195
try {
196-
const { err, libraryConfig } = await getChannelPromise(libraryConfigurationCh)
196+
const { err, libraryConfig } = await getChannelPromise(libraryConfigurationCh, frameworkVersion)
197197
if (!err) {
198198
isFlakyTestRetriesEnabled = libraryConfig.isFlakyTestRetriesEnabled
199199
flakyTestRetriesCount = libraryConfig.flakyTestRetriesCount

packages/datadog-plugin-cypress/src/cypress-plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ class CypressPlugin {
550550
[TEST_SESSION_NAME]: testSessionName
551551
}
552552
}
553-
const libraryCapabilitiesTags = getLibraryCapabilitiesTags(this.constructor.id)
553+
const libraryCapabilitiesTags = getLibraryCapabilitiesTags(this.constructor.id, false, this.frameworkVersion)
554554
metadataTags.test = {
555555
...metadataTags.test,
556556
...libraryCapabilitiesTags

packages/dd-trace/src/plugins/ci_plugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ module.exports = class CiPlugin extends Plugin {
7575
this.rootDir = process.cwd() // fallback in case :session:start events are not emitted
7676

7777
this.addSub(`ci:${this.constructor.id}:library-configuration`, (ctx) => {
78-
const { onDone, isParallel } = ctx
78+
const { onDone, isParallel, frameworkVersion } = ctx
7979
ctx.currentStore = storage('legacy').getStore()
8080

8181
if (!this.tracer._exporter || !this.tracer._exporter.getLibraryConfiguration) {
@@ -88,7 +88,7 @@ module.exports = class CiPlugin extends Plugin {
8888
this.libraryConfig = libraryConfig
8989
}
9090

91-
const libraryCapabilitiesTags = getLibraryCapabilitiesTags(this.constructor.id, isParallel)
91+
const libraryCapabilitiesTags = getLibraryCapabilitiesTags(this.constructor.id, isParallel, frameworkVersion)
9292
const metadataTags = {
9393
test: {
9494
...libraryCapabilitiesTags

packages/dd-trace/src/plugins/util/test.js

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const fs = require('fs')
33
const { URL } = require('url')
44
const log = require('../../log')
55
const { getEnvironmentVariable } = require('../../config-helper')
6+
const satisfies = require('semifies')
67

78
const istanbul = require('istanbul-lib-coverage')
89
const ignore = require('ignore')
@@ -129,6 +130,18 @@ const DD_CAPABILITIES_TEST_MANAGEMENT_DISABLE = '_dd.library_capabilities.test_m
129130
const DD_CAPABILITIES_TEST_MANAGEMENT_ATTEMPT_TO_FIX = '_dd.library_capabilities.test_management.attempt_to_fix'
130131
const UNSUPPORTED_TIA_FRAMEWORKS = new Set(['playwright', 'vitest'])
131132
const UNSUPPORTED_TIA_FRAMEWORKS_PARALLEL_MODE = new Set(['cucumber', 'mocha'])
133+
const MINIMUM_FRAMEWORK_VERSION_FOR_EFD = {
134+
playwright: '>=1.38.0'
135+
}
136+
const MINIMUM_FRAMEWORK_VERSION_FOR_IMPACTED_TESTS = {
137+
playwright: '>=1.38.0'
138+
}
139+
const MINIMUM_FRAMEWORK_VERSION_FOR_QUARANTINE = {
140+
playwright: '>=1.38.0'
141+
}
142+
const MINIMUM_FRAMEWORK_VERSION_FOR_DISABLE = {
143+
playwright: '>=1.38.0'
144+
}
132145
const UNSUPPORTED_ATTEMPT_TO_FIX_FRAMEWORKS_PARALLEL_MODE = new Set(['mocha'])
133146
const NOT_SUPPORTED_GRANULARITY_IMPACTED_TESTS_FRAMEWORKS = new Set(['mocha', 'playwright', 'vitest'])
134147

@@ -895,18 +908,52 @@ function isTiaSupported (testFramework, isParallel) {
895908
(isParallel && UNSUPPORTED_TIA_FRAMEWORKS_PARALLEL_MODE.has(testFramework)))
896909
}
897910

911+
function isEarlyFlakeDetectionSupported (testFramework, frameworkVersion) {
912+
return testFramework === 'playwright'
913+
? satisfies(frameworkVersion, MINIMUM_FRAMEWORK_VERSION_FOR_EFD[testFramework])
914+
: true
915+
}
916+
917+
function isImpactedTestsSupported (testFramework, frameworkVersion) {
918+
return testFramework === 'playwright'
919+
? satisfies(frameworkVersion, MINIMUM_FRAMEWORK_VERSION_FOR_IMPACTED_TESTS[testFramework])
920+
: true
921+
}
922+
923+
function isQuarantineSupported (testFramework, frameworkVersion) {
924+
return testFramework === 'playwright'
925+
? satisfies(frameworkVersion, MINIMUM_FRAMEWORK_VERSION_FOR_QUARANTINE[testFramework])
926+
: true
927+
}
928+
929+
function isDisableSupported (testFramework, frameworkVersion) {
930+
return testFramework === 'playwright'
931+
? satisfies(frameworkVersion, MINIMUM_FRAMEWORK_VERSION_FOR_DISABLE[testFramework])
932+
: true
933+
}
934+
898935
function isAttemptToFixSupported (testFramework, isParallel) {
899936
return !(isParallel && UNSUPPORTED_ATTEMPT_TO_FIX_FRAMEWORKS_PARALLEL_MODE.has(testFramework))
900937
}
901938

902-
function getLibraryCapabilitiesTags (testFramework, isParallel) {
939+
function getLibraryCapabilitiesTags (testFramework, isParallel, frameworkVersion) {
903940
return {
904-
[DD_CAPABILITIES_TEST_IMPACT_ANALYSIS]: isTiaSupported(testFramework, isParallel) ? '1' : undefined,
905-
[DD_CAPABILITIES_EARLY_FLAKE_DETECTION]: '1',
941+
[DD_CAPABILITIES_TEST_IMPACT_ANALYSIS]: isTiaSupported(testFramework, isParallel)
942+
? '1'
943+
: undefined,
944+
[DD_CAPABILITIES_EARLY_FLAKE_DETECTION]: isEarlyFlakeDetectionSupported(testFramework, frameworkVersion)
945+
? '1'
946+
: undefined,
906947
[DD_CAPABILITIES_AUTO_TEST_RETRIES]: '1',
907-
[DD_CAPABILITIES_IMPACTED_TESTS]: '1',
908-
[DD_CAPABILITIES_TEST_MANAGEMENT_QUARANTINE]: '1',
909-
[DD_CAPABILITIES_TEST_MANAGEMENT_DISABLE]: '1',
948+
[DD_CAPABILITIES_IMPACTED_TESTS]: isImpactedTestsSupported(testFramework, frameworkVersion)
949+
? '1'
950+
: undefined,
951+
[DD_CAPABILITIES_TEST_MANAGEMENT_QUARANTINE]: isQuarantineSupported(testFramework, frameworkVersion)
952+
? '1'
953+
: undefined,
954+
[DD_CAPABILITIES_TEST_MANAGEMENT_DISABLE]: isDisableSupported(testFramework, frameworkVersion)
955+
? '1'
956+
: undefined,
910957
[DD_CAPABILITIES_TEST_MANAGEMENT_ATTEMPT_TO_FIX]: isAttemptToFixSupported(testFramework, isParallel)
911958
? '4'
912959
: undefined

0 commit comments

Comments
 (0)