Skip to content

test: add file attribute to JUnit reporter testcase elements - #59432

Closed
sangwook-dev wants to merge 2 commits into
nodejs:mainfrom
sangwook-dev:add-junit-file-attribute
Closed

sangwook-dev wants to merge 2 commits into
nodejs:mainfrom
sangwook-dev:add-junit-file-attribute

Conversation

@sangwook-dev

Copy link
Copy Markdown
Contributor

Fixes: #59422

This PR adds support for the file attribute in JUnit XML reporter's testcase elements, addressing the missing source file information that is useful for CI/CD platforms
like GitLab.

Changes

  • Add file attribute normalization infrastructure in test output transform
  • Implement file attribute support in JUnit reporter for testcase elements
  • Include comprehensive tests to verify correct file path handling

Background

The JUnit XML specification supports a file attribute on testcase elements to indicate the source file containing the test. This attribute was missing from Node.js test
runner's JUnit output, limiting integration with tools that rely on this information for enhanced test reporting.

Before:

<testcase name="testName" time="0.000414" classname="test" failure="Failed">

After:
<testcase name="testName" time="0.000414" classname="test" file="src/junit.test.mts" failure="Failed">

Testing
image

  • All existing tests pass
  • New tests verify file attribute is correctly included
  • File path normalization works across platforms

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/test_runner

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem. labels Aug 10, 2025
@codecov

codecov Bot commented Aug 11, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.54%. Comparing base (b757a8f) to head (6509a5e).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #59432   +/-   ##
=======================================
  Coverage   88.53%   88.54%           
=======================================
  Files         703      703           
  Lines      207804   207807    +3     
  Branches    40005    40005           
=======================================
+ Hits       183989   184005   +16     
+ Misses      15817    15811    -6     
+ Partials     7998     7991    -7     
Files with missing lines Coverage Δ
lib/internal/test_runner/reporter/junit.js 94.47% <100.00%> (+0.10%) ⬆️

... and 25 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sangwook-dev
sangwook-dev force-pushed the add-junit-file-attribute branch from 791f5f7 to 2473640 Compare August 11, 2025 11:38
@sangwook-dev

Copy link
Copy Markdown
Contributor Author

@MoLow

Force pushed to fix commit message lint error - shortened title to meet 72 character limit per Node.js contribution guidelines.

@sangwook-dev
sangwook-dev force-pushed the add-junit-file-attribute branch from 2473640 to 70e2c68 Compare August 14, 2025 20:39
@sangwook-dev

Copy link
Copy Markdown
Contributor Author

Force pushed to fix commit message lint error - shortened title to meet 72 character limit per Node.js contribution guidelines.

@atlowChemi

atlowChemi commented Aug 18, 2025 •

Copy link
Copy Markdown
Member

@Han5991 Thanks for the contribution!
The submodule of the second commit should be test_runner, not test (test is the repo's tests themself, while test_runner is node's node:test module 🙂)

@sangwook-dev
sangwook-dev force-pushed the add-junit-file-attribute branch from 70e2c68 to fa35503 Compare August 18, 2025 06:08
@sangwook-dev

Copy link
Copy Markdown
Contributor Author

@atlowChemi

Thank you! The submodule reference has been successfully changed from "test" to "test_runner" in the second commit message.

@atlowChemi

Copy link
Copy Markdown
Member

@atlowChemi

Thank you! The submodule reference has been successfully changed from "test" to "test_runner" in the second commit message.

They seem to be applied the wrong way?
The commit which handles the tests is currently test_runner, and the one changing the test runner is test

@sangwook-dev
sangwook-dev force-pushed the add-junit-file-attribute branch from fa35503 to 25aeae1 Compare August 18, 2025 08:50
@sangwook-dev

Copy link
Copy Markdown
Contributor Author

@atlowChemi
Thank you! The submodule reference has been successfully changed from "test" to "test_runner" in the second commit message.

They seem to be applied the wrong way? The commit which handles the tests is currently test_runner, and the one changing the test runner is test

@atlowChemi
Thank you for checking! I've reapplied the changes with the correct commit message prefixes - now the test_runner module changes use test_runner: and the test preparation changes use test:.

@atlowChemi atlowChemi added commit-queue-rebase PRs the Commit Queue should land as multiple self-contained commits. request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels Aug 18, 2025
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Aug 18, 2025
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@bjohansebas bjohansebas added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Sep 17, 2025
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Sep 17, 2025
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/69263/

@sangwook-dev

Copy link
Copy Markdown
Contributor Author

@atlowChemi

One of the CI jobs seems to have failed due to a flaky test. Would you mind rerunning just the failed job when you have a chance?

Add file attribute normalization in JUnit test output transform to
support upcoming file attribute feature in JUnit XML reporter.
Add file attribute to JUnit testcase elements when file information
is available in test event data.
@sangwook-dev
sangwook-dev force-pushed the add-junit-file-attribute branch from 25aeae1 to 6509a5e Compare October 7, 2025 08:03
@MoLow MoLow added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Oct 8, 2025
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Oct 8, 2025
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/69612/

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/69613/

@MoLow MoLow added the commit-queue PRs queued for automated landing through the Commit Queue. label Oct 8, 2025
@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Oct 8, 2025
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 1527825...f0aa073

nodejs-github-bot pushed a commit that referenced this pull request Oct 8, 2025
Add file attribute normalization in JUnit test output transform to
support upcoming file attribute feature in JUnit XML reporter.

PR-URL: #59432
Fixes: #59422
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
nodejs-github-bot pushed a commit that referenced this pull request Oct 8, 2025
Add file attribute to JUnit testcase elements when file information
is available in test event data.

PR-URL: #59432
Fixes: #59422
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
@RafaelGSS RafaelGSS mentioned this pull request Oct 13, 2025
9 tasks done
aduh95 pushed a commit that referenced this pull request Oct 31, 2025
Add file attribute normalization in JUnit test output transform to
support upcoming file attribute feature in JUnit XML reporter.

PR-URL: #59432
Fixes: #59422
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
aduh95 pushed a commit that referenced this pull request Oct 31, 2025
Add file attribute to JUnit testcase elements when file information
is available in test event data.

PR-URL: #59432
Fixes: #59422
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
aduh95 pushed a commit that referenced this pull request Nov 7, 2025
Add file attribute normalization in JUnit test output transform to
support upcoming file attribute feature in JUnit XML reporter.

PR-URL: #59432
Fixes: #59422
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
aduh95 pushed a commit that referenced this pull request Nov 7, 2025
Add file attribute to JUnit testcase elements when file information
is available in test event data.

PR-URL: #59432
Fixes: #59422
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
@sangwook-dev
sangwook-dev deleted the add-junit-file-attribute branch February 8, 2026 05:42
ChefGroep added a commit to GroepOnline/chefgroep-commander that referenced this pull request Nov 9, 2026
The first real corpus from the merged pipeline could not be used, and the
failure was hiding behind a fabricated filename.

Observed on PR #505, run 42560237630 (head dca2c21, attempt 1, runner
commander-ci-oci-h2qr4-runner-bk7cx, node-tests success): the uploaded
node-tests JUnit carried no file attribute on any testcase, so all 1798
testcases collapsed into one row and no time could be attributed to a file.
The canonical node-tests job pins Node 22.23.2; the file attribute exists only
from the Node line that added it (nodejs/node#59432, f0aa073, 24.x). The same
canonical command locally on Node 24.22.1 produced 223 rows with real paths.

- test-timing-report: displayPath returns null instead of inventing
  "(unknown file)", so the JSON keeps the gap visible. Markdown still labels the
  row "(no file identity)", and rows without identity sort after real paths on
  equal time instead of displacing one.
- test-shard-plan: name that case explicitly instead of reporting a generic
  unsafe path, because the cause is the reporter's runtime, not bad input.
- docs/ci-test-timing.md: record the measurement, the required runtime, and why
  the canonical job must not be moved off its pinned version to obtain a
  corpus; a separate timing lane needs its own cost and admission decision.

Verified end to end against the real artifact: the re-extracted report now shows
"(no file identity)" and the planner exits 2 with the runtime message, writing
no output. Focused suites 20/20 pass; lint, lint:sync, graph check and
diff check pass. No weights were invented and no routing changed.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
MisterWanted pushed a commit to GroepOnline/chefgroep-commander that referenced this pull request Nov 9, 2026
* ci: split native-artifact suite and report per-file test timing

node --test runs files concurrently but tests inside a file serially, so
tests/deploy/native-artifact.test.mjs (34 tests, ~80 artifact builds) was a
201s serial floor on every Node suite run. Split it verbatim into build,
install and reuse files with shared helpers.

Add scripts/ci/test-timing-report.mjs, which summarises node:test JUnit
per file, warns on a per-file budget and writes a step summary and JSON.
node-tests and node-compat now emit JUnit through COMMANDER_TEST_JUNIT and
publish the report; node-tests uploads it as an artifact. Both steps are
non-fatal observability and never block the merge gate.

Local full npm test (4 CPU, Node 24.22.1): 219.5s -> 170.2s; largest file
serial time 201s -> 83.5s.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>

* ci: fail closed on timing inventory and plan shards offline

Timing-driven shards need complete, trustworthy per-file coverage before any
routing change. Add an offline planner that derives the canonical test-file
inventory from the npm test operands and refuses missing, unknown, duplicate,
unsafe or invalid rows instead of guessing weights.

- scripts/ci/test-shard-plan.mjs: fail-closed audit and deterministic advisory
  LPT dry-run partitions; never executes input; refuses input/output aliases;
  invalid input preserves existing output.
- tests/ci/test-shard-plan.test.mjs: real-CLI inventory run plus malformed,
  duplicate, unknown, tie, zero, count-edge and overflow regressions.
- test-timing-report: reject blank and nonfinite durations, overflowing totals
  and nonfinite budgets; order equal files by code unit, not locale.
- Correct the overlapping-timing comment: nested testcase sums are neither a
  wall-clock estimate nor a shard lower bound.
- package.json: default JUnit destination becomes a Git-ignored regular file.
  Node 24.22.1 fsync on /dev/null raised EINVAL after the suite completed.
  Explicit CI destinations and nonzero exits on real failures are unchanged.
- docs/ci-test-timing.md: trust scope, provenance requirements and advisory-only
  limits of local measurements.

Local canonical npm test: 1805 tests, 1800 pass, 0 fail, 5 skipped; independent
XML/glob check matched all 223 files exactly once across four dry-run shards.
No speedup, CI-provenance, isolation or provider-lane claim.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>

* ci: re-run admission after the operator-approved oversize exception

The policy classifies this PR as oversize because the verbatim native-artifact
split moves 3392 lines. The operator explicitly approved the exception; the
ci:oversize-approved label and the OVERSIZE-JUSTIFICATION line are in place.

This empty commit exists only because pull_request runs are triggered by
synchronize, and pr-policy only reclassifies on a new push. It changes no file.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>

* fix(ci): keep a missing file identity visible in timing evidence

The first real corpus from the merged pipeline could not be used, and the
failure was hiding behind a fabricated filename.

Observed on PR #505, run 42560237630 (head dca2c21, attempt 1, runner
commander-ci-oci-h2qr4-runner-bk7cx, node-tests success): the uploaded
node-tests JUnit carried no file attribute on any testcase, so all 1798
testcases collapsed into one row and no time could be attributed to a file.
The canonical node-tests job pins Node 22.23.2; the file attribute exists only
from the Node line that added it (nodejs/node#59432, f0aa073, 24.x). The same
canonical command locally on Node 24.22.1 produced 223 rows with real paths.

- test-timing-report: displayPath returns null instead of inventing
  "(unknown file)", so the JSON keeps the gap visible. Markdown still labels the
  row "(no file identity)", and rows without identity sort after real paths on
  equal time instead of displacing one.
- test-shard-plan: name that case explicitly instead of reporting a generic
  unsafe path, because the cause is the reporter's runtime, not bad input.
- docs/ci-test-timing.md: record the measurement, the required runtime, and why
  the canonical job must not be moved off its pinned version to obtain a
  corpus; a separate timing lane needs its own cost and admission decision.

Verified end to end against the real artifact: the re-extracted report now shows
"(no file identity)" and the planner exits 2 with the runtime message, writing
no output. Focused suites 20/20 pass; lint, lint:sync, graph check and
diff check pass. No weights were invented and no routing changed.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>

* fix(ci): collect native per-file timing on the pinned Node runtime

Observe test:summary events in the existing canonical execution and keep
native harness durations distinct from legacy JUnit testcase sums.
Reject incomplete evidence and preserve canonical test selection and routing.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>

* fix(ci): accept symlinked roots in the shard inventory guard

realpathSync(absolute) resolves symlinks across the whole path, but the
guard compared it against path.resolve(absolute), which only normalizes.
Under any symlinked root (macOS os.tmpdir(), a symlinked cwd handed to
test-timing-report) every file mismatched and the inventory threw
'unsafe canonical test file'. Compare against the real root instead so
the check still rejects symlinks inside the tree only.

* chore(graph): refresh generated outputs after the shard-plan guard fix

---------

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commit-queue-rebase PRs the Commit Queue should land as multiple self-contained commits. needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JUnit XML testcase element has no file attribute

6 participants