Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions integration-tests/mocha/mocha.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2100,6 +2100,60 @@ describe(`mocha@${MOCHA_VERSION}`, function () {
}).catch(done)
})
})

onlyLatestIt('can skip suites in parallel mode', async () => {
receiver.setSuitesToSkip([{
type: 'suite',
attributes: {
suite: 'ci-visibility/test/ci-visibility-test.js',
},
}])

const eventsPromise = receiver
.gatherPayloadsMaxTimeout(({ url }) => url.endsWith('/api/v2/citestcycle'), (payloads) => {
const events = payloads.flatMap(({ payload }) => payload.events)
const testSession = events.find(event => event.type === 'test_session_end').content
assert.strictEqual(testSession.meta[MOCHA_IS_PARALLEL], 'true')
assert.strictEqual(testSession.meta[TEST_ITR_SKIPPING_ENABLED], 'true')
assert.strictEqual(testSession.meta[TEST_ITR_TESTS_SKIPPED], 'true')
assert.strictEqual(testSession.meta[TEST_ITR_SKIPPING_TYPE], 'suite')
assert.strictEqual(testSession.metrics[TEST_ITR_SKIPPING_COUNT], 1)

const suites = events.filter(event => event.type === 'test_suite_end').map(event => event.content)
assert.strictEqual(suites.length, 2)

const skippedSuite = suites.find(s =>
s.resource === 'test_suite.ci-visibility/test/ci-visibility-test.js'
)
assert.strictEqual(skippedSuite.meta[TEST_STATUS], 'skip')
assert.strictEqual(skippedSuite.meta[TEST_SKIPPED_BY_ITR], 'true')

const runningSuite = suites.find(s =>
s.resource === 'test_suite.ci-visibility/test/ci-visibility-test-2.js'
)
assert.strictEqual(runningSuite.meta[TEST_STATUS], 'pass')

// Only 1 test ran (from the non-skipped suite)
const tests = events.filter(event => event.type === 'test').map(event => event.content)
assert.strictEqual(tests.length, 1)
assert.strictEqual(tests[0].meta[TEST_STATUS], 'pass')
})

childProcess = exec(
'node node_modules/mocha/bin/mocha --parallel --jobs 2' +
' ./ci-visibility/test/ci-visibility-test.js' +
' ./ci-visibility/test/ci-visibility-test-2.js',
{
cwd,
env: getCiVisAgentlessConfig(receiver.port),
}
)

await Promise.all([
eventsPromise,
once(childProcess, 'exit'),
])
})
})

context('error tags', () => {
Expand Down
32 changes: 28 additions & 4 deletions packages/datadog-instrumentations/src/mocha/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function getOnStartHandler (isParallel, frameworkVersion) {
const processArgv = process.argv.slice(2).join(' ')
const command = `mocha ${processArgv}`
testSessionStartCh.publish({ command, frameworkVersion })
if (!isParallel && skippedSuites.length) {
if (skippedSuites.length) {
itrSkippedSuitesCh.publish({ skippedSuites, frameworkVersion })
}
}
Expand Down Expand Up @@ -315,8 +315,7 @@ function getExecutionConfiguration (runner, isParallel, frameworkVersion, onFini
config.isTestManagementTestsEnabled = libraryConfig.isTestManagementEnabled
config.testManagementAttemptToFixRetries = libraryConfig.testManagementAttemptToFixRetries
config.isImpactedTestsEnabled = libraryConfig.isImpactedTestsEnabled
// ITR is not supported in parallel mode yet
config.isSuitesSkippingEnabled = !isParallel && libraryConfig.isSuitesSkippingEnabled
config.isSuitesSkippingEnabled = libraryConfig.isSuitesSkippingEnabled
config.isFlakyTestRetriesEnabled = libraryConfig.isFlakyTestRetriesEnabled
config.flakyTestRetriesCount = libraryConfig.flakyTestRetriesCount

Expand Down Expand Up @@ -626,6 +625,13 @@ addHook({
this.once('start', getOnStartHandler(true, frameworkVersion))
this.once('end', getOnEndHandler(true))

// Populate unskippable suites before config is fetched (matches serial mode at Mocha.prototype.run)
for (const filePath of files) {
if (isMarkedAsUnskippable({ path: filePath })) {
unskippableSuites.push(filePath)
}
}

getExecutionConfiguration(this, true, frameworkVersion, () => {
if (config.isKnownTestsEnabled) {
const testSuites = files.map(file => getTestSuitePath(file, process.cwd()))
Expand All @@ -640,7 +646,25 @@ addHook({
config.isEarlyFlakeDetectionFaulty = true
}
}
run.apply(this, arguments)
if (config.isSuitesSkippingEnabled && suitesToSkip.length) {
const filteredFiles = []
const skippedFiles = []
for (const file of files) {
const testPath = getTestSuitePath(file, process.cwd())
const shouldSkip = suitesToSkip.includes(testPath)
const isUnskippable = unskippableSuites.includes(file)
if (shouldSkip && !isUnskippable) {
skippedFiles.push(testPath)
} else {
filteredFiles.push(file)
}
}
isSuitesSkipped = skippedFiles.length > 0
skippedSuites = skippedFiles
run.apply(this, [cb, { files: filteredFiles }])
} else {
run.apply(this, arguments)
}
})

return this
Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/src/plugins/util/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
const DD_CI_LIBRARY_CONFIGURATION_ERROR = '_dd.ci.library_configuration_error'

const UNSUPPORTED_TIA_FRAMEWORKS = new Set(['playwright', 'vitest'])
const UNSUPPORTED_TIA_FRAMEWORKS_PARALLEL_MODE = new Set(['cucumber', 'mocha'])
const UNSUPPORTED_TIA_FRAMEWORKS_PARALLEL_MODE = new Set(['cucumber'])
const MINIMUM_FRAMEWORK_VERSION_FOR_EFD = {
playwright: '>=1.38.0',
}
Expand All @@ -170,7 +170,7 @@
playwright: '>=1.38.0',
}

const UNSUPPORTED_ATTEMPT_TO_FIX_FRAMEWORKS_PARALLEL_MODE = new Set([])

Check failure on line 173 in packages/dd-trace/src/plugins/util/test.js

View workflow job for this annotation

GitHub Actions / lint

The empty array is useless
const NOT_SUPPORTED_GRANULARITY_IMPACTED_TESTS_FRAMEWORKS = new Set(['mocha', 'playwright', 'vitest'])

const TEST_LEVEL_EVENT_TYPES = [
Expand Down
Loading