Skip to content

Commit

Permalink
added support to pass --report-filename for json reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
beatfactor committed Sep 8, 2022
1 parent f7db1a9 commit d73a6fd
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/reporter/global-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ module.exports = class GlobalReporter {
};
}

constructor(reporter = DefaultSettings.default_reporter, settings, openReport = false) {
constructor(reporter = DefaultSettings.default_reporter, settings, {openReport = false, reportFileName = null} = {}) {
this.suiteResults = [];
this.skippedSuites = 0;
this.uncaughtErr = null;
this.reporterFile = reporter;
this.reportFileName = reportFileName;

if (!Array.isArray(this.reporterFile)) {
this.reporterFile = [reporter];
Expand Down Expand Up @@ -189,6 +190,7 @@ module.exports = class GlobalReporter {
const needsCallback = reporter.write.length === 3;
const options = {
filename_prefix: this.settings.report_prefix,
report_filename: this.reportFileName,
output_folder,
globals,
start_session,
Expand Down
3 changes: 2 additions & 1 deletion lib/reporter/reporters/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {Logger} = Utils;
const BaseReporter = require('../base-reporter.js');

class JsonReporter extends BaseReporter {

writeReport(moduleKey, data = {}) {
const module = this.results.modules[moduleKey];
const pathParts = moduleKey.split(path.sep);
Expand All @@ -20,7 +21,7 @@ class JsonReporter extends BaseReporter {
shouldCreateFolder = true;
}

const filename = path.join(output_folder, `${module.reportPrefix}${moduleName}.json`);
const filename = this.options.report_filename || path.join(output_folder, `${module.reportPrefix}${moduleName}.json`);

const httpOutput = Logger.getOutput().map(item => {
return [item[0], stripAnsi(item[1]), item[2] || ''];
Expand Down
5 changes: 4 additions & 1 deletion lib/runner/test-runners/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ class DefaultRunner {
this.argv = argv;
this.addtOpts = addtOpts;
this.publishReport = true; // in-case of an uncaught exception, the report will not be published
this.globalReporter = new GlobalReporter(argv.reporter, settings, argv.open);
this.globalReporter = new GlobalReporter(argv.reporter, settings, {
open: argv.open,
reportFileName: argv['report-filename']
});
}

get client() {
Expand Down
1 change: 1 addition & 0 deletions lib/testsuite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ class TestSuite {
moduleKey,
modulePath,
reportPrefix: '',
reportFileName: this.argv['report-filename'],
groupName
}
});
Expand Down

0 comments on commit d73a6fd

Please sign in to comment.