diff --git a/lib/internal/test_runner/reporter/junit.js b/lib/internal/test_runner/reporter/junit.js index 24bbd9ffc3e1cc..d9f9126ba28f85 100644 --- a/lib/internal/test_runner/reporter/junit.js +++ b/lib/internal/test_runner/reporter/junit.js @@ -116,6 +116,9 @@ module.exports = async function* junitReporter(source) { } else { currentTest.tag = 'testcase'; currentTest.attrs.classname = event.data.classname ?? 'test'; + if (event.data.file) { + currentTest.attrs.file = event.data.file; + } if (event.data.skip) { ArrayPrototypePush(currentTest.children, { __proto__: null, nesting: event.data.nesting + 1, tag: 'skipped', diff --git a/test/fixtures/test-runner/output/junit_reporter.snapshot b/test/fixtures/test-runner/output/junit_reporter.snapshot index 37cea45d62bd84..e955f9666049ca 100644 --- a/test/fixtures/test-runner/output/junit_reporter.snapshot +++ b/test/fixtures/test-runner/output/junit_reporter.snapshot @@ -1,12 +1,12 @@ - + - + - + [Error [ERR_TEST_FAILURE]: thrown from sync fail todo] { @@ -23,7 +23,7 @@ } - + [Error [ERR_TEST_FAILURE]: thrown from sync fail todo with message] { @@ -40,15 +40,15 @@ } - + - + - + - + [Error [ERR_TEST_FAILURE]: thrown from sync throw fail] { code: 'ERR_TEST_FAILURE', @@ -64,11 +64,11 @@ } - + - - + + [Error [ERR_TEST_FAILURE]: thrown from async throw fail] { code: 'ERR_TEST_FAILURE', @@ -84,7 +84,7 @@ } - + [Error [ERR_TEST_FAILURE]: thrown from async throw fail] { @@ -101,7 +101,7 @@ } - + [Error [ERR_TEST_FAILURE]: Expected values to be strictly equal: @@ -130,8 +130,8 @@ true !== false } - - + + [Error [ERR_TEST_FAILURE]: rejected from reject fail] { code: 'ERR_TEST_FAILURE', @@ -147,13 +147,13 @@ true !== false } - - - - - + + + + + - + Error [ERR_TEST_FAILURE]: thrown from subtest sync throw fail * @@ -176,31 +176,31 @@ Error [ERR_TEST_FAILURE]: thrown from subtest sync throw fail - + [Error [ERR_TEST_FAILURE]: Symbol(thrown symbol from sync throw non-error fail)] { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: Symbol(thrown symbol from sync throw non-error fail) } - - - - + + + + - + - + - - + + - + - + [Error [ERR_TEST_FAILURE]: this should be executed] { code: 'ERR_TEST_FAILURE', @@ -216,22 +216,22 @@ Error [ERR_TEST_FAILURE]: thrown from subtest sync throw fail } - - - - - - + + + + + + - + - + - - + + [Error [ERR_TEST_FAILURE]: callback failure] { code: 'ERR_TEST_FAILURE', @@ -242,15 +242,15 @@ Error [ERR_TEST_FAILURE]: thrown from subtest sync throw fail } - - - - + + + + [Error [ERR_TEST_FAILURE]: passed a callback but also returned a Promise] { code: 'ERR_TEST_FAILURE', failureType: 'callbackAndPromisePresent', cause: 'passed a callback but also returned a Promise' } - + [Error [ERR_TEST_FAILURE]: thrown from callback throw] { code: 'ERR_TEST_FAILURE', @@ -266,7 +266,7 @@ Error [ERR_TEST_FAILURE]: thrown from subtest sync throw fail } - + Error [ERR_TEST_FAILURE]: callback invoked multiple times * @@ -277,8 +277,8 @@ Error [ERR_TEST_FAILURE]: callback invoked multiple times } - - + + Error [ERR_TEST_FAILURE]: callback invoked multiple times * { @@ -293,7 +293,7 @@ Error [ERR_TEST_FAILURE]: callback invoked multiple times } - + Error [ERR_TEST_FAILURE]: thrown from callback async throw * { @@ -305,18 +305,18 @@ Error [ERR_TEST_FAILURE]: thrown from callback async throw } - + - - - + + + - + [Error [ERR_TEST_FAILURE]: customized] { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: customized } - + [Error [ERR_TEST_FAILURE]: { foo: 1, @@ -329,7 +329,7 @@ Error [ERR_TEST_FAILURE]: thrown from callback async throw - + Error [ERR_TEST_FAILURE]: thrown from subtest sync throw fails at first * @@ -350,7 +350,7 @@ Error [ERR_TEST_FAILURE]: thrown from subtest sync throw fails at first } - + Error [ERR_TEST_FAILURE]: thrown from subtest sync throw fails at second * { @@ -369,25 +369,25 @@ Error [ERR_TEST_FAILURE]: thrown from subtest sync throw fails at second - + [Error [ERR_TEST_FAILURE]: test timed out after 5ms] { code: 'ERR_TEST_FAILURE', failureType: 'testTimeoutFailure', cause: 'test timed out after 5ms' } - + [Error [ERR_TEST_FAILURE]: test timed out after 5ms] { code: 'ERR_TEST_FAILURE', failureType: 'testTimeoutFailure', cause: 'test timed out after 5ms' } - - - - + + + + [Error [ERR_TEST_FAILURE]: custom error] { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: 'custom error' } - + Error [ERR_TEST_FAILURE]: foo * { @@ -400,7 +400,7 @@ Error [ERR_TEST_FAILURE]: foo } - + Error [ERR_TEST_FAILURE]: bar * { @@ -413,7 +413,7 @@ Error [ERR_TEST_FAILURE]: bar } - + [Error [ERR_TEST_FAILURE]: Expected values to be loosely deep-equal: @@ -498,7 +498,7 @@ should loosely deep-equal } - + Error [ERR_TEST_FAILURE]: test could not be started because its parent finished * { diff --git a/test/parallel/test-runner-output.mjs b/test/parallel/test-runner-output.mjs index 7169c28e293dbe..094df64864bae0 100644 --- a/test/parallel/test-runner-output.mjs +++ b/test/parallel/test-runner-output.mjs @@ -38,6 +38,7 @@ function replaceJunitDuration(str) { .replaceAll(/time="[0-9.]+"/g, 'time="*"') .replaceAll(/duration_ms [0-9.]+/g, 'duration_ms *') .replaceAll(`hostname="${hostname()}"`, 'hostname="HOSTNAME"') + .replaceAll(/file="[^"]*"/g, 'file="*"') .replace(stackTraceBasePath, '$3'); }