Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add outputDirectory and outputName; #62

Merged
merged 1 commit into from
Sep 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ jest --ci --testResultsProcessor="jest-junit"

## Configuration

`jest-junit` offers seven configurations based on environment variables or a `jest-junit` key defined in `package.json` or a reporter option.
`jest-junit` offers seven configurations based on environment variables or a `jest-junit` key defined in `package.json` or a reporter option.
Environement variable and package.json configuration should be **strings**.
Reporter options should also be strings exception for suiteNameTemplate, classNameTemplate, titleNameTemplate that can also accept a function returning a string.

| Variable Name | Description | Default | Possible Injection Values
|--|--|--|--|
| `JEST_SUITE_NAME` | `name` attribute of `<testsuites>` | `"jest tests"` | N/A
| `JEST_JUNIT_OUTPUT` | File path to save the output. | `"./junit.xml"` | N/A
| `JEST_JUNIT_OUTPUT_DIR` | Directory to save the output. | `null` | N/A
| `JEST_JUNIT_OUTPUT_NAME` | File name for the output. | `"./junit.xml"` | N/A
| `JEST_JUNIT_SUITE_NAME` | Template string for `name` attribute of the `<testsuite>`. | `"{title}"` | `{title}`, `{filepath}`, `{filename}`, `{displayName}`
| `JEST_JUNIT_CLASSNAME` | Template string for the `classname` attribute of `<testcase>`. | `"{classname} {title}"` | `{classname}`, `{title}`, `{filepath}`, `{filename}`, `{displayName}`
| `JEST_JUNIT_TITLE` | Template string for the `name` attribute of `<testcase>`. | `"{classname} {title}"` | `{classname}`, `{title}`, `{filepath}`, `{filename}`, `{displayName}`
Expand All @@ -79,7 +81,8 @@ Or you can also define a `jest-junit` key in your `package.json`. All are **str
...
"jest-junit": {
"suiteName": "jest tests",
"output": "./junit.xml",
"outputDirectory": ".",
"outputName": "./junit.xml",
"classNameTemplate": "{classname}-{title}",
"titleTemplate": "{classname}-{title}",
"ancestorSeparator": " › ",
Expand Down
4 changes: 4 additions & 0 deletions constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module.exports = {
ENVIRONMENT_CONFIG_MAP: {
JEST_SUITE_NAME: 'suiteName',
JEST_JUNIT_OUTPUT: 'output',
JEST_JUNIT_OUTPUT_DIR: 'outputDirectory',
JEST_JUNIT_OUTPUT_NAME: 'outputName',
JEST_JUNIT_CLASSNAME: 'classNameTemplate',
JEST_JUNIT_SUITE_NAME: 'suiteNameTemplate',
JEST_JUNIT_TITLE: 'titleTemplate',
Expand All @@ -15,6 +17,8 @@ module.exports = {
DEFAULT_OPTIONS: {
suiteName: 'jest tests',
output: path.join(process.cwd(), './junit.xml'),
outputDirectory: null,
outputName: 'junit.xml',
classNameTemplate: '{classname} {title}',
suiteNameTemplate: '{title}',
titleTemplate: '{classname} {title}',
Expand Down
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ const processor = (report, reporterOptions = {}) => {

const jsonResults = buildJsonResults(report, fs.realpathSync(process.cwd()), options);

// Set output to use new outputDirectory and fallback on original output
const output = options.outputDirectory === null ? options.output : path.join(options.outputDirectory, options.outputName);
// Ensure output path exists
mkdirp.sync(path.dirname(options.output));
mkdirp.sync(path.dirname(output));

// Write data to file
fs.writeFileSync(options.output, xml(jsonResults, { indent: ' '}));
fs.writeFileSync(output, xml(jsonResults, { indent: ' '}));

// Jest 18 compatibility
return report;
Expand Down