Skip to content

Commit 911188f

Browse files
authored
Merge pull request #96 from palmerj3/addConsoleSupportAgain
Add console support when jest-junit is used as a reporter
2 parents 057ceb8 + fa423a3 commit 911188f

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,19 @@ const jestValidate = require('jest-validate');
99
const buildJsonResults = require('./utils/buildJsonResults');
1010
const getOptions = require('./utils/getOptions');
1111

12+
// Store console results from onTestResult to later
13+
// append to result
14+
const consoleBuffer = {};
15+
1216
const processor = (report, reporterOptions = {}, jestRootDir = null) => {
1317
// If jest-junit is used as a reporter allow for reporter options
1418
// to be used. Env and package.json will override.
1519
const options = getOptions.options(reporterOptions);
1620

21+
report.testResults.forEach((t, i) => {
22+
t.console = consoleBuffer[t.testFilePath];
23+
});
24+
1725
const jsonResults = buildJsonResults(report, fs.realpathSync(process.cwd()), options);
1826

1927
// Set output to use new outputDirectory and fallback on original output
@@ -64,6 +72,12 @@ function JestJUnit (globalConfig, options) {
6472
this._globalConfig = globalConfig;
6573
this._options = options;
6674

75+
this.onTestResult = (test, testResult, aggregatedResult) => {
76+
if (testResult.console && testResult.console.length > 0) {
77+
consoleBuffer[testResult.testFilePath] = testResult.console;
78+
}
79+
};
80+
6781
this.onRunComplete = (contexts, results) => {
6882
processor(results, this._options, this._globalConfig.rootDir);
6983
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jest-junit",
3-
"version": "6.4.0",
3+
"version": "7.0.0",
44
"description": "A jest reporter that generates junit xml files",
55
"main": "index.js",
66
"repository": "https://github.com/jest-community/jest-junit",

0 commit comments

Comments
 (0)