Skip to content

Commit

Permalink
Merge pull request #9 from jsg2021/master
Browse files Browse the repository at this point in the history
Add package.json config option
  • Loading branch information
palmerj3 authored Mar 17, 2017
2 parents ee919ed + 766e382 commit 61ff401
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ Example:
JEST_SUITE_NAME="Jest JUnit Unit Tests" JEST_JUNIT_OUTPUT="./artifacts/junit.xml" jest
```

You can also define a 'jest-junit' key in your package.json.

```
{
...
"jest-junit": {
"suiteName": "jest tests",
"output": "./junit.xml",
"classNameTemplate": "{classname}-{title}",
"titleTemplate": "{classname}-{title}"
}
}
```

Example output:
```xml
<testsuites name="Jest JUnit Unit Tests">
Expand Down
18 changes: 14 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,21 @@ const path = require('path');
const CLASSNAME_VAR = '{classname}';
const TITLE_VAR = '{title}';

const SUITE_NAME = process.env.JEST_SUITE_NAME || 'jest tests';
const OUTPUT_PATH = process.env.JEST_JUNIT_OUTPUT ||
const cfg = {};
try {
const config = (require(path.join(process.cwd(), 'package.json')) || {})['jest-junit'];
if (config) {
Object.assign(cfg, config);
}
} catch (e) {
//don't blowup if there was an error...just skip
}

const SUITE_NAME = process.env.JEST_SUITE_NAME || cfg.suiteName || 'jest tests';
const OUTPUT_PATH = process.env.JEST_JUNIT_OUTPUT || cfg.output ||
path.join(process.cwd(), './junit.xml');
const CLASSNAME_TEMPLATE = process.env.JEST_JUNIT_CLASSNAME || '{classname} {title}';
const TITLE_TEMPLATE = process.env.JEST_JUNIT_TITLE || '{classname} {title}';
const CLASSNAME_TEMPLATE = process.env.JEST_JUNIT_CLASSNAME || cfg.classNameTemplate || '{classname} {title}';
const TITLE_TEMPLATE = process.env.JEST_JUNIT_TITLE || cfg.titleTemplate || '{classname} {title}';

const replaceVars = function (str, classname, title) {
return str
Expand Down

0 comments on commit 61ff401

Please sign in to comment.