diff --git a/lib/reporter/index.js b/lib/reporter/index.js index 066c4dfc90..5ae14d97b9 100644 --- a/lib/reporter/index.js +++ b/lib/reporter/index.js @@ -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')); } @@ -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) || @@ -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); } @@ -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(); @@ -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)})`); } } @@ -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) { @@ -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`); diff --git a/lib/runner/concurrency/child-process.js b/lib/runner/concurrency/child-process.js index af4310331c..5b231ca6ca 100644 --- a/lib/runner/concurrency/child-process.js +++ b/lib/runner/concurrency/child-process.js @@ -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'); @@ -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) { @@ -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 + ' '; }); @@ -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]; @@ -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]])); @@ -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); diff --git a/lib/runner/concurrency/worker-task.js b/lib/runner/concurrency/worker-task.js index 31901906d1..427a99c641 100644 --- a/lib/runner/concurrency/worker-task.js +++ b/lib/runner/concurrency/worker-task.js @@ -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) { @@ -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'})); + } }); } } diff --git a/lib/settings/defaults.js b/lib/settings/defaults.js index 36adfbc733..d7aed546c0 100644 --- a/lib/settings/defaults.js +++ b/lib/settings/defaults.js @@ -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: '',