test(ci): refine test suite name unique (#54013)

### What

Pairing PR to https://github.com/vercel/turbo/pull/5714, which I believe last piece to reenable correct datadog test reports for daily next.js integration + turbopack.

1. Creates a unique suite name to avoid collision / merging across different env / grouped test run
2. revert suitename template (which is for _suites_, not _suite_ for top level) as 1 resolves uniqueness
This commit is contained in:
OJ Kwon 2023-08-14 12:58:56 -07:00 committed by GitHub
parent 3d569bd92a
commit 2e67454ae5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 8 deletions

View file

@ -30,9 +30,7 @@ const customJestConfig = {
// This won't count for the retry to avoid duplicated test being reported twice
// - which means our test trace will report test results for the flaky test as failed without retry.
const shouldEnableTestTrace =
process.env.DATADOG_API_KEY &&
process.env.DATADOG_TRACE_NEXTJS_TEST &&
!process.env.IS_RETRY
process.env.DATADOG_API_KEY && process.env.DATADOG_TRACE_NEXTJS_TEST
if (shouldEnableTestTrace) {
if (!customJestConfig.reporters) {
@ -48,11 +46,6 @@ if (shouldEnableTestTrace) {
'jest-junit',
{
outputDirectory,
// note: {filename} is not a full path, since putting full path
// makes suite name too long and truncates and not able to read the suite name
suiteNameTemplate: `{title} [${process.env.NEXT_TEST_MODE ?? 'default'}${
process.env.TURBOPACK ? '/t' : ''
}${process.env.EXPERIMENTAL_TURBOPACK ? '/et' : ''}/{filename}]`,
reportTestSuiteErrors: 'true',
uniqueOutputName: 'true',
outputName: 'nextjs-test-junit',

View file

@ -278,6 +278,7 @@ async function main() {
console.log(`${GROUP}Running tests:
${testNames.join('\n')}
${ENDGROUP}`)
console.log(`total: ${testNames.length}`)
const hasIsolatedTests = testNames.some((test) => {
return configuredTestTypes.some(
@ -365,6 +366,22 @@ ${ENDGROUP}`)
CONTINUOUS_INTEGRATION: '',
RUN_ID: '',
BUILD_NUMBER: '',
// Format the output of junit report to include the test name
// For the debugging purpose to compare actual run list to the generated reports
// [NOTE]: This won't affect if junit reporter is not enabled
JEST_JUNIT_OUTPUT_NAME:
test && test.length > 0 ? test.replaceAll('/', '_') : undefined,
// Specify suite name for the test to avoid unexpected merging across different env / grouped tests
// This is not individual suites name (corresponding 'describe'), top level suite name which have redundant names by default
// [NOTE]: This won't affect if junit reporter is not enabled
JEST_SUITE_NAME: [
`${process.env.NEXT_TEST_MODE ?? 'default'}`,
groupArg,
testType,
test,
]
.filter(Boolean)
.join(':'),
...(isFinalRun
? {
// Events can be finicky in CI. This switches to a more