Skip to content

Commit

Permalink
Add package.json config option
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Grimes committed Mar 16, 2017
1 parent ee919ed commit d57eaf0
Show file tree
Hide file tree
Showing 3 changed files with 22 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
11 changes: 7 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
'use strict';

const readPkg = require('read-pkg').sync;
const pkg = (readPkg(process.cwd()) || {})['jest-junit'] || {};

const xml = require('xml');
const mkdirp = require('mkdirp');
const fs = require('fs');
Expand All @@ -9,11 +12,11 @@ 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 SUITE_NAME = process.env.JEST_SUITE_NAME || pkg.suiteName || 'jest tests';
const OUTPUT_PATH = process.env.JEST_JUNIT_OUTPUT || pkg.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 || pkg.classNameTemplate || '{classname} {title}';
const TITLE_TEMPLATE = process.env.JEST_JUNIT_TITLE || pkg.titleTemplate || '{classname} {title}';

const replaceVars = function (str, classname, title) {
return str
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
],
"dependencies": {
"mkdirp": "^0.5.1",
"read-pkg": "^2.0.0",
"xml": "^1.0.1"
}
}

0 comments on commit d57eaf0

Please sign in to comment.