Skip to content

feat(cspell-junit-reporter): add JUnit XML reporter package - #8945

Open
conorbronsdon wants to merge 4 commits into
streetsidesoftware:mainfrom
conorbronsdon:feat/cspell-junit-reporter
Open

feat(cspell-junit-reporter): add JUnit XML reporter package#8945
conorbronsdon wants to merge 4 commits into
streetsidesoftware:mainfrom
conorbronsdon:feat/cspell-junit-reporter

Conversation

@conorbronsdon

Copy link
Copy Markdown

Closes #4570.

Adds @cspell/cspell-junit-reporter, a new workspace package modeled on packages/cspell-json-reporter, that emits a JUnit-compatible XML report of a cspell run.

The issue asked for a minimal mapping along the lines of:

<testsuite tests="3">
  <testcase classname="File1" name"/>
  <testcase classname="File2" name="AnotherSuccessfulTest"/>
  <testcase classname="foo3" name="AFailingTest">
    <failure type="prohibited word"> zzz </failure>
  </testcase>
</testsuite>

This PR follows that shape but wraps it in a <testsuites> root and groups by file (one <testsuite> per file, suite name = file path), since that is the convention used by other widely-consumed JUnit reporters (for example ESLint's JUnit formatter) and is what most CI JUnit parsers expect. The package README documents the full mapping.

  • package.json, tsconfig.json, test framework, and files/exports/publishConfig shape are copied from cspell-json-reporter. Version pinned to 10.0.1 to match the monorepo's locked versioning.
  • No third-party XML library was added. The repo has no existing XML dependency, so a small escaping helper (src/utils/escapeXml.ts) and a pure XML-string builder (src/utils/buildJUnitXml.ts) were written in-repo, consistent with the monorepo's small-utility-file convention.
  • Unit tests (32) cover: no files, a clean file (single passing testcase), a file with issues, escaping of special characters in paths/words/messages, a skipped file, and non-issue processing errors (error emitter routed to a dedicated cspell-errors testsuite using <error>).

Assumptions the issue thread left ambiguous, called out for review:

  1. One <testsuite> per file rather than one flat suite for the whole run. Matches common JUnit reporter convention and keeps per-file counts meaningful in CI UIs.
  2. A clean file gets one synthetic passing <testcase name="no issues found"> so a suite is never reported with tests="0", which some JUnit consumers treat as suspicious.
  3. Settings are intentionally slimmer than cspell-json-reporter's (outFile, suiteName only). JUnit XML has no natural place for arbitrary debug/progress log dumps.
  4. cspell processing errors are reported as <error> elements, distinct from spelling <failure> elements, per the JUnit failure-vs-error distinction.

Verified locally: tsc -b clean, vitest 32/32, eslint and prettier clean, and the full monorepo build:prod succeeds with the package in the workspace. One environment note: the package's CLI smoke-test script wasn't runnable locally (repo requires Node >=22.18.0, local was 22.17.0 — the sibling json-reporter fails identically there), so CI is the first place it will run.

conorbronsdon and others added 2 commits July 7, 2026 21:14
Adds @cspell/cspell-junit-reporter, modeled on cspell-json-reporter,
which emits a JUnit-compatible XML report of a cspell run for CI
systems that consume the JUnit test result format.

Mapping: one <testsuites> root for the run, one <testsuite> per file
checked, one <testcase> per spelling issue (with a nested <failure>),
a single passing <testcase> for clean files, and a dedicated
cspell-errors testsuite using <error> for processing errors not tied
to a specific issue. All file paths, words, and messages are XML
escaped.

Closes streetsidesoftware#4570.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ing, use IssueType enum

Pre-submission review of streetsidesoftware#4570 found two issues:

- package.json shipped at 0.1.0 while every other publishable package
  in the monorepo (lerna fixed/locked versioning, per lerna.json) is
  pinned at 10.0.1. Align it so lerna publish doesn't choke on a
  mismatched starting version.
- buildJUnitXml.ts compared issue.issueType against the magic number 1
  instead of the IssueType.directive enum already exported by
  @cspell/cspell-types.

Re-ran build, vitest (32/32), eslint, and prettier for the package
after both fixes; all clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@conorbronsdon
conorbronsdon marked this pull request as ready for review July 8, 2026 06:50
@Jason3S
Jason3S requested a lite review from Copilot August 9, 2026 18:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new workspace package, @cspell/cspell-junit-reporter, which implements a CSpell reporter that emits JUnit-compatible XML for CI consumption. It follows the existing cspell-json-reporter package structure while adding in-repo XML escaping and XML string building utilities.

Changes:

  • Added a new reporter package (packages/cspell-junit-reporter) with JUnit XML output generation and settings validation.
  • Implemented XML escaping and JUnit XML document construction, plus unit tests and snapshots.
  • Wired the new workspace package into the monorepo via pnpm-lock.yaml.

Reviewed changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pnpm-lock.yaml Adds the new workspace importer entry for packages/cspell-junit-reporter.
packages/cspell-junit-reporter/package.json Defines the new package metadata, build/test scripts, and dependency on @cspell/cspell-types.
packages/cspell-junit-reporter/tsconfig.json Adds TS project references for the new package.
packages/cspell-junit-reporter/tsconfig.esm.json Configures ESM build output for the new reporter package.
packages/cspell-junit-reporter/README.md Documents installation, usage, settings, and JUnit XML mapping.
packages/cspell-junit-reporter/cSpell.example.mjs Provides a runnable example config for the package’s test:run smoke test.
packages/cspell-junit-reporter/src/index.ts Implements the reporter entry point: collects issues/progress/errors and writes XML to stdout/stderr/file.
packages/cspell-junit-reporter/src/index.test.ts Tests reporter output routing and basic grouping behavior (snapshotted).
packages/cspell-junit-reporter/src/snapshots/index.test.ts.snap Stores snapshots for reporter output in tests.
packages/cspell-junit-reporter/src/CSpellJUnitReporterSettings.ts Defines and documents the reporter’s settings shape.
packages/cspell-junit-reporter/src/utils/validateSettings.ts Validates settings at runtime and throws typed assertion errors.
packages/cspell-junit-reporter/src/utils/validateSettings.test.ts Unit tests for settings validation behavior.
packages/cspell-junit-reporter/src/utils/snapshots/validateSettings.test.ts.snap Snapshots for settings validation error cases.
packages/cspell-junit-reporter/src/utils/escapeXml.ts Adds XML escaping utilities for text and attribute contexts.
packages/cspell-junit-reporter/src/utils/escapeXml.test.ts Unit tests covering escaping behavior and invalid character stripping.
packages/cspell-junit-reporter/src/utils/buildJUnitXml.ts Builds the JUnit XML document and per-file/per-error testsuite elements.
packages/cspell-junit-reporter/src/utils/buildJUnitXml.test.ts Unit tests covering empty output, clean files, issues, escaping, skipped files, and processing errors.
Files not reviewed (1)
  • pnpm-lock.yaml: Generated file

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/cspell-junit-reporter/src/utils/escapeXml.ts Outdated
Comment thread packages/cspell-junit-reporter/src/utils/buildJUnitXml.ts Outdated
@conorbronsdon

Copy link
Copy Markdown
Author

Addressed both review comments in 8c78d3d: expanded control-character filtering and unified skipped-file JUnit counts, with regression coverage. All 33 reporter tests pass, along with formatting and the TypeScript build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide a Junit compliant reporter

3 participants