Skip to content

Commit

Permalink
fix(jest): change reporters option to array type
Browse files Browse the repository at this point in the history
Jest expects the reporters option to be an array of strings.
  • Loading branch information
Sven Röttering authored and vsavkin committed Aug 6, 2019
1 parent b892c1e commit ec9ed17
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
8 changes: 7 additions & 1 deletion docs/api-jest/builders/jest.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ Type: `boolean`

Forces test results output highlighting even if stdout is not a TTY. (https://jestjs.io/docs/en/cli#colors)

### config

Type: `string`

The path to a Jest config file specifying how to find and execute tests. If no rootDir is set in the config, the directory containing the config file is assumed to be the rootDir for the project. This can also be a JSON-encoded value which Jest will use as configuration

### coverage

Type: `boolean`
Expand Down Expand Up @@ -110,7 +116,7 @@ Will not fail if no tests are found (for example while using `--testPathPattern`

### reporters

Type: `string`
Type: `array`

Run tests with specified reporters. Reporter options are not available via CLI. Example with multiple reporters: jest --reporters="default" --reporters="jest-junit" (https://jestjs.io/docs/en/cli#reporters)

Expand Down
13 changes: 8 additions & 5 deletions packages/jest/src/builders/jest/jest.impl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ describe('Jest Builder', () => {
]
}
}),
watch: false
watch: false,
reporters: ['default']
},
['/root/jest.config.js']
);
Expand All @@ -73,7 +74,7 @@ describe('Jest Builder', () => {
testNamePattern: 'should load',
testPathPattern: '/test/path',
colors: false,
reporters: '/test/path',
reporters: ['/test/path'],
verbose: false,
coverage: false,
coverageReporters: 'test',
Expand Down Expand Up @@ -106,7 +107,7 @@ describe('Jest Builder', () => {
testNamePattern: 'should load',
testPathPattern: '/test/path',
colors: false,
reporters: '/test/path',
reporters: ['/test/path'],
verbose: false,
coverageReporters: 'test',
coverageDirectory: '/test/path',
Expand Down Expand Up @@ -149,6 +150,7 @@ describe('Jest Builder', () => {
}),
coverage: false,
findRelatedTests: true,
reporters: ['default'],
runInBand: true,
testNamePattern: 'should load',
watch: false
Expand All @@ -174,7 +176,7 @@ describe('Jest Builder', () => {
testNamePattern: 'test',
testPathPattern: '/test/path',
colors: false,
reporters: '/test/path',
reporters: ['/test/path'],
verbose: false,
coverage: false,
coverageReporters: 'test',
Expand Down Expand Up @@ -218,7 +220,7 @@ describe('Jest Builder', () => {
testPathPattern: '/test/path',
colors: false,
verbose: false,
reporters: '/test/path',
reporters: ['/test/path'],
coverageReporters: 'test',
coverageDirectory: '/test/path',
updateSnapshot: true,
Expand Down Expand Up @@ -257,6 +259,7 @@ describe('Jest Builder', () => {
]
}
}),
reporters: ['default'],
setupTestFrameworkScriptFile: '/root/test.ts',
watch: false
},
Expand Down
8 changes: 7 additions & 1 deletion packages/jest/src/builders/jest/jest.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const { runCLI } = require('jest');

export interface JestBuilderOptions extends JsonObject {
codeCoverage?: boolean;
config?: string;
jestConfig: string;
testFile?: string;
setupFile?: string;
Expand All @@ -37,7 +38,7 @@ export interface JestBuilderOptions extends JsonObject {
testNamePattern?: string;
testPathPattern?: string;
colors?: boolean;
reporters?: string;
reporters?: string[];
verbose?: false;
coverage?: false;
coverageReporters?: string;
Expand Down Expand Up @@ -77,6 +78,7 @@ function run(

const config: any = {
_: [],
config: options.config,
coverage: options.codeCoverage,
bail: options.bail,
ci: options.ci,
Expand Down Expand Up @@ -125,6 +127,10 @@ function run(
config.clearCache = true;
}

if (!options.reporters || !options.reporters.length) {
config.reporters = ['default'];
}

return from(runCLI(config, [options.jestConfig])).pipe(
map((results: any) => {
return {
Expand Down
9 changes: 8 additions & 1 deletion packages/jest/src/builders/jest/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"description": "Indicates that test coverage information should be collected and reported in the output. (https://jestjs.io/docs/en/cli#coverage)",
"type": "boolean"
},
"config": {
"description": "The path to a Jest config file specifying how to find and execute tests. If no rootDir is set in the config, the directory containing the config file is assumed to be the rootDir for the project. This can also be a JSON-encoded value which Jest will use as configuration",
"type": "string"
},
"clearCache": {
"description": "Deletes the Jest cache directory and then exits without running tests. Will delete Jest's default cache directory. _Note: clearing the cache will reduce performance_.",
"type": "boolean"
Expand Down Expand Up @@ -91,7 +95,10 @@
},
"reporters": {
"description": "Run tests with specified reporters. Reporter options are not available via CLI. Example with multiple reporters: jest --reporters=\"default\" --reporters=\"jest-junit\" (https://jestjs.io/docs/en/cli#reporters)",
"type": "string"
"type": "array",
"items": {
"type": "string"
}
},
"verbose": {
"description": "Display individual test results with the test suite hierarchy. (https://jestjs.io/docs/en/cli#verbose)"
Expand Down

0 comments on commit ec9ed17

Please sign in to comment.