Skip to content

Commit

Permalink
Fix custom reporter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronabramov committed Jun 19, 2017
1 parent 66864bd commit 3701b13
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ Object {
"christoph": "pojer",
"dmitrii": "abramov",
"hello": "world",
"maxWorkers": "<<REPLACED>>",
"pattern": Object {
"input": "add-fail-test.js",
"paths": Array [
"add-fail-test.js",
],
"shouldTreatInputAsPattern": false,
"testPathPattern": "add-fail-test.js",
},
"testPathPattern": "\\"add-fail-test.js\\"",
},
}
`;
Expand Down Expand Up @@ -60,6 +70,16 @@ Object {
"christoph": "pojer",
"dmitrii": "abramov",
"hello": "world",
"maxWorkers": "<<REPLACED>>",
"pattern": Object {
"input": "add-test.js",
"paths": Array [
"add-test.js",
],
"shouldTreatInputAsPattern": false,
"testPathPattern": "add-test.js",
},
"testPathPattern": "\\"add-test.js\\"",
},
}
`;
Expand Down Expand Up @@ -101,7 +121,18 @@ Object {
"called": true,
"path": false,
},
"options": Object {},
"options": Object {
"maxWorkers": "<<REPLACED>>",
"pattern": Object {
"input": "add-test.js",
"paths": Array [
"add-test.js",
],
"shouldTreatInputAsPattern": false,
"testPathPattern": "add-test.js",
},
"testPathPattern": "\\"add-test.js\\"",
},
}
`;
Expand Down
4 changes: 4 additions & 0 deletions integration_tests/custom_reporters/reporters/TestReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ class TestReporter {
onRunComplete.numFailedTests = results.numFailedTests;
onRunComplete.numTotalTests = results.numTotalTests;

if (this._statsCollected.options.maxWorkers) {
// Since it's a different number on different machines.
this._statsCollected.options.maxWorkers = '<<REPLACED>>';
}
// The Final Call
process.stdout.write(JSON.stringify(this._statsCollected, null, 4));
}
Expand Down
14 changes: 3 additions & 11 deletions packages/jest-cli/src/TestRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,7 @@ class TestRunner {
: new DefaultReporter(this._globalConfig),
);

this.addReporter(
new SummaryReporter(this._globalConfig, {
pattern: this._options.pattern,
testNamePattern: this._options.testNamePattern,
testPathPattern: this._options.testPathPattern,
}),
);
this.addReporter(new SummaryReporter(this._globalConfig, this._options));
}

_addCustomReporters(reporters: Array<ReporterConfig>) {
Expand Down Expand Up @@ -356,10 +350,8 @@ class TestRunner {
if (typeof reporter === 'string') {
return {options: this._options, path: reporter};
} else if (Array.isArray(reporter)) {
const [path] = reporter;
let [, options] = reporter;
options = Object.assign({}, this._options, options);
return {options, path};
const [path, options] = reporter;
return {options: Object.assign({}, this._options, options), path};
}

throw new Error('Reporter should be either a string or an array');
Expand Down
11 changes: 3 additions & 8 deletions packages/jest-cli/src/reporters/SummaryReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ import type {GlobalConfig} from 'types/Config';
import type {Context} from 'types/Context';
import type {ReporterOnStartOptions} from 'types/Reporters';
import type {PathPattern} from '../SearchSource';

type SummaryReporterOptions = {|
pattern: PathPattern,
testNamePattern: string,
testPathPattern: string,
|};
import type {TestRunnerOptions} from '../TestRunner';

import chalk from 'chalk';
import BaseReporter from './BaseReporter';
Expand Down Expand Up @@ -64,9 +59,9 @@ const NPM_EVENTS = new Set([
class SummaryReporter extends BaseReporter {
_estimatedTime: number;
_globalConfig: GlobalConfig;
_options: SummaryReporterOptions;
_options: TestRunnerOptions;

constructor(globalConfig: GlobalConfig, options: SummaryReporterOptions) {
constructor(globalConfig: GlobalConfig, options: TestRunnerOptions) {
super();
this._globalConfig = globalConfig;
this._estimatedTime = 0;
Expand Down

0 comments on commit 3701b13

Please sign in to comment.