{"id":13493523,"url":"https://github.com/jest-community/jest-junit","last_synced_at":"2025-05-14T15:06:11.205Z","repository":{"id":39759790,"uuid":"74174788","full_name":"jest-community/jest-junit","owner":"jest-community","description":"A Jest reporter that creates compatible junit xml files","archived":false,"fork":false,"pushed_at":"2024-12-09T03:44:00.000Z","size":612,"stargazers_count":494,"open_issues_count":27,"forks_count":115,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-05-11T22:19:03.779Z","etag":null,"topics":["javascript","jest","jest-junit","jest-testresultsprocessor","junit","nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jest-community.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-11-18T23:33:59.000Z","updated_at":"2025-04-22T07:59:35.000Z","dependencies_parsed_at":"2024-05-19T07:40:34.784Z","dependency_job_id":"f0393c8d-a0b5-418b-8a90-107860e7e385","html_url":"https://github.com/jest-community/jest-junit","commit_stats":{"total_commits":213,"total_committers":49,"mean_commits":4.346938775510204,"dds":0.5539906103286385,"last_synced_commit":"a8f75833a9fa0b6f42d6d9b3393cb8340d693b29"},"previous_names":[],"tags_count":53,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jest-community%2Fjest-junit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jest-community%2Fjest-junit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jest-community%2Fjest-junit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jest-community%2Fjest-junit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jest-community","download_url":"https://codeload.github.com/jest-community/jest-junit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254169034,"owners_count":22026207,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","jest","jest-junit","jest-testresultsprocessor","junit","nodejs"],"created_at":"2024-07-31T19:01:16.104Z","updated_at":"2025-05-14T15:06:11.176Z","avatar_url":"https://github.com/jest-community.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Packages"],"sub_categories":["Reporters"],"readme":"[![Actions Status](https://github.com/jest-community/jest-junit/actions/workflows/nodejs.yml/badge.svg?branch=master)](https://github.com/jest-community/jest-junit/actions)\n\n# jest-junit\nA Jest reporter that creates compatible junit xml files\n\nNote: as of jest-junit 11.0.0 NodeJS \u003e= 10.12.0 is required.\n\n## Installation\n```shell\nyarn add --dev jest-junit\n```\n\n## Usage\nIn your jest config add the following entry:\n```JSON\n{\n  \"reporters\": [ \"default\", \"jest-junit\" ]\n}\n```\n\nThen simply run:\n\n```shell\njest\n```\n\nFor your Continuous Integration you can simply do:\n```shell\njest --ci --reporters=default --reporters=jest-junit\n```\n\n## Usage as testResultsProcessor (deprecated)\nThe support for `testResultsProcessor` is only kept for [legacy reasons][test-results-processor] and might be removed in the future.\nYou should therefore prefer to configure `jest-junit` as a _reporter_.\n\nShould you still want to, add the following entry to your jest config:\n```JSON\n{\n  \"testResultsProcessor\": \"jest-junit\"\n}\n```\n\nThen simply run:\n\n```shell\njest\n```\n\nFor your Continuous Integration you can simply do:\n```shell\njest --ci --testResultsProcessor=\"jest-junit\"\n```\n\n## Configuration\n\n`jest-junit` offers several configurations based on environment variables or a `jest-junit` key defined in `package.json` or a reporter option.\nEnvironment variable and package.json configuration should be **strings**.\nReporter options should also be strings exception for suiteNameTemplate, classNameTemplate, titleNameTemplate that can also accept a function returning a string.\n\n| Environment Variable Name | Reporter Config Name| Description | Default | Possible Injection Values\n|---|---|---|---|---|\n| `JEST_SUITE_NAME` | `suiteName` | `name` attribute of `\u003ctestsuites\u003e` | `\"jest tests\"` | N/A\n| `JEST_JUNIT_OUTPUT_DIR` | `outputDirectory` | Directory to save the output. Relative path outside of project root (e.g. in monorepos) has to be prefixed with `\u003crootDir\u003e` literal, e.g. `\u003crootDir\u003e/../coverage` | `process.cwd()` | N/A\n| `JEST_JUNIT_OUTPUT_NAME` | `outputName` | File name for the output. | `\"junit.xml\"` | N/A\n| `JEST_JUNIT_OUTPUT_FILE` | `outputFile` | Fullpath for the output. If defined, `outputDirectory` and `outputName` will be overridden | `undefined` | N/A\n| `JEST_JUNIT_UNIQUE_OUTPUT_NAME` | `uniqueOutputName` | Create unique file name for the output leveraging the `outputName` as a prefix if given `${outputName}-${uuid}.xml` or a default of `junit.xml-${uuid}.xml` if `outputName` is not specified, overrides `outputName` | `false` | N/A\n| `JEST_JUNIT_SUITE_NAME` | `suiteNameTemplate` | Template string for `name` attribute of the `\u003ctestsuite\u003e`. | `\"{title}\"` | `{title}`, `{filepath}`, `{filename}`, `{displayName}`\n| `JEST_JUNIT_CLASSNAME` | `classNameTemplate` | Template string for the `classname` attribute of `\u003ctestcase\u003e`. | `\"{classname} {title}\"` | `{classname}`, `{title}`, `{suitename}`, `{filepath}`, `{filename}`, `{displayName}`\n| `JEST_JUNIT_TITLE` | `titleTemplate` | Template string for the `name` attribute of `\u003ctestcase\u003e`. | `\"{classname} {title}\"` | `{classname}`, `{title}`, `{filepath}`, `{filename}`, `{displayName}`\n| `JEST_JUNIT_ANCESTOR_SEPARATOR` | `ancestorSeparator` | Character(s) used to join the `describe` blocks. | `\" \"` | N/A\n| `JEST_JUNIT_ADD_FILE_ATTRIBUTE` | `addFileAttribute` | Add file attribute to the output (validated on CIRCLE CI and GitLab CI). Must be a string. | `\"false\"` | N/A\n| `JEST_JUNIT_FILE_PATH_PREFIX` | `filePathPrefix` | Prefix to add to the test suite file path. The value will be prefixed using `path.join`. Useful in case of monorepo | `\"\"` | N/A\n| `JEST_JUNIT_INCLUDE_CONSOLE_OUTPUT` | `includeConsoleOutput` | Adds console output to any testSuite that generates stdout during a test run. | `false` | N/A\n| `JEST_JUNIT_INCLUDE_SHORT_CONSOLE_OUTPUT` | `includeShortConsoleOutput` | Adds short console output (only message value) to any testSuite that generates stdout during a test run. | `false` | N/A\n| `JEST_JUNIT_REPORT_TEST_SUITE_ERRORS` | `reportTestSuiteErrors` | Reports test suites that failed to execute altogether as `error`. _Note:_ since the suite name cannot be determined from files that fail to load, it will default to file path.| `false` | N/A\n| `JEST_JUNIT_NO_STACK_TRACE` | `noStackTrace` | Omit stack traces from test failure reports, similar to `jest --noStackTrace` | `false` | N/A\n| `JEST_USE_PATH_FOR_SUITE_NAME` | `usePathForSuiteName` | **DEPRECATED. Use `suiteNameTemplate` instead.** Use file path as the `name` attribute of `\u003ctestsuite\u003e` | `\"false\"` | N/A\n| `JEST_JUNIT_TEST_CASE_PROPERTIES_JSON_FILE` | `testCasePropertiesFile` | Name of the custom testcase properties file | `\"junitProperties.js\"` | N/A\n| `JEST_JUNIT_TEST_CASE_PROPERTIES_DIR` | `testCasePropertiesDirectory` | Location of the custom testcase properties file | `process.cwd()` | N/A\n| `JEST_JUNIT_TEST_SUITE_PROPERTIES_JSON_FILE` | `testSuitePropertiesFile` | Name of the custom testsuite properties file | `\"junitTestCaseProperties.js\"` | N/A\n| `JEST_JUNIT_TEST_SUITE_PROPERTIES_DIR` | `testSuitePropertiesDirectory` | Location of the custom testsuite properties file | `process.cwd()` | N/A\n\n\nYou can configure these options via the command line as seen below:\n\n```shell\nJEST_SUITE_NAME=\"Jest JUnit Unit Tests\" JEST_JUNIT_OUTPUT_DIR=\"./artifacts\" jest\n```\n\nOr you can also define a `jest-junit` key in your `package.json`.  All are **string** values.\n\n```\n{\n  ...\n  \"jest-junit\": {\n    \"suiteName\": \"jest tests\",\n    \"outputDirectory\": \".\",\n    \"outputName\": \"junit.xml\",\n    \"uniqueOutputName\": \"false\",\n    \"classNameTemplate\": \"{classname}-{title}\",\n    \"titleTemplate\": \"{classname}-{title}\",\n    \"ancestorSeparator\": \" › \",\n    \"usePathForSuiteName\": \"true\"\n  }\n}\n```\n\nOr you can define your options in your reporter configuration.\n\n```js\n// jest.config.js\n{\n  reporters: [\n    \"default\",\n    [ \"jest-junit\", { suiteName: \"jest tests\" } ]\n  ]\n}\n```\n\n\n### Configuration Precedence\nIf using the `usePathForSuiteName` and `suiteNameTemplate`, the `usePathForSuiteName` value will take precedence. ie: if `usePathForSuiteName=true` and `suiteNameTemplate=\"{filename}\"`, the filepath will be used as the `name` attribute of the `\u003ctestsuite\u003e` in the rendered `jest-junit.xml`).\n\n### Examples\n\nBelow are some example configuration values and the rendered `.xml` to created by `jest-junit`.\n\nThe following test defined in the file `/__tests__/addition.test.js` will be used for all examples:\n```js\ndescribe('addition', () =\u003e {\n  describe('positive numbers', () =\u003e {\n    it('should add up', () =\u003e {\n      expect(1 + 2).toBe(3);\n    });\n  });\n});\n```\n\n#### Example 1\nThe default output:\n\n```xml\n\u003ctestsuites name=\"jest tests\"\u003e\n  \u003ctestsuite name=\"addition\" tests=\"1\" errors=\"0\" failures=\"0\" skipped=\"0\" timestamp=\"2017-07-13T09:42:28\" time=\"0.161\"\u003e\n    \u003ctestcase classname=\"addition positive numbers should add up\" name=\"addition positive numbers should add up\" time=\"0.004\"\u003e\n    \u003c/testcase\u003e\n  \u003c/testsuite\u003e\n\u003c/testsuites\u003e\n```\n\n#### Example 2\nUsing the `classNameTemplate` and `titleTemplate`:\n\n```shell\nJEST_JUNIT_CLASSNAME=\"{classname}\" JEST_JUNIT_TITLE=\"{title}\" jest\n```\n\nrenders\n\n```xml\n\u003ctestsuites name=\"jest tests\"\u003e\n  \u003ctestsuite name=\"addition\" tests=\"1\" errors=\"0\" failures=\"0\" skipped=\"0\" timestamp=\"2017-07-13T09:45:42\" time=\"0.154\"\u003e\n    \u003ctestcase classname=\"addition positive numbers\" name=\"should add up\" time=\"0.005\"\u003e\n    \u003c/testcase\u003e\n  \u003c/testsuite\u003e\n\u003c/testsuites\u003e\n```\n\n#### Example 3\nUsing the `ancestorSeparator`:\n\n```shell\nJEST_JUNIT_ANCESTOR_SEPARATOR=\" › \" jest\n```\nrenders\n\n```xml\n\u003ctestsuites name=\"jest tests\"\u003e\n  \u003ctestsuite name=\"addition\" tests=\"1\" errors=\"0\" failures=\"0\" skipped=\"0\" timestamp=\"2017-07-13T09:47:12\" time=\"0.162\"\u003e\n    \u003ctestcase classname=\"addition › positive numbers should add up\" name=\"addition › positive numbers should add up\" time=\"0.004\"\u003e\n    \u003c/testcase\u003e\n  \u003c/testsuite\u003e\n\u003c/testsuites\u003e\n```\n\n#### Example 4\nUsing the `suiteNameTemplate`:\n\n```shell\nJEST_JUNIT_SUITE_NAME =\"{filename}\" jest\n```\n\n```xml\n\u003ctestsuites name=\"jest tests\"\u003e\n  \u003ctestsuite name=\"addition.test.js\" tests=\"1\" errors=\"0\" failures=\"0\" skipped=\"0\" timestamp=\"2017-07-13T09:42:28\" time=\"0.161\"\u003e\n    \u003ctestcase classname=\"addition positive numbers should add up\" name=\"addition positive numbers should add up\" time=\"0.004\"\u003e\n    \u003c/testcase\u003e\n  \u003c/testsuite\u003e\n\u003c/testsuites\u003e\n```\n\n\n#### Example 5\nUsing `classNameTemplate` as a function in reporter options\n\n```js\n// jest.config.js\n{\n  reporters: [\n    \"default\",\n      [\n        \"jest-junit\",\n        {\n          classNameTemplate: (vars) =\u003e {\n            return vars.classname.toUpperCase();\n          }\n        }\n      ]\n  ]\n}\n```\n\nrenders\n\n```xml\n\u003ctestsuites name=\"jest tests\"\u003e\n  \u003ctestsuite name=\"addition\" tests=\"1\" errors=\"0\" failures=\"0\" skipped=\"0\" timestamp=\"2017-07-13T09:42:28\" time=\"0.161\"\u003e\n    \u003ctestcase classname=\"ADDITION POSITIVE NUMBERS\" name=\"addition positive numbers should add up\" time=\"0.004\"\u003e\n    \u003c/testcase\u003e\n  \u003c/testsuite\u003e\n\u003c/testsuites\u003e\n```\n\n#### Adding custom testsuite properties\nNew feature as of jest-junit 11.0.0!\n\nCreate a file in your project root directory named junitProperties.js:\n```js\nmodule.exports = () =\u003e {\n  return {\n    key: \"value\",\n  };\n};\n```\n\nWill render\n```xml\n\u003ctestsuites name=\"jest tests\"\u003e\n  \u003ctestsuite name=\"addition\" tests=\"1\" errors=\"0\" failures=\"0\" skipped=\"0\" timestamp=\"2017-07-13T09:42:28\" time=\"0.161\"\u003e\n    \u003cproperties\u003e\n      \u003cproperty name=\"key\" value=\"value\" /\u003e\n    \u003c/properties\u003e\n    \u003ctestcase classname=\"addition positive numbers should add up\" name=\"addition positive numbers should add up\" time=\"0.004\"\u003e\n    \u003c/testcase\u003e\n  \u003c/testsuite\u003e\n\u003c/testsuites\u003e\n```\n\n#### Adding custom testcase properties\n\nCreate a file in your project root directory named junitTestCaseProperties.js:\n```js\nmodule.exports = (testResult) =\u003e {\n  return {\n    \"dd_tags[test.invocations]\": testResult.invocations,\n  };\n};\n```\n\nWill render\n```xml\n\u003ctestsuites name=\"jest tests\"\u003e\n  \u003ctestsuite name=\"addition\" tests=\"1\" errors=\"0\" failures=\"0\" skipped=\"0\" timestamp=\"2017-07-13T09:42:28\" time=\"0.161\"\u003e\n    \u003ctestcase classname=\"addition positive numbers should add up\" name=\"addition positive numbers should add up\" time=\"0.004\"\u003e\n      \u003cproperties\u003e\n        \u003cproperty name=\"dd_tags[test.invocations]\" value=\"1\" /\u003e\n      \u003c/properties\u003e\n    \u003c/testcase\u003e\n  \u003c/testsuite\u003e\n\u003c/testsuites\u003e\n```\n\nWARNING: Properties for testcases is not following standard JUnit XML schema.\nHowever, other consumers may support properties for testcases like [DataDog metadata through `\u003cproperty\u003e` elements](https://docs.datadoghq.com/continuous_integration/tests/junit_upload/?tab=jenkins#providing-metadata-through-property-elements)\n\n[test-results-processor]: https://github.com/jest-community/jest-junit/discussions/158#discussioncomment-392985\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjest-community%2Fjest-junit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjest-community%2Fjest-junit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjest-community%2Fjest-junit/lists"}