Skip to content

Commit 6653fb8

Browse files
author
lalugeo
committed
* final output writing added with prolog
* new string constant and options added for prolog * README updated with new options
1 parent 8e3205f commit 6653fb8

File tree

4 files changed

+6209
-4
lines changed

4 files changed

+6209
-4
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ Reporter options should also be strings exception for suiteNameTemplate, classNa
6666
| `JEST_JUNIT_TITLE` | Template string for the `name` attribute of `<testcase>`. | `"{classname} {title}"` | `{classname}`, `{title}`, `{filepath}`, `{filename}`, `{displayName}`
6767
| `JEST_JUNIT_ANCESTOR_SEPARATOR` | Character(s) used to join the `describe` blocks. | `" "` | N/A
6868
| `JEST_USE_PATH_FOR_SUITE_NAME` | **DEPRECATED. Use `suiteNameTemplate` instead.** Use file path as the `name` attribute of `<testsuite>` | `"false"` | N/A
69+
| `JEST_JUNIT_INCLUDE_XML_PROLOG` | Determines if the XML output contains the Prolog | `"false"` | N/A
6970

7071

7172
You can configure these options via the command line as seen below:
@@ -86,7 +87,8 @@ Or you can also define a `jest-junit` key in your `package.json`. All are **str
8687
"classNameTemplate": "{classname}-{title}",
8788
"titleTemplate": "{classname}-{title}",
8889
"ancestorSeparator": " › ",
89-
"usePathForSuiteName": "true"
90+
"usePathForSuiteName": "true",
91+
"includeXmlProlog": "false"
9092
}
9193
}
9294
```

constants/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module.exports = {
1313
JEST_JUNIT_TITLE: 'titleTemplate',
1414
JEST_JUNIT_ANCESTOR_SEPARATOR: 'ancestorSeparator',
1515
JEST_USE_PATH_FOR_SUITE_NAME: 'usePathForSuiteName',
16+
JEST_JUNIT_INCLUDE_XML_PROLOG:'includeXmlProlog',
1617
},
1718
DEFAULT_OPTIONS: {
1819
suiteName: 'jest tests',
@@ -24,10 +25,12 @@ module.exports = {
2425
titleTemplate: '{classname} {title}',
2526
ancestorSeparator: ' ',
2627
usePathForSuiteName: 'false',
28+
includeXmlProlog: 'false',
2729
},
2830
CLASSNAME_VAR: 'classname',
2931
FILENAME_VAR: 'filename',
3032
FILEPATH_VAR: 'filepath',
3133
TITLE_VAR: 'title',
3234
DISPLAY_NAME_VAR: 'displayName',
33-
};
35+
XML_PROLOG_STRING: '<?xml version="1.0" encoding="UTF-8"?>',
36+
};

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const mkdirp = require('mkdirp');
55
const fs = require('fs');
66
const path = require('path');
77
const jestValidate = require('jest-validate');
8+
const constants = require('./constants');
89

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

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

3031
// Jest 18 compatibility
3132
return report;
@@ -70,4 +71,3 @@ function JestJUnit (globalConfig, options) {
7071
}
7172

7273
module.exports = JestJUnit;
73-

0 commit comments

Comments
 (0)