Skip to content

Commit

Permalink
feat(builders): add runInBand and maxWorkers options to jest (#757)
Browse files Browse the repository at this point in the history
Fixes #754

## Current Behavior

`runInBand` and `maxWorkers` are useful for CI environments but are not available through the builder.

## Expected Behavior

Both `runInBand` and `maxWorkers` have been added and can be used as per [Jest Troubleshooting](https://jestjs.io/docs/en/troubleshooting#tests-are-extremely-slow-on-docker-and-or-continuous-integration-ci-server).

```sh
  --max-workers
    Max number of workers to run tests across. Useful for CI. (https://jestjs.io/docs/en/cli.html#maxworkers-num)
  --run-in-band
    Run tests in a single process as opposed to multiple workers. Useful for CI. (https://jestjs.io/docs/en/cli.html#runinband)
```
  • Loading branch information
FrozenPandaz authored and bcabanes committed Sep 14, 2018
1 parent 817691d commit edae03e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/builders/src/jest/jest.builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ describe('Jest Builder', () => {
onlyChanged: true,
passWithNoTests: true,
bail: true,
silent: true
silent: true,
runInBand: true,
maxWorkers: 2
}
})
.toPromise();
Expand All @@ -88,7 +90,9 @@ describe('Jest Builder', () => {
onlyChanged: true,
passWithNoTests: true,
bail: true,
silent: true
silent: true,
runInBand: true,
maxWorkers: 2
},
['./jest.config.js']
);
Expand Down
7 changes: 7 additions & 0 deletions packages/builders/src/jest/jest.builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export interface JestBuilderOptions {
ci?: boolean;
codeCoverage?: boolean;
onlyChanged?: boolean;
maxWorkers?: number;
passWithNoTests?: boolean;
runInBand?: boolean;
setupFile?: string;
silent?: boolean;
updateSnapshot?: boolean;
Expand All @@ -39,6 +41,7 @@ export default class JestBuilder implements Builder<JestBuilderOptions> {
onlyChanged: options.onlyChanged,
passWithNoTests: options.passWithNoTests,
silent: options.silent,
runInBand: options.runInBand,
globals: JSON.stringify({
'ts-jest': {
tsConfigFile: path.relative(builderConfig.root, options.tsConfig)
Expand All @@ -47,6 +50,10 @@ export default class JestBuilder implements Builder<JestBuilderOptions> {
})
};

if (options.maxWorkers) {
config.maxWorkers = options.maxWorkers;
}

if (options.setupFile) {
config.setupTestFrameworkScriptFile = path.join(
'<rootDir>',
Expand Down
10 changes: 10 additions & 0 deletions packages/builders/src/jest/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@
"type": "boolean",
"description":
"Prevent tests from printing messages through the console. (https://jestjs.io/docs/en/cli#silent)"
},
"runInBand": {
"type": "boolean",
"description":
"Run tests in a single process as opposed to multiple workers. Useful for CI. (https://jestjs.io/docs/en/cli.html#runinband)"
},
"maxWorkers": {
"type": "number",
"description":
"Max number of workers to run tests across. Useful for CI. (https://jestjs.io/docs/en/cli.html#maxworkers-num)"
}
},
"required": ["jestConfig", "tsConfig"]
Expand Down

0 comments on commit edae03e

Please sign in to comment.