Skip to content

Commit

Permalink
feat(jest): expose maxmaxWorkers property in jest config (projen#1675)
Browse files Browse the repository at this point in the history
closes projen#1645

---
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
  • Loading branch information
saudkhanzada authored Mar 10, 2022
1 parent 8ed9df6 commit 5b9369c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/api/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -14645,6 +14645,7 @@ Name | Type | Description
**haste**?🔹 | <code>[javascript.HasteConfig](#projen-javascript-hasteconfig)</code> | This will be used to configure the behavior of jest-haste-map, Jest's internal file crawler/cache system.<br/>__*Default*__: {}
**injectGlobals**?🔹 | <code>boolean</code> | Insert Jest's globals (expect, test, describe, beforeEach etc.) into the global environment. If you set this to false, you should import from @jest/globals.<br/>__*Default*__: true
**maxConcurrency**?🔹 | <code>number</code> | A number limiting the number of tests that are allowed to run at the same time when using test.concurrent. Any test above this limit will be queued and executed once a slot is released.<br/>__*Default*__: 5
**maxWorkers**?🔹 | <code>string &#124; number</code> | Specifies the maximum number of workers the worker-pool will spawn for running tests.<br/>__*Default*__: the number of the cores available on your machine minus one for the main thread
**moduleDirectories**?🔹 | <code>Array<string></code> | An array of directory names to be searched recursively up from the requiring module's location.<br/>__*Default*__: ["node_modules"]
**moduleFileExtensions**?🔹 | <code>Array<string></code> | An array of file extensions your modules use.<br/>__*Default*__: ["js", "json", "jsx", "ts", "tsx", "node"]
**moduleNameMapper**?🔹 | <code>Map<string, string &#124; Array<string>></code> | A map from regular expressions to module names or to arrays of module names that allow to stub out resources, like images or styles with a single module.<br/>__*Default*__: null
Expand Down
9 changes: 9 additions & 0 deletions src/javascript/jest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,15 @@ export interface JestConfigOptions {
*/
readonly maxConcurrency?: number;

/**
* Specifies the maximum number of workers the worker-pool will spawn for running tests. In single run mode,
* this defaults to the number of the cores available on your machine minus one for the main thread
* In watch mode, this defaults to half of the available cores on your machine.
* For environments with variable CPUs available, you can use percentage based configuration: "maxWorkers": "50%"
* @default - the number of the cores available on your machine minus one for the main thread
*/
readonly maxWorkers?: number | string;

/**
* An array of directory names to be searched recursively up from the requiring module's location.
* Setting this option will override the default, if you wish to still search node_modules for packages
Expand Down
2 changes: 2 additions & 0 deletions test/jest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ test("Node Project Jest With Options Configured", () => {
automock: true,
bail: 5,
notify: false,
maxWorkers: 1,
},
},
});
Expand All @@ -75,6 +76,7 @@ test("Node Project Jest With Options Configured", () => {
expect(jest.automock).toEqual(true);
expect(jest.bail).toEqual(5);
expect(jest.notify).toEqual(false);
expect(jest.maxWorkers).toEqual(1);
});

test("Node Project Jest With Path Configured", () => {
Expand Down

0 comments on commit 5b9369c

Please sign in to comment.