Skip to content

Commit b44bfca

Browse files
fix test suite duration
1 parent fe11901 commit b44bfca

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

packages/datadog-instrumentations/src/playwright.js

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const STATUS_TO_TEST_STATUS = {
4949
}
5050

5151
let remainingTestsByFile = {}
52+
let skippedTestsByFile = {}
5253
let isKnownTestsEnabled = false
5354
let isEarlyFlakeDetectionEnabled = false
5455
let earlyFlakeDetectionNumRetries = 0
@@ -127,15 +128,20 @@ function deepCloneSuite (suite, filterTest, tags = []) {
127128
}
128129

129130
function getTestsBySuiteFromTestGroups (testGroups) {
130-
return testGroups.reduce((acc, { requireFile, tests }) => {
131-
if (acc[requireFile]) {
132-
acc[requireFile].push(...tests)
133-
} else {
134-
// Copy the tests, otherwise we modify the original tests
135-
acc[requireFile] = [...tests]
136-
}
131+
const nonSkippedTestGroups = testGroups.reduce((acc, { requireFile, tests }) => {
132+
const nonSkippedTests = tests.filter(test => test.expectedStatus !== 'skipped')
133+
acc[requireFile] = acc[requireFile] ? [...acc[requireFile], ...nonSkippedTests] : [...nonSkippedTests]
134+
return acc
135+
}, {})
136+
const skippedTestGroups = testGroups.reduce((acc, { requireFile, tests }) => {
137+
const skippedTests = tests.filter(test => test.expectedStatus === 'skipped')
138+
acc[requireFile] = acc[requireFile] ? [...acc[requireFile], ...skippedTests] : [...skippedTests]
137139
return acc
138140
}, {})
141+
return {
142+
nonSkippedTestGroups,
143+
skippedTestGroups
144+
}
139145
}
140146

141147
function getTestsBySuiteFromTestsById (testsById) {
@@ -305,6 +311,15 @@ function testBeginHandler (test, browserName, isMainProcess) {
305311
const testSuiteCtx = { testSuiteAbsolutePath }
306312
testSuiteToCtx.set(testSuiteAbsolutePath, testSuiteCtx)
307313
testSuiteStartCh.runStores(testSuiteCtx, () => {})
314+
const skippedTests = skippedTestsByFile[testSuiteAbsolutePath]
315+
if (skippedTests) {
316+
// We report the skipped tests at the beginning of the suite to avoid
317+
skippedTests.forEach(test => {
318+
testBeginHandler(test, browserName, true)
319+
testEndHandler(test, [], 'skip', null, false, true)
320+
})
321+
delete skippedTestsByFile[testSuiteAbsolutePath]
322+
}
308323
}
309324

310325
// We disable retries by default if attemptToFix is true
@@ -428,6 +443,7 @@ function testEndHandler (test, annotations, testStatus, error, isTimeout, isMain
428443

429444
function dispatcherRunWrapper (run) {
430445
return function () {
446+
// TODO: add `skippedTestsByFile` here
431447
remainingTestsByFile = getTestsBySuiteFromTestsById(this._testById)
432448
return run.apply(this, arguments)
433449
}
@@ -440,7 +456,9 @@ function dispatcherRunWrapperNew (run) {
440456
// Not available from >=1.44.0
441457
this._ddAllTests = testGroups.flatMap(g => g.tests)
442458
}
443-
remainingTestsByFile = getTestsBySuiteFromTestGroups(testGroups)
459+
const { nonSkippedTestGroups, skippedTestGroups } = getTestsBySuiteFromTestGroups(testGroups)
460+
remainingTestsByFile = nonSkippedTestGroups
461+
skippedTestsByFile = skippedTestGroups
444462
return run.apply(this, arguments)
445463
}
446464
}
@@ -628,7 +646,7 @@ function runAllTestsWrapper (runAllTests, playwrightVersion) {
628646
Object.values(remainingTestsByFile).forEach(tests => {
629647
// `tests` should normally be empty, but if it isn't,
630648
// there were tests that did not go through `testBegin` or `testEnd`,
631-
// because they were skipped
649+
// because they were skipped and were not handled in `skippedTestsByFile`
632650
tests.forEach(test => {
633651
const browser = getBrowserNameFromProjects(projects, test)
634652
testBeginHandler(test, browser, true)

0 commit comments

Comments
 (0)