Skip to content

Commit

Permalink
Clean up whitespace in reporter code
Browse files Browse the repository at this point in the history
  • Loading branch information
novemberborn committed Jun 14, 2020
1 parent 19c4f35 commit 27d2c6a
Showing 1 changed file with 19 additions and 89 deletions.
108 changes: 19 additions & 89 deletions lib/reporters/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,7 @@ class Reporter {
this.stdStream = stdStream;
this.watching = watching;
this.relativeFile = file => path.relative(projectDir, file);
this.consumeStateChange = whileCorked(
this.reportStream,
this.consumeStateChange
);
this.consumeStateChange = whileCorked(this.reportStream, this.consumeStateChange);

if (this.verbose) {
this.durationThreshold = durationThreshold || 100;
Expand All @@ -132,10 +129,7 @@ class Reporter {
stream: reportStream
});
this.lineWriter = new LineWriterWithSpinner(this.reportStream, this.spinner);
this.endRun = whileCorked(
this.reportStream,
whileCorked(this.lineWriter, this.endRun)
);
this.endRun = whileCorked(this.reportStream, whileCorked(this.lineWriter, this.endRun));
}

this.reset();
Expand Down Expand Up @@ -334,8 +328,7 @@ class Reporter {

if (this.verbose && !this.filesWithMissingAvaImports.has(event.testFile)) {
if (event.nonZeroExitCode) {
this.lineWriter.writeLine(colors.error(`${figures.cross} ${this.relativeFile(event.testFile)} exited with a non-zero exit code: ${event.nonZeroExitCode}`)
);
this.lineWriter.writeLine(colors.error(`${figures.cross} ${this.relativeFile(event.testFile)} exited with a non-zero exit code: ${event.nonZeroExitCode}`));
} else {
this.lineWriter.writeLine(colors.error(`${figures.cross} ${this.relativeFile(event.testFile)} exited due to ${event.signal}`));
}
Expand Down Expand Up @@ -443,55 +436,24 @@ class Reporter {
string += os.EOL;
}

let firstLinePostfix = this.watching ?
' ' +
chalk.gray.dim(
'[' + new Date().toLocaleTimeString('en-US', {hour12: false}) + ']'
) :
'';
let firstLinePostfix = this.watching ? ' ' + chalk.gray.dim('[' + new Date().toLocaleTimeString('en-US', {hour12: false}) + ']') : '';

if (this.stats.passedTests > 0) {
string +=
os.EOL +
colors.pass(`${this.stats.passedTests} passed`) +
firstLinePostfix;
string += os.EOL + colors.pass(`${this.stats.passedTests} passed`) + firstLinePostfix;
firstLinePostfix = '';
}

if (this.stats.passedKnownFailingTests > 0) {
string +=
os.EOL +
colors.error(
`${this.stats.passedKnownFailingTests} ${plur(
'known failure',
this.stats.passedKnownFailingTests
)}`
);
string += os.EOL + colors.error(`${this.stats.passedKnownFailingTests} ${plur('known failure', this.stats.passedKnownFailingTests)}`);
}

if (this.stats.failedHooks > 0) {
string +=
os.EOL +
colors.error(
`${this.stats.failedHooks} ${plur(
'hook',
this.stats.failedHooks
)} failed`
) +
firstLinePostfix;
string += os.EOL + colors.error(`${this.stats.failedHooks} ${plur('hook', this.stats.failedHooks)} failed`) + firstLinePostfix;
firstLinePostfix = '';
}

if (this.stats.failedTests > 0) {
string +=
os.EOL +
colors.error(
`${this.stats.failedTests} ${plur(
'test',
this.stats.failedTests
)} failed`
) +
firstLinePostfix;
string += os.EOL + colors.error(`${this.stats.failedTests} ${plur('test', this.stats.failedTests)} failed`) + firstLinePostfix;
firstLinePostfix = '';
}

Expand All @@ -507,21 +469,15 @@ class Reporter {
}

writeErr(event) {
if (
event.err.name === 'TSError' &&
event.err.object &&
event.err.object.diagnosticText
) {
if (event.err.name === 'TSError' && event.err.object && event.err.object.diagnosticText) {
this.lineWriter.writeLine(colors.errorStack(trimOffNewlines(event.err.object.diagnosticText)));
this.lineWriter.writeLine();
return;
}

if (event.err.source) {
this.lineWriter.writeLine(colors.errorSource(`${this.relativeFile(event.err.source.file)}:${event.err.source.line}`));
const excerpt = codeExcerpt(event.err.source, {
maxWidth: this.reportStream.columns - 2
});
const excerpt = codeExcerpt(event.err.source, {maxWidth: this.reportStream.columns - 2});
if (excerpt) {
this.lineWriter.writeLine();
this.lineWriter.writeLine(excerpt);
Expand Down Expand Up @@ -636,9 +592,7 @@ class Reporter {
}

endRun() {// eslint-disable-line complexity
let firstLinePostfix = this.watching ?
` ${chalk.gray.dim(`[${new Date().toLocaleTimeString('en-US', {hour12: false})}]`)}` :
'';
let firstLinePostfix = this.watching ? ` ${chalk.gray.dim(`[${new Date().toLocaleTimeString('en-US', {hour12: false})}]`)}` : '';
let wroteSomething = false;

if (!this.verbose) {
Expand Down Expand Up @@ -694,10 +648,7 @@ class Reporter {

if (this.filesWithoutMatchedLineNumbers.size > 0) {
for (const testFile of this.filesWithoutMatchedLineNumbers) {
if (
!this.filesWithMissingAvaImports.has(testFile) &&
!this.filesWithoutDeclaredTests.has(testFile)
) {
if (!this.filesWithMissingAvaImports.has(testFile) && !this.filesWithoutDeclaredTests.has(testFile)) {
this.lineWriter.writeLine(colors.error(`${figures.cross} Line numbers for ${this.relativeFile(testFile)} did not match any tests`) + firstLinePostfix);
firstLinePostfix = '';
wroteSomething = true;
Expand All @@ -714,10 +665,7 @@ class Reporter {
}

if (this.failures.length > 0) {
const writeTrailingLines =
this.internalErrors.length > 0 ||
this.uncaughtExceptions.length > 0 ||
this.unhandledRejections.length > 0;
const writeTrailingLines = this.internalErrors.length > 0 || this.uncaughtExceptions.length > 0 || this.unhandledRejections.length > 0;

const lastFailure = this.failures[this.failures.length - 1];
for (const event of this.failures) {
Expand All @@ -741,9 +689,7 @@ class Reporter {

if (!this.verbose) {
if (this.internalErrors.length > 0) {
const writeTrailingLines =
this.uncaughtExceptions.length > 0 ||
this.unhandledRejections.length > 0;
const writeTrailingLines = this.uncaughtExceptions.length > 0 || this.unhandledRejections.length > 0;

const last = this.internalErrors[this.internalErrors.length - 1];
for (const event of this.internalErrors) {
Expand All @@ -768,9 +714,7 @@ class Reporter {
if (this.uncaughtExceptions.length > 0) {
const writeTrailingLines = this.unhandledRejections.length > 0;

const last = this.uncaughtExceptions[
this.uncaughtExceptions.length - 1
];
const last = this.uncaughtExceptions[this.uncaughtExceptions.length - 1];
for (const event of this.uncaughtExceptions) {
this.lineWriter.writeLine(colors.title(`Uncaught exception in ${this.relativeFile(event.testFile)}`));
this.lineWriter.writeLine();
Expand All @@ -785,9 +729,7 @@ class Reporter {
}

if (this.unhandledRejections.length > 0) {
const last = this.unhandledRejections[
this.unhandledRejections.length - 1
];
const last = this.unhandledRejections[this.unhandledRejections.length - 1];
for (const event of this.unhandledRejections) {
this.lineWriter.writeLine(colors.title(`Unhandled rejection in ${this.relativeFile(event.testFile)}`));
this.lineWriter.writeLine();
Expand All @@ -807,30 +749,18 @@ class Reporter {
}
}

if (
this.failFastEnabled &&
(this.stats.remainingTests > 0 ||
this.stats.files > this.stats.finishedWorkers)
) {
if (this.failFastEnabled && (this.stats.remainingTests > 0 || this.stats.files > this.stats.finishedWorkers)) {
let remaining = '';
if (this.stats.remainingTests > 0) {
remaining += `At least ${this.stats.remainingTests} ${plur(
'test was',
'tests were',
this.stats.remainingTests
)} skipped`;
remaining += `At least ${this.stats.remainingTests} ${plur('test was', 'tests were', this.stats.remainingTests)} skipped`;
if (this.stats.files > this.stats.finishedWorkers) {
remaining += ', as well as ';
}
}

if (this.stats.files > this.stats.finishedWorkers) {
const skippedFileCount = this.stats.files - this.stats.finishedWorkers;
remaining += `${skippedFileCount} ${plur(
'test file',
'test files',
skippedFileCount
)}`;
remaining += `${skippedFileCount} ${plur('test file', 'test files', skippedFileCount)}`;
if (this.stats.remainingTests === 0) {
remaining += ` ${plur('was', 'were', skippedFileCount)} skipped`;
}
Expand Down

0 comments on commit 27d2c6a

Please sign in to comment.