Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix reporters to handle string params
Documentation shows reporters as `reporters [array<moduleName | [moduleName, options]>]`, the code was incorrectly handling the following cases:

```
// no `string` moduleName
// _addCustomReporters(reporters: Array<ReporterConfig>)
reporters: ['default', 'someother']

// _shouldAddDefaultReporters(reporters?: Array<ReporterConfig>): boolean {
reporters: [['default', {}], 'someother']
```

This fix, use  the already existing `_getReporterProps` to compare `{path} === 'default'`.
  • Loading branch information
artola committed Aug 15, 2018
commit 257cc2f800e0711c84cfae75d4d10b6f27bd5223
16 changes: 7 additions & 9 deletions packages/jest-cli/src/TestScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,10 @@ export default class TestScheduler {
}
}

_shouldAddDefaultReporters(reporters?: Array<ReporterConfig>): boolean {
_shouldAddDefaultReporters(reporters?: Array<string | ReporterConfig>): boolean {
return (
!reporters ||
!!reporters.find(reporterConfig => reporterConfig[0] === 'default')
!!reporters.find(reporter => this._getReporterProps(reporter).path === 'default')
);
}

Expand Down Expand Up @@ -303,13 +303,11 @@ export default class TestScheduler {
this.addReporter(new SummaryReporter(this._globalConfig));
}

_addCustomReporters(reporters: Array<ReporterConfig>) {
const customReporters = reporters.filter(
reporterConfig => reporterConfig[0] !== 'default',
);

customReporters.forEach((reporter, index) => {
_addCustomReporters(reporters: Array<string | ReporterConfig>) {
reporters.forEach((reporter, index) => {
const {options, path} = this._getReporterProps(reporter);

if (path === 'default') return;

try {
// $FlowFixMe
Expand All @@ -331,7 +329,7 @@ export default class TestScheduler {
* to make dealing with them less painful.
*/
_getReporterProps(
reporter: ReporterConfig,
reporter: string | ReporterConfig,
): {path: string, options?: Object} {
if (typeof reporter === 'string') {
return {options: this._options, path: reporter};
Expand Down