| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 41edd2f commit 400d598
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,6 +2,7 @@ | |||
| 2 | 2 | const { | |
| 3 | 3 | ArrayFrom, | |
| 4 | 4 | ArrayPrototypeEvery, | |
| 5 | + ArrayPrototypeJoin, | ||
| 5 | 6 | ArrayPrototypePush, | |
| 6 | 7 | ArrayPrototypePushApply, | |
| 7 | 8 | ArrayPrototypeShift, | |
@@ -1672,6 +1673,17 @@ class Test extends AsyncResource { | |||
| 1672 | 1673 | details.passed_on_attempt = this.passedAttempt; | |
| 1673 | 1674 | } | |
| 1674 | 1675 | ||
| 1676 | + // Generate classname from suite hierarchy for JUnit reporter | ||
| 1677 | + if (this.parent && this.parent !== this.root) { | ||
| 1678 | + const parts = []; | ||
| 1679 | + for (let t = this.parent; t !== t.root; t = t.parent) { | ||
| 1680 | + ArrayPrototypeUnshift(parts, t.name); | ||
| 1681 | + } | ||
| 1682 | + if (parts.length > 0) { | ||
| 1683 | + details.classname = ArrayPrototypeJoin(parts, '.'); | ||
| 1684 | + } | ||
| 1685 | + } | ||
| 1686 | + | ||
| 1675 | 1687 | return { __proto__: null, details, directive }; | |
| 1676 | 1688 | } | |
| 1677 | 1689 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,6 +45,7 @@ class TestsStream extends Readable { | |||
| 45 | 45 | parentId, | |
| 46 | 46 | details, | |
| 47 | 47 | tags: ArrayPrototypeSlice(tags), | |
| 48 | + ...(details.classname && { __proto__: null, classname: details.classname }), | ||
| 48 | 49 | ...loc, | |
| 49 | 50 | ...directive, | |
| 50 | 51 | }); | |
@@ -60,6 +61,7 @@ class TestsStream extends Readable { | |||
| 60 | 61 | parentId, | |
| 61 | 62 | details, | |
| 62 | 63 | tags: ArrayPrototypeSlice(tags), | |
| 64 | + ...(details.classname && { __proto__: null, classname: details.classname }), | ||
| 63 | 65 | ...loc, | |
| 64 | 66 | ...directive, | |
| 65 | 67 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,19 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + require('../../../common'); | ||
| 3 | + const { suite, test } = require('node:test'); | ||
| 4 | + | ||
| 5 | + suite('Math', () => { | ||
| 6 | + suite('Addition', () => { | ||
| 7 | + test('adds positive numbers', () => {}); | ||
| 8 | + }); | ||
| 9 | + | ||
| 10 | + suite('Multiplication', () => { | ||
| 11 | + test('multiplies positive numbers', () => {}); | ||
| 12 | + }); | ||
| 13 | + }); | ||
| 14 | + | ||
| 15 | + suite('String', () => { | ||
| 16 | + test('concatenates strings', () => {}); | ||
| 17 | + }); | ||
| 18 | + | ||
| 19 | + test('standalone test', () => {}); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,23 @@ | |||
| 1 | + <?xml version="1.0" encoding="utf-8"?> | ||
| 2 | + <testsuites> | ||
| 3 | + <testsuite name="Math" time="*" disabled="0" errors="0" tests="2" failures="0" skipped="0" timestamp="*" hostname="HOSTNAME"> | ||
| 4 | + <testsuite name="Addition" time="*" disabled="0" errors="0" tests="1" failures="0" skipped="0" timestamp="*" hostname="HOSTNAME"> | ||
| 5 | + <testcase name="adds positive numbers" time="*" classname="Math.Addition" file="*"/> | ||
| 6 | + </testsuite> | ||
| 7 | + <testsuite name="Multiplication" time="*" disabled="0" errors="0" tests="1" failures="0" skipped="0" timestamp="*" hostname="HOSTNAME"> | ||
| 8 | + <testcase name="multiplies positive numbers" time="*" classname="Math.Multiplication" file="*"/> | ||
| 9 | + </testsuite> | ||
| 10 | + </testsuite> | ||
| 11 | + <testsuite name="String" time="*" disabled="0" errors="0" tests="1" failures="0" skipped="0" timestamp="*" hostname="HOSTNAME"> | ||
| 12 | + <testcase name="concatenates strings" time="*" classname="String" file="*"/> | ||
| 13 | + </testsuite> | ||
| 14 | + <testcase name="standalone test" time="*" classname="test" file="*"/> | ||
| 15 | + <!-- tests 4 --> | ||
| 16 | + <!-- suites 4 --> | ||
| 17 | + <!-- pass 4 --> | ||
| 18 | + <!-- fail 0 --> | ||
| 19 | + <!-- cancelled 0 --> | ||
| 20 | + <!-- skipped 0 --> | ||
| 21 | + <!-- todo 0 --> | ||
| 22 | + <!-- duration_ms * --> | ||
| 23 | + </testsuites> | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -129,7 +129,7 @@ true !== false | |||
| 129 | 129 | <testcase name="immediate reject - passes but warns" time="*" classname="test" file="*"/> | |
| 130 | 130 | <testcase name="immediate resolve pass" time="*" classname="test" file="*"/> | |
| 131 | 131 | <testsuite name="subtest sync throw fail" time="*" disabled="0" errors="0" tests="1" failures="1" skipped="0" timestamp="*" hostname="HOSTNAME"> | |
| 132 | - <testcase name="+sync throw fail" time="*" classname="test" file="*" failure="thrown from subtest sync throw fail"> | ||
| 132 | + <testcase name="+sync throw fail" time="*" classname="subtest sync throw fail" file="*" failure="thrown from subtest sync throw fail"> | ||
| 133 | 133 | <failure type="testCodeFailure" message="thrown from subtest sync throw fail"> | |
| 134 | 134 | Error [ERR_TEST_FAILURE]: thrown from subtest sync throw fail | |
| 135 | 135 | at TestContext.<anonymous> (<project-root>/test/fixtures/test-runner/output/output.js:125:11) | |
@@ -152,15 +152,15 @@ Error [ERR_TEST_FAILURE]: thrown from subtest sync throw fail | |||
| 152 | 152 | </failure> | |
| 153 | 153 | </testcase> | |
| 154 | 154 | <testsuite name="level 0a" time="*" disabled="0" errors="0" tests="4" failures="0" skipped="0" timestamp="*" hostname="HOSTNAME"> | |
| 155 | - <testcase name="level 1a" time="*" classname="test" file="*"/> | ||
| 156 | - <testcase name="level 1b" time="*" classname="test" file="*"/> | ||
| 157 | - <testcase name="level 1c" time="*" classname="test" file="*"/> | ||
| 158 | - <testcase name="level 1d" time="*" classname="test" file="*"/> | ||
| 155 | + <testcase name="level 1a" time="*" classname="level 0a" file="*"/> | ||
| 156 | + <testcase name="level 1b" time="*" classname="level 0a" file="*"/> | ||
| 157 | + <testcase name="level 1c" time="*" classname="level 0a" file="*"/> | ||
| 158 | + <testcase name="level 1d" time="*" classname="level 0a" file="*"/> | ||
| 159 | 159 | </testsuite> | |
| 160 | 160 | <testsuite name="top level" time="*" disabled="0" errors="0" tests="2" failures="0" skipped="0" timestamp="*" hostname="HOSTNAME"> | |
| 161 | - <testcase name="+long running" time="*" classname="test" file="*"/> | ||
| 161 | + <testcase name="+long running" time="*" classname="top level" file="*"/> | ||
| 162 | 162 | <testsuite name="+short running" time="*" disabled="0" errors="0" tests="1" failures="0" skipped="0" timestamp="*" hostname="HOSTNAME"> | |
| 163 | - <testcase name="++short running" time="*" classname="test" file="*"/> | ||
| 163 | + <testcase name="++short running" time="*" classname="top level.+short running" file="*"/> | ||
| 164 | 164 | </testsuite> | |
| 165 | 165 | </testsuite> | |
| 166 | 166 | <testcase name="invalid subtest - pass but subtest fails" time="*" classname="test" file="*"/> | |
@@ -267,9 +267,9 @@ Error [ERR_TEST_FAILURE]: thrown from callback async throw | |||
| 267 | 267 | </testcase> | |
| 268 | 268 | <testcase name="callback async throw after done" time="*" classname="test" file="*"/> | |
| 269 | 269 | <testsuite name="only is set on subtests but not in only mode" time="*" disabled="0" errors="0" tests="3" failures="0" skipped="0" timestamp="*" hostname="HOSTNAME"> | |
| 270 | - <testcase name="running subtest 1" time="*" classname="test" file="*"/> | ||
| 271 | - <testcase name="running subtest 3" time="*" classname="test" file="*"/> | ||
| 272 | - <testcase name="running subtest 4" time="*" classname="test" file="*"/> | ||
| 270 | + <testcase name="running subtest 1" time="*" classname="only is set on subtests but not in only mode" file="*"/> | ||
| 271 | + <testcase name="running subtest 3" time="*" classname="only is set on subtests but not in only mode" file="*"/> | ||
| 272 | + <testcase name="running subtest 4" time="*" classname="only is set on subtests but not in only mode" file="*"/> | ||
| 273 | 273 | </testsuite> | |
| 274 | 274 | <testcase name="custom inspect symbol fail" time="*" classname="test" file="*" failure="customized"> | |
| 275 | 275 | <failure type="testCodeFailure" message="customized"> | |
@@ -289,7 +289,7 @@ Error [ERR_TEST_FAILURE]: thrown from callback async throw | |||
| 289 | 289 | </failure> | |
| 290 | 290 | </testcase> | |
| 291 | 291 | <testsuite name="subtest sync throw fails" time="*" disabled="0" errors="0" tests="2" failures="2" skipped="0" timestamp="*" hostname="HOSTNAME"> | |
| 292 | - <testcase name="sync throw fails at first" time="*" classname="test" file="*" failure="thrown from subtest sync throw fails at first"> | ||
| 292 | + <testcase name="sync throw fails at first" time="*" classname="subtest sync throw fails" file="*" failure="thrown from subtest sync throw fails at first"> | ||
| 293 | 293 | <failure type="testCodeFailure" message="thrown from subtest sync throw fails at first"> | |
| 294 | 294 | Error [ERR_TEST_FAILURE]: thrown from subtest sync throw fails at first | |
| 295 | 295 | at TestContext.<anonymous> (<project-root>/test/fixtures/test-runner/output/output.js:334:11) | |
@@ -304,7 +304,7 @@ Error [ERR_TEST_FAILURE]: thrown from subtest sync throw fails at first | |||
| 304 | 304 | } | |
| 305 | 305 | </failure> | |
| 306 | 306 | </testcase> | |
| 307 | - <testcase name="sync throw fails at second" time="*" classname="test" file="*" failure="thrown from subtest sync throw fails at second"> | ||
| 307 | + <testcase name="sync throw fails at second" time="*" classname="subtest sync throw fails" file="*" failure="thrown from subtest sync throw fails at second"> | ||
| 308 | 308 | <failure type="testCodeFailure" message="thrown from subtest sync throw fails at second"> | |
| 309 | 309 | Error [ERR_TEST_FAILURE]: thrown from subtest sync throw fails at second | |
| 310 | 310 | at TestContext.<anonymous> (<project-root>/test/fixtures/test-runner/output/output.js:337:11) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -207,7 +207,7 @@ describe('node:test reporters', { concurrency: true }, () => { | |||
| 207 | 207 | assert.match(timestamp, /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/); | |
| 208 | 208 | assert.ok(!Number.isNaN(Date.parse(timestamp)), `expected a valid date, got ${timestamp}`); | |
| 209 | 209 | assert.match(fileContents, /<testcase .*name="failing".*>\s*<failure .*type="testCodeFailure".*message="error".*>/); | |
| 210 | - assert.match(fileContents, /<testcase .*name="ok".*classname="test".*\/>/); | ||
| 210 | + assert.match(fileContents, /<testcase .*name="ok".*classname="nested".*\/>/); | ||
| 211 | 211 | assert.match(fileContents, /<testcase .*name="top level".*classname="test".*\/>/); | |
| 212 | 212 | }); | |
| 213 | 213 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,12 @@ | |||
| 1 | + // Test that the output of test-runner/output/junit_classname_hierarchy.js matches | ||
| 2 | + // test-runner/output/junit_classname_hierarchy.snapshot | ||
| 3 | + import '../common/index.mjs'; | ||
| 4 | + import * as fixtures from '../common/fixtures.mjs'; | ||
| 5 | + import { spawnAndAssert, junitTransform, ensureCwdIsProjectRoot } from '../common/assertSnapshot.js'; | ||
| 6 | + | ||
| 7 | + ensureCwdIsProjectRoot(); | ||
| 8 | + await spawnAndAssert( | ||
| 9 | + fixtures.path('test-runner/output/junit_classname_hierarchy.js'), | ||
| 10 | + junitTransform, | ||
| 11 | + { flags: ['--test-reporter=junit'] }, | ||
| 12 | + ); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments