feat(cspell-junit-reporter): add JUnit XML reporter package - #8945
feat(cspell-junit-reporter): add JUnit XML reporter package#8945conorbronsdon wants to merge 4 commits into
Conversation
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>
There was a problem hiding this comment.
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.
|
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. |
Closes #4570.
Adds
@cspell/cspell-junit-reporter, a new workspace package modeled onpackages/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:
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, andfiles/exports/publishConfigshape are copied fromcspell-json-reporter. Version pinned to 10.0.1 to match the monorepo's locked versioning.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.erroremitter routed to a dedicatedcspell-errorstestsuite using<error>).Assumptions the issue thread left ambiguous, called out for review:
<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.<testcase name="no issues found">so a suite is never reported withtests="0", which some JUnit consumers treat as suspicious.cspell-json-reporter's (outFile,suiteNameonly). JUnit XML has no natural place for arbitrary debug/progress log dumps.<error>elements, distinct from spelling<failure>elements, per the JUnit failure-vs-error distinction.Verified locally:
tsc -bclean, vitest 32/32, eslint and prettier clean, and the full monorepobuild:prodsucceeds 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.