Skip to content

Commit

Permalink
Merge pull request #96 from palmerj3/addConsoleSupportAgain
Browse files Browse the repository at this point in the history
Add console support when jest-junit is used as a reporter
  • Loading branch information
palmerj3 committed Jul 23, 2019
2 parents 057ceb8 + fa423a3 commit 911188f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@ const jestValidate = require('jest-validate');
const buildJsonResults = require('./utils/buildJsonResults');
const getOptions = require('./utils/getOptions');

// Store console results from onTestResult to later
// append to result
const consoleBuffer = {};

const processor = (report, reporterOptions = {}, jestRootDir = null) => {
// If jest-junit is used as a reporter allow for reporter options
// to be used. Env and package.json will override.
const options = getOptions.options(reporterOptions);

report.testResults.forEach((t, i) => {
t.console = consoleBuffer[t.testFilePath];
});

const jsonResults = buildJsonResults(report, fs.realpathSync(process.cwd()), options);

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

this.onTestResult = (test, testResult, aggregatedResult) => {
if (testResult.console && testResult.console.length > 0) {
consoleBuffer[testResult.testFilePath] = testResult.console;
}
};

this.onRunComplete = (contexts, results) => {
processor(results, this._options, this._globalConfig.rootDir);
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jest-junit",
"version": "6.4.0",
"version": "7.0.0",
"description": "A jest reporter that generates junit xml files",
"main": "index.js",
"repository": "https://github.com/jest-community/jest-junit",
Expand Down

0 comments on commit 911188f

Please sign in to comment.