Skip to content

Commit

Permalink
Polish concurrent runner output. (jestjs#1813)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpojer authored Sep 28, 2016
1 parent e2ad210 commit fd6b124
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 45 deletions.
19 changes: 12 additions & 7 deletions packages/jest-cli/src/TestRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,6 @@ class TestRunner {
const estimatedTime =
Math.ceil(getEstimatedTime(timings, this._options.maxWorkers) / 1000);

this._dispatcher.onRunStart(
config,
aggregatedResults,
{estimatedTime},
);

const onTestResult = (testPath: Path, testResult: TestResult) => {
if (testResult.testResults.length === 0) {
const message = 'Your test suite must contain at least one test.';
Expand Down Expand Up @@ -242,8 +236,18 @@ class TestRunner {
)
);

const runInBand = shouldRunInBand();
this._dispatcher.onRunStart(
config,
aggregatedResults,
{
estimatedTime,
showStatus: !runInBand,
},
);

const testRun =
shouldRunInBand()
runInBand
? this._createInBandTestRun(testPaths, onTestResult, onRunFailure)
: this._createParallelTestRun(testPaths, onTestResult, onRunFailure);

Expand Down Expand Up @@ -334,6 +338,7 @@ class TestRunner {
const CoverageReporter = require('./reporters/CoverageReporter');
this.addReporter(new CoverageReporter());
}

this.addReporter(new SummaryReporter());
if (this._config.notify) {
this.addReporter(new NotifyReporter());
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-cli/src/jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ const runJest = (config, argv, pipe, onComplete) => {
}

localConsole.log(
source.getNoTestsFoundMessage(patternInfo, config, data) + '\n',
source.getNoTestsFoundMessage(patternInfo, config, data),
);
}
return data;
Expand Down
5 changes: 0 additions & 5 deletions packages/jest-cli/src/reporters/BaseReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import type {AggregatedResult, TestResult} from 'types/TestResult';
import type {Config, Path} from 'types/Config';
import type {ReporterOnStartOptions, RunnerContext} from 'types/Reporters';

const clearLine = require('jest-util').clearLine;
const preRunMessage = require('../preRunMessage');

class BaseReporter {
Expand Down Expand Up @@ -50,10 +49,6 @@ class BaseReporter {
runnerContext: RunnerContext,
): ?Promise<any> {}

clearLine() {
clearLine(process.stderr);
}

_setError(error: Error) {
this._error = error;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-cli/src/reporters/CoverageReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type CoverageMap = {|

const BaseReporter = require('./BaseReporter');

const {clearLine} = require('jest-util');
const {createReporter} = require('istanbul-api');
const chalk = require('chalk');
const fs = require('fs');
Expand Down Expand Up @@ -124,7 +125,7 @@ class CoverageReporter extends BaseReporter {
}
});
if (isInteractive) {
this.clearLine();
clearLine(process.stderr);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-cli/src/reporters/DefaultReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type {ReporterOnStartOptions, RunnerContext} from 'types/Reporters';
const BaseReporter = require('./BaseReporter');
const Status = require('./Status');

const {clearLine} = require('jest-util');
const chalk = require('chalk');
const getConsoleOutput = require('./getConsoleOutput');
const getResultHeader = require('./getResultHeader');
Expand Down Expand Up @@ -125,7 +126,7 @@ class DefaultReporter extends BaseReporter {
process.stdout.write = this._out;
// $FlowFixMe
process.stderr.write = this._err;
this.clearLine();
clearLine(process.stderr);
}

onTestResult(
Expand Down
20 changes: 13 additions & 7 deletions packages/jest-cli/src/reporters/Status.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ class Status {
_estimatedTime: number;
_height: number;
_interval: number;
_lastAggregatedResults: AggregatedResult;
_aggregatedResults: AggregatedResult;
_lastUpdated: number;
_showStatus: boolean;

constructor() {
this._cache = null;
Expand All @@ -78,6 +79,7 @@ class Status {
this._emitScheduled = false;
this._estimatedTime = 0;
this._height = 0;
this._showStatus = false;
}

onChange(callback: () => void) {
Expand All @@ -89,8 +91,9 @@ class Status {
options: ReporterOnStartOptions,
) {
this._estimatedTime = (options && options.estimatedTime) || 0;
this._showStatus = options && options.showStatus;
this._interval = setInterval(() => this._tick(), 1000);
this._lastAggregatedResults = aggregatedResults;
this._aggregatedResults = aggregatedResults;
this._debouncedEmit();
}

Expand All @@ -102,7 +105,11 @@ class Status {

testStarted(testPath: Path, config: Config) {
this._currentTests.add(testPath, config);
this._debouncedEmit();
if (!this._showStatus) {
this._emit();
} else {
this._debouncedEmit();
}
}

testFinished(
Expand All @@ -111,7 +118,7 @@ class Status {
aggregatedResults: AggregatedResult,
) {
const {testFilePath} = testResult;
this._lastAggregatedResults = aggregatedResults;
this._aggregatedResults = aggregatedResults;
this._currentTests.delete(testFilePath);
this._debouncedEmit();
}
Expand Down Expand Up @@ -143,9 +150,9 @@ class Status {
}
});

if (this._lastAggregatedResults) {
if (this._showStatus && this._aggregatedResults) {
content += '\n' + getSummary(
this._lastAggregatedResults,
this._aggregatedResults,
{
estimatedTime: this._estimatedTime,
roundTime: true,
Expand All @@ -154,7 +161,6 @@ class Status {
);
}

content += '\n';
let height = 0;

for (let i = 0; i < content.length; i++) {
Expand Down
47 changes: 24 additions & 23 deletions packages/jest-cli/src/reporters/SummaryReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,30 +79,31 @@ class SummareReporter extends BaseReporter {
aggregatedResults: AggregatedResult,
runnerContext: RunnerContext,
) {
const {testResults} = aggregatedResults;
const lastResult = testResults[testResults.length - 1];
// Print a newline if the last test did not fail to line up newlines if the
// test had failed.
if (
!config.verbose &&
lastResult &&
!lastResult.numFailingTests &&
!lastResult.testExecError
) {
this.log('');
}
if (aggregatedResults.numTotalTestSuites) {
const {testResults} = aggregatedResults;
const lastResult = testResults[testResults.length - 1];
// Print a newline if the last test did not fail to line up newlines
// similar to when an error would have been thrown in the test.
if (
!config.verbose &&
lastResult &&
!lastResult.numFailingTests &&
!lastResult.testExecError
) {
this.log('');
}

this._printSummary(aggregatedResults, config);
this._printSnapshotSummary(aggregatedResults.snapshot, config);

this._printSummary(aggregatedResults, config);
this._printSnapshotSummary(aggregatedResults.snapshot, config);
this.log(
(aggregatedResults.numTotalTestSuites
? getSummary(aggregatedResults, {
estimatedTime: this._estimatedTime,
})
: ''
) +
'\n' + runnerContext.getTestSummary(),
);
this.log(
aggregatedResults.numTotalTestSuites
? getSummary(aggregatedResults, {
estimatedTime: this._estimatedTime,
}) + '\n' + runnerContext.getTestSummary()
: '',
);
}
}

_printSnapshotSummary(snapshots: SnapshotSummary, config: Config) {
Expand Down
1 change: 1 addition & 0 deletions types/Reporters.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export type RunnerContext = {|

export type ReporterOnStartOptions = {|
estimatedTime: number,
showStatus: boolean,
|};

0 comments on commit fd6b124

Please sign in to comment.