$ show jest-community/jest-junit
jest-junit is a Jest reporter that transforms test results into JUnit-compatible XML files, commonly used in CI/CD pipelines for integration with tools like Jenkins, CircleCI, and GitLab CI. The codebase is a small, focused Node.js library with a clear architecture: an entry point that supports both the modern reporter API and the deprecated testResultsProcessor, a configuration resolver that merges settings from environment variables, package.json, and reporter options, and a core transformation module (`buildJsonResults`) that converts Jest's aggregated result objects into a structured JSON representation directly mappable to JUnit XML via the `xml` package. It handles template variables for test suite names, class names, and test titles, supports custom properties via external JS files, and manages edge cases like test compilation errors, empty suites, console output inclusion, and retried tests. The code is well-tested with Jest and includes XML schema validation. While the library is not architecturally groundbreaking, it is cleanly modular, follows Node.js best practices, and its configuration and transformation patterns could be reused in other test report generators.
The LLM identified 2 files worth highlighting for reuse:
Core module that transforms Jest's test results report into a JSON structure for JUnit XML generation. It demonstrates a well-encapsulated transformation pattern: it takes a raw test report, options, and app directory, iterates over suites and test cases, applies template variable substitution (e.g., {filename}, {classname}) using a replaceVars helper that supports both string templates and functions, handles failure/error/skipped states, includes optional console output, and supports custom properties from external files. This module could be extracted and adapted for converting other test frameworks' results to JUnit-compatible XML with minimal changes.
Implements a layered configuration resolution system with clear precedence: reporter options < environment variables < package.json 'jest-junit' key < defaults. Includes a utility to traverse up directories to find the nearest package.json, making it suitable for monorepo setups. The pattern is cleanly abstracted into getEnvOptions, getAppOptions, and the main options() function, and is reusable in any Node.js library that needs to support multiple configuration sources with a well-defined override order.