Skip to content

Commit

Permalink
* final output writing added with prolog
Browse files Browse the repository at this point in the history
* new string constant and options added for prolog
* README updated with new options
  • Loading branch information
lalugeo committed Jan 10, 2019
1 parent 8e3205f commit 6653fb8
Show file tree
Hide file tree
Showing 4 changed files with 6,209 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Reporter options should also be strings exception for suiteNameTemplate, classNa
| `JEST_JUNIT_TITLE` | Template string for the `name` attribute of `<testcase>`. | `"{classname} {title}"` | `{classname}`, `{title}`, `{filepath}`, `{filename}`, `{displayName}`
| `JEST_JUNIT_ANCESTOR_SEPARATOR` | Character(s) used to join the `describe` blocks. | `" "` | N/A
| `JEST_USE_PATH_FOR_SUITE_NAME` | **DEPRECATED. Use `suiteNameTemplate` instead.** Use file path as the `name` attribute of `<testsuite>` | `"false"` | N/A
| `JEST_JUNIT_INCLUDE_XML_PROLOG` | Determines if the XML output contains the Prolog | `"false"` | N/A


You can configure these options via the command line as seen below:
Expand All @@ -86,7 +87,8 @@ Or you can also define a `jest-junit` key in your `package.json`. All are **str
"classNameTemplate": "{classname}-{title}",
"titleTemplate": "{classname}-{title}",
"ancestorSeparator": " › ",
"usePathForSuiteName": "true"
"usePathForSuiteName": "true",
"includeXmlProlog": "false"
}
}
```
Expand Down
5 changes: 4 additions & 1 deletion constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = {
JEST_JUNIT_TITLE: 'titleTemplate',
JEST_JUNIT_ANCESTOR_SEPARATOR: 'ancestorSeparator',
JEST_USE_PATH_FOR_SUITE_NAME: 'usePathForSuiteName',
JEST_JUNIT_INCLUDE_XML_PROLOG:'includeXmlProlog',
},
DEFAULT_OPTIONS: {
suiteName: 'jest tests',
Expand All @@ -24,10 +25,12 @@ module.exports = {
titleTemplate: '{classname} {title}',
ancestorSeparator: ' ',
usePathForSuiteName: 'false',
includeXmlProlog: 'false',
},
CLASSNAME_VAR: 'classname',
FILENAME_VAR: 'filename',
FILEPATH_VAR: 'filepath',
TITLE_VAR: 'title',
DISPLAY_NAME_VAR: 'displayName',
};
XML_PROLOG_STRING: '<?xml version="1.0" encoding="UTF-8"?>',
};
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const mkdirp = require('mkdirp');
const fs = require('fs');
const path = require('path');
const jestValidate = require('jest-validate');
const constants = require('./constants');

const buildJsonResults = require('./utils/buildJsonResults');
const getOptions = require('./utils/getOptions');
Expand All @@ -25,7 +26,7 @@ const processor = (report, reporterOptions = {}, jestRootDir = null) => {
mkdirp.sync(path.dirname(finalOutput));

// Write data to file
fs.writeFileSync(finalOutput, xml(jsonResults, { indent: ' ' }));
fs.writeFileSync(finalOutput,(constants.XML_PROLOG === 'true')? constants.XML_PROLOG_STRING : '' + xml(jsonResults, { indent: ' ' }));

// Jest 18 compatibility
return report;
Expand Down Expand Up @@ -70,4 +71,3 @@ function JestJUnit (globalConfig, options) {
}

module.exports = JestJUnit;

Loading

0 comments on commit 6653fb8

Please sign in to comment.