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 (#3025)

* fix(testing): update maxWorkers jest builder option to support string 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: #2871

* fix(testing): fix test expectation missing property
  • Loading branch information
wrslatz authored May 23, 2020
1 parent bd5ca7d commit 3ecf6ea
Show file tree
Hide file tree
Showing 5 changed files with 35 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,37 @@ 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: '50%',
testPathPattern: [],
},
['/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 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
2 changes: 1 addition & 1 deletion packages/jest/src/builders/jest/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"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 3ecf6ea

Please sign in to comment.