Skip to content

Commit

Permalink
static function refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
harshit-bs committed May 15, 2023
1 parent 25df503 commit 88801ac
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 25 deletions.
23 changes: 0 additions & 23 deletions lib/reporter/reporters/minimalJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,6 @@ const BaseReporter = require('../base-reporter.js');

class MinimalJsonReporter extends BaseReporter {

static isRerunFailedEnabled(argv = {}) {
return process.env.NIGHTWATCH_RERUN_FAILED === 'true' || argv['rerun-failed'];
}

static getRerunFailedFile(minimal_report_file_path) {
const jsonFile = path.resolve(process.env.NIGHTWATCH_RERUN_REPORT_FILE || minimal_report_file_path || '');

if (!Utils.fileExistsSync(jsonFile)) {
const err = new Error('Unable to find the Json reporter file to rerun failed tests');

err.showTrace = false;
err.detailedErr = 'Configure the environment variable NIGHTWATCH_RERUN_REPORT_FILE with Json reporter file path';
err.help = [
`Try setting ${Logger.colors.cyan('minimal_report_file_path: "JSON-REPORTER-PATH"')} in nightwatch configuration`,
`Or, try running: ${Logger.colors.cyan('export NIGHTWATCH_RERUN_REPORT_FILE="JSON-REPORTER-PATH"')}`
];

throw err;
}

return jsonFile;
}

adaptModule(module) {
// Pick only the necessary fields
const result = lodashPick(module, [
Expand Down
23 changes: 21 additions & 2 deletions lib/runner/test-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,28 @@ class TestSource {
return testsource;
}

getRerunFailedFile(minimal_report_file_path) {
const jsonFile = path.resolve(process.env.NIGHTWATCH_RERUN_REPORT_FILE || minimal_report_file_path || '');

if (!Utils.fileExistsSync(jsonFile)) {
const err = new Error('Unable to find the Json reporter file to rerun failed tests');

err.showTrace = false;
err.detailedErr = 'Configure the environment variable NIGHTWATCH_RERUN_REPORT_FILE with Json reporter file path';
err.help = [
`Try setting ${Logger.colors.cyan('minimal_report_file_path: "JSON-REPORTER-PATH"')} in nightwatch configuration`,
`Or, try running: ${Logger.colors.cyan('export NIGHTWATCH_RERUN_REPORT_FILE="JSON-REPORTER-PATH"')}`
];

throw err;
}

return jsonFile;
}

getTestSourceForRerunFailed() {
const {reporter_options: {minimal_report_file_path}} = this.settings;
const minimalJsonFile = MinimalJsonReporter.getRerunFailedFile(minimal_report_file_path);
const minimalJsonFile = this.getRerunFailedFile(minimal_report_file_path);

try {
const {modules = {}} = require(minimalJsonFile);
Expand Down Expand Up @@ -89,7 +108,7 @@ class TestSource {
* @returns {*}
*/
getSource() {
if (MinimalJsonReporter.isRerunFailedEnabled(this.argv) && Concurrency.isMasterProcess()) {
if ((process.env.NIGHTWATCH_RERUN_FAILED === 'true' || this.argv['rerun-failed']) && Concurrency.isMasterProcess()) {
return this.getTestSourceForRerunFailed(this.argv);
}

Expand Down

0 comments on commit 88801ac

Please sign in to comment.