Skip to content

Commit

Permalink
Fix nightwatchjs#3752 add setting to disable the output boxes for par…
Browse files Browse the repository at this point in the history
…allel runs using the boxen library (nightwatchjs#3758)
  • Loading branch information
swrdfish committed Jun 13, 2023
1 parent e4ede1f commit c3fc199
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 22 deletions.
22 changes: 11 additions & 11 deletions lib/reporter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Reporter extends SimplifiedReporter {
static printAssertions(testcase) {
testcase.assertions.forEach(function(a) {
if (a.failure !== false) {
let message = a.stackTrace.split('\n');
const message = a.stackTrace.split('\n');
message.unshift(a.fullMsg);
Utils.showStackTrace(message.join('\n'));
}
Expand Down Expand Up @@ -188,7 +188,7 @@ class Reporter extends SimplifiedReporter {
try {
let commandResult = result;

let isSuccess = result === undefined ||
const isSuccess = result === undefined ||
result == null || result.passed ||
!((result instanceof Error) ||
(result.error instanceof Error) ||
Expand Down Expand Up @@ -281,7 +281,7 @@ class Reporter extends SimplifiedReporter {
* Subtracts the number of passed assertions from the total assertions count
*/
resetCurrentTestPassedCount() {
let assertionsCount = this.testResults.currentTestResult.passed;
const assertionsCount = this.testResults.currentTestResult.passed;

this.testResults.subtractPassedCount(assertionsCount);
}
Expand All @@ -292,8 +292,8 @@ class Reporter extends SimplifiedReporter {
ok = true;
}

let elapsedTime = this.testResults.currentTestElapsedTime;
let currentTestResult = this.testResults.currentTestResult;
const elapsedTime = this.testResults.currentTestElapsedTime;
const currentTestResult = this.testResults.currentTestResult;

const Concurrency = require('../runner/concurrency');
const isWorker = Concurrency.isWorker();
Expand All @@ -310,7 +310,7 @@ class Reporter extends SimplifiedReporter {
Logger.logDetailedMessage(colors.green('No assertions ran.\n'), 'warn');
}
} else {
let failureMsg = this.getFailureMessage();
const failureMsg = this.getFailureMessage();
Logger.logDetailedMessage(`\n ${colors.red('FAILED:')} ${failureMsg} (${Utils.formatElapsedTime(elapsedTime, true)})`);
}
}
Expand All @@ -323,16 +323,16 @@ class Reporter extends SimplifiedReporter {
printSimplifiedTestResult(ok, elapsedTime, isWorker) {
const {currentTest} = this;

let result = [colors[ok ? 'green': 'red'](Utils.symbols[ok ? 'ok' : 'fail'])];
const result = [colors[ok ? 'green': 'red'](Utils.symbols[ok ? 'ok' : 'fail'])];
if (!this.unitTestsMode) {
if (isWorker) {
result.push(colors.white(process.env.__NIGHTWATCH_ENV, colors.background.black));
result.push(colors.white(this.settings.testEnv, colors.background.black));
}

result.push(colors.cyan('[' + this.suiteName + ']'));
}

let testName = currentTest.name;
const testName = currentTest.name;
result.push(ok ? testName : colors.red(testName));

if (elapsedTime > 20) {
Expand All @@ -355,8 +355,8 @@ class Reporter extends SimplifiedReporter {
}

getFailureMessage() {
let failureMsg = [];
let currentTestResult = this.testResults.currentTestResult;
const failureMsg = [];
const currentTestResult = this.testResults.currentTestResult;

if (currentTestResult.failed > 0){
failureMsg.push(`${colors.red(currentTestResult.failed)} assertions failed`);
Expand Down
23 changes: 15 additions & 8 deletions lib/runner/concurrency/child-process.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const child_process = require('child_process');
const EventEmitter = require('events');
const boxen = require('boxen');
const {Logger, isObject, symbols} = require('../../utils');
const ProcessListener = require('../../runner/process-listener.js');

Expand Down Expand Up @@ -80,7 +81,7 @@ class ChildProcess extends EventEmitter {
writeToStdout(data) {
data = data.toString().trim();

let color_pair = this.availColors[this.index%4];
const color_pair = this.availColors[this.index%4];
let output = '';

if (ChildProcess.prevIndex !== this.index) {
Expand All @@ -99,7 +100,7 @@ class ChildProcess extends EventEmitter {
this.env_label = Logger.colors[color_pair[1]](` ${this.environment} `, Logger.colors.background[color_pair[0]]);
}

let lines = data.split('\n').map(line => {
const lines = data.split('\n').map(line => {
return childProcessLabel + ' ' + line + ' ';
});

Expand All @@ -118,8 +119,8 @@ class ChildProcess extends EventEmitter {
run(colors, type) {
this.availColors = colors;

let cliArgs = this.getArgs();
let env = {};
const cliArgs = this.getArgs();
const env = {};

Object.keys(process.env).forEach(function(key) {
env[key] = process.env[key];
Expand Down Expand Up @@ -147,7 +148,7 @@ class ChildProcess extends EventEmitter {
}));
}

let color_pair = this.availColors[this.index%4];
const color_pair = this.availColors[this.index%4];

this.printLog(' Running: ' + Logger.colors[color_pair[1]](` ${this.env_itemKey} `, Logger.colors.background[color_pair[0]]));

Expand All @@ -168,9 +169,15 @@ class ChildProcess extends EventEmitter {
this.child.on('exit', code => {
this.printLog('');

let status = code > 0 ? symbols.fail : symbols.ok;
// eslint-disable-next-line no-console
console.log(`\n${status} ${this.env_label}`, this.env_output.join('\n'), '\n');
const status = code > 0 ? symbols.fail : symbols.ok;

if (this.settings.disable_output_boxes) {
// eslint-disable-next-line no-console
console.log(`\n${status} ${this.env_label}`, this.env_output.join('\n'), '\n');
} else {
// eslint-disable-next-line no-console
console.log(boxen(this.env_output.join('\n'), {title: `────────────────── ${status} ${this.env_label}`, padding: 1, borderColor: 'cyan'}));
}

code = code || this.processListener.exitCode;
resolve(code);
Expand Down
12 changes: 9 additions & 3 deletions lib/runner/concurrency/worker-task.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class WorkerTask extends EventEmitter {
this.argv = argv;
this.index = index;
this.task_label = '';
}
this.env_label = argv.env;
}

printLog(msg) {
if (this.settings.output) {
Expand Down Expand Up @@ -86,8 +87,13 @@ class WorkerTask extends EventEmitter {

return this.piscina.run({argv: this.argv, port1}, {transferList: [port1]})
.then(failures => {
// eslint-disable-next-line no-console
console.log(boxen(this.task_output.join('\n'), {title: `────────────────── ${failures ? symbols.fail : symbols.ok} ${this.task_label}`, padding: 1, borderColor: 'cyan'}));
if (this.settings.disable_output_boxes){
// eslint-disable-next-line no-console
console.log(`${failures ? symbols.fail : symbols.ok} ${this.task_label}\n`, this.task_output.join('\n'), '\n');
} else {
// eslint-disable-next-line no-console
console.log(boxen(this.task_output.join('\n'), {title: `────────────────── ${failures ? symbols.fail : symbols.ok} ${this.task_label}`, padding: 1, borderColor: 'cyan'}));
}
});
}
}
Expand Down
3 changes: 3 additions & 0 deletions lib/settings/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ module.exports = {
// Set this to true if you'd like to see timestamps next to the logging output
output_timestamp: false,

// Set this to true if you'd like to disable bounding boxes on terminal output. Useful when running in some CI environments.
disable_output_boxes: false,

// Set this to iso if you'd like to see timestamps as ISO strings
timestamp_format: '',

Expand Down

0 comments on commit c3fc199

Please sign in to comment.