{"id":12263,"library":"typescript-xunit-xml","title":"TypeScript xUnit XML Reporter","description":"The `typescript-xunit-xml` package provides a command-line interface and a programmatic API for converting the diagnostic output of the TypeScript compiler (`tsc`) into an xUnit-style XML format. This conversion is highly beneficial for integrating TypeScript build processes with continuous integration (CI) systems like Jenkins, GitLab CI, or Azure DevOps, allowing them to interpret compilation errors and warnings as test failures. The package is currently at version 1.2.0, with its last publish occurring approximately three years ago, suggesting a maintenance rather than active development cadence. Its primary differentiator lies in its focused design specifically for `tsc` output, offering a streamlined solution for reporting TypeScript-specific issues without requiring broader testing frameworks. While it functions effectively as a CLI tool via pipe operations, it also exposes `parse` and `format` functions for direct programmatic use within Node.js applications, enabling more custom integration scenarios.","status":"maintenance","version":"1.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/glenjamin/typescript-xunit-xml","tags":["javascript","typescript","xunit","junit","xml"],"install":[{"cmd":"npm install typescript-xunit-xml","lang":"bash","label":"npm"},{"cmd":"yarn add typescript-xunit-xml","lang":"bash","label":"yarn"},{"cmd":"pnpm add typescript-xunit-xml","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Imports the `parse` function to convert raw TypeScript compiler output strings into structured message objects. This is a named export.","wrong":"import parse from 'typescript-xunit-xml';","symbol":"parse","correct":"import { parse } from 'typescript-xunit-xml';"},{"note":"Imports the `format` function to serialize an array of message objects into a well-formed xUnit XML string. This is a named export.","wrong":"import format from 'typescript-xunit-xml';","symbol":"format","correct":"import { format } from 'typescript-xunit-xml';"},{"note":"CommonJS pattern to destructure both `parse` and `format` functions from the module's exports object. Directly requiring the module's main file is common for programmatic access.","wrong":"const converter = require('typescript-xunit-xml'); // Then access converter.parse, converter.format","symbol":"{ parse, format } (CommonJS)","correct":"const { parse, format } = require('typescript-xunit-xml');"}],"quickstart":{"code":"import { readFileSync, writeFileSync } from 'fs';\nimport { spawnSync } from 'child_process';\nimport { parse, format } from 'typescript-xunit-xml'; // Programmatic API\n\nconst tsConfigFile = 'tsconfig.json';\nconst tsCodeFile = 'src/index.ts';\n\n// Ensure src directory exists and create dummy files for demonstration\nif (!require('fs').existsSync('src')) require('fs').mkdirSync('src');\nwriteFileSync(tsCodeFile, `\nfunction greet(name: string): string {\n    return \\`Hello, \\${name}!\\`;\n}\nconst x: number = 'hello'; // Intentionally cause a type error for the demo\nconsole.log(greet(\"World\"));\n`);\nwriteFileSync(tsConfigFile, `\n{\n  \"compilerOptions\": {\n    \"target\": \"es2016\", \"module\": \"commonjs\", \"strict\": true,\n    \"esModuleInterop\": true, \"skipLibCheck\": true,\n    \"forceConsistentCasingInFileNames\": true, \"noEmit\": true\n  },\n  \"include\": [\"src/**/*.ts\"]\n}\n`);\n\nconsole.log(\"Running tsc and piping output to typescript-xunit-xml...\");\n// Simulate the CLI usage: tsc --project . --noEmit | typescript-xunit-xml\n// The --noEmit flag is crucial for tsc to output diagnostics to stdout/stderr instead of compiling files.\nconst tscProcess = spawnSync('tsc', ['--project', '.', '--noEmit'], { encoding: 'utf8' });\n\nif (tscProcess.status !== 0) {\n    console.warn(\"TypeScript compilation errors detected (expected for this demo).\");\n} else {\n    console.log(\"No TypeScript errors. Outputting empty xUnit XML.\");\n}\n\n// tsc often sends errors to stderr, so check both\nconst tscOutput = (tscProcess.stderr || tscProcess.stdout).toString();\n\n// Use the programmatic API to process the output\nconst parsedMessages = parse(tscOutput);\nconst xunitXml = format(parsedMessages);\n\nwriteFileSync('junit.xml', xunitXml);\nconsole.log(\"Generated junit.xml with xUnit report (check 'junit.xml' for content):\");\n// console.log(xunitXml); // Uncomment to see the XML directly in console\n\n// Clean up dummy files\ntry {\n  require('fs').unlinkSync(tsCodeFile);\n  require('fs').unlinkSync(tsConfigFile);\n  require('fs').rmdirSync('src');\n  console.log(\"Cleaned up dummy files.\");\n} catch (e) {\n  console.error(\"Cleanup failed:\", e.message);\n}\n","lang":"typescript","description":"Demonstrates programmatic usage of `typescript-xunit-xml` to process TypeScript compiler output from a dummy project and generate an xUnit XML report, simulating typical CI/CD integration."},"warnings":[{"fix":"Monitor for updates to `typescript-xunit-xml` when upgrading major TypeScript compiler versions. If issues arise, consider contributing a fix or using an alternative reporter.","message":"The package relies on parsing the standard output format of the TypeScript compiler (tsc). Any future breaking changes to tsc's diagnostic output format could lead to incorrect parsing or runtime errors within `typescript-xunit-xml`.","severity":"breaking","affected_versions":">=1.2.0"},{"fix":"Ensure `tsc` is invoked without the `--pretty` flag when its output is piped to `typescript-xunit-xml`. The roadmap indicates future support, but it's not present in v1.2.0.","message":"Currently, `typescript-xunit-xml` does not support parsing `--pretty` output from the TypeScript compiler. Using `--pretty` will result in malformed or incomplete XML reports.","severity":"gotcha","affected_versions":">=1.2.0"},{"fix":"Ensure `tsc` output is pristine. Use direct piping (`|`) and avoid intermediate tools that might reformat text. In Node.js, capture `stderr` and `stdout` directly from `child_process` as demonstrated in the quickstart.","message":"When running `tsc` in environments that buffer stdout/stderr or modify output (e.g., some CI runners, IDE integrations), the raw output might be altered before reaching `typescript-xunit-xml`, leading to parsing failures.","severity":"gotcha","affected_versions":">=1.2.0"},{"fix":"Understand how your CI system interprets xUnit 'skipped' vs. 'failed' test cases. Adjust build failure criteria in your CI pipeline if you wish warnings to cause a hard build break.","message":"TypeScript compiler warnings are typically reported by `typescript-xunit-xml` as 'skipped' tests in the xUnit report, while errors are reported as 'failures'. This distinction is important for CI systems that differentiate between these states.","severity":"gotcha","affected_versions":">=1.2.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Install the package globally (`npm install -g typescript-xunit-xml`), or use `npx typescript-xunit-xml`, or ensure `node_modules/.bin` is in your PATH in shell scripts.","cause":"The `typescript-xunit-xml` CLI tool is not found in the system's PATH or within `node_modules/.bin`.","error":"'typescript-xunit-xml' is not recognized as an internal or external command, operable program or batch file."},{"fix":"Install TypeScript globally (`npm install -g typescript`) or ensure `tsc` is available in your project's `node_modules/.bin` (e.g., by adding `\"scripts\": { \"test\": \"tsc && ...\" }` to `package.json` and running `npm test`).","cause":"The TypeScript compiler (`tsc`) is not installed globally or is not accessible in the execution environment's PATH.","error":"tsc: The term 'tsc' is not recognized as the name of a cmdlet, function, script file, or operable program."},{"fix":"Ensure `tsc` is run without the `--pretty` flag and that no other tools are altering its `stdout` or `stderr` before it reaches `typescript-xunit-xml`.","cause":"The input provided to `typescript-xunit-xml` (via pipe or programmatic `parse` function) is not in the expected format of standard TypeScript compiler diagnostics, likely due to a `--pretty` flag or other output modifications.","error":"Error: Invalid TS diagnostics output. Expected format..."}],"ecosystem":"npm"}