Skip to content

Commit

Permalink
fix(testing): update maxWorkers jest builder option to support string…
Browse files Browse the repository at this point in the history
… type

Jest supports both number and string args for the maxWorkers option, per their latest docs. This
updates the options for the jest builder to support both number and string types. Also updates the
docs accordingly.

ISSUES CLOSED: nrwl#2871
  • Loading branch information
wrslatz committed May 17, 2020
1 parent 6e8d461 commit 3dcfc93
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/angular/api-jest/builders/jest.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Prints the test results in JSON. This mode will send all other test output and u

Alias(es): w

Type: `number`
Type: `number | string`

Specifies the maximum number of workers the worker-pool will spawn for running tests. This defaults to the number of the cores available on your machine. Useful for CI. (its usually best not to override this default) (https://jestjs.io/docs/en/cli#maxworkers-num)

Expand Down
2 changes: 1 addition & 1 deletion docs/react/api-jest/builders/jest.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Prints the test results in JSON. This mode will send all other test output and u

Alias(es): w

Type: `number`
Type: `number | string`

Specifies the maximum number of workers the worker-pool will spawn for running tests. This defaults to the number of the cores available on your machine. Useful for CI. (its usually best not to override this default) (https://jestjs.io/docs/en/cli#maxworkers-num)

Expand Down
31 changes: 31 additions & 0 deletions packages/jest/src/builders/jest/jest.impl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,36 @@ describe('Jest Builder', () => {
);
});

it('should support passing string type for maxWorkers option to jestCLI', async () => {
const run = await architect.scheduleBuilder('@nrwl/jest:jest', {
jestConfig: './jest.config.js',
tsConfig: './tsconfig.test.json',
maxWorkers: "50%",
});
expect(await run.result).toEqual(
jasmine.objectContaining({
success: true,
})
);
expect(runCLI).toHaveBeenCalledWith(
{
_: [],
globals: JSON.stringify({
'ts-jest': {
tsConfig: '/root/tsconfig.test.json',
stringifyContentPathRegex: '\\.(html|svg)$',
astTransformers: [
'jest-preset-angular/build/InlineFilesTransformer',
'jest-preset-angular/build/StripStylesTransformer',
],
},
}),
maxWorkers: 2,
},
['/root/jest.config.js']
);
});

it('should send the main to runCLI', async () => {
const run = await architect.scheduleBuilder('@nrwl/jest:jest', {
jestConfig: './jest.config.js',
Expand All @@ -272,6 +302,7 @@ describe('Jest Builder', () => {
},
}),
setupFilesAfterEnv: ['/root/test-setup.ts'],
maxWorkers: "50%",
testPathPattern: [],
watch: false,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/jest/src/builders/jest/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface JestBuilderOptions extends JsonObject {
clearCache?: boolean;
findRelatedTests?: string;
json?: boolean;
maxWorkers?: number;
maxWorkers?: number | string;
onlyChanged?: boolean;
outputFile?: string;
passWithNoTests?: boolean;
Expand Down
5 changes: 4 additions & 1 deletion packages/jest/src/builders/jest/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@
"maxWorkers": {
"alias": "w",
"description": "Specifies the maximum number of workers the worker-pool will spawn for running tests. This defaults to the number of the cores available on your machine. Useful for CI. (its usually best not to override this default) (https://jestjs.io/docs/en/cli#maxworkers-num)",
"type": "number"
"oneOf": [
{ "type": "number" },
{ "type": "string" }
]
},
"onlyChanged": {
"alias": "o",
Expand Down

0 comments on commit 3dcfc93

Please sign in to comment.