Skip to content

Commit

Permalink
feat(builders): expose clearCache to Jest builder
Browse files Browse the repository at this point in the history
This exposes the `clearCache` option from Jest to Nx. You can now easily
clear Jest's default cache directory while running your tests.
  • Loading branch information
bcabanes authored and vsavkin committed Apr 16, 2019
1 parent c1f3772 commit 41b915b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/api-builders/jest.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ Type: `boolean`

Whether to run Jest in continuous integration (CI) mode. This option is on by default in most popular CI environments. It will prevent snapshots from being written unless explicitly requested. (https://jestjs.io/docs/en/cli#ci)

### clearCache

Type: `boolean`

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_.

### codeCoverage

Type: `boolean`
Expand Down
5 changes: 5 additions & 0 deletions packages/builders/src/jest/jest.builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface JestBuilderOptions {
bail?: number | boolean;
ci?: boolean;
color?: boolean;
clearCache?: boolean;
json?: boolean;
maxWorkers?: number;
onlyChanged?: boolean;
Expand Down Expand Up @@ -109,6 +110,10 @@ export default class JestBuilder implements Builder<JestBuilderOptions> {
config._ = [options.testFile];
}

if (options.clearCache) {
config.clearCache = true;
}

return from(runCLI(config, [options.jestConfig])).pipe(
map((results: any) => {
return {
Expand Down
4 changes: 4 additions & 0 deletions packages/builders/src/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"
},
"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"
},
"jestConfig": {
"description": "The path of the Jest configuration. (https://jestjs.io/docs/en/configuration)",
"type": "string"
Expand Down

0 comments on commit 41b915b

Please sign in to comment.