From 8cbc5b4a3b7b4295a71fdaf9cc5c96b1ab33cb50 Mon Sep 17 00:00:00 2001 From: Jason Jean Date: Tue, 11 Sep 2018 12:23:31 -0400 Subject: [PATCH] feat(builders): add runInBand and maxWorkers options to jest --- packages/builders/src/jest/jest.builder.spec.ts | 8 ++++++-- packages/builders/src/jest/jest.builder.ts | 7 +++++++ packages/builders/src/jest/schema.json | 10 ++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/builders/src/jest/jest.builder.spec.ts b/packages/builders/src/jest/jest.builder.spec.ts index 8fdaa5fdf7eb41..e5ccbd047ca8c1 100644 --- a/packages/builders/src/jest/jest.builder.spec.ts +++ b/packages/builders/src/jest/jest.builder.spec.ts @@ -67,7 +67,9 @@ describe('Jest Builder', () => { ci: true, updateSnapshot: true, onlyChanged: true, - passWithNoTests: true + passWithNoTests: true, + runInBand: true, + maxWorkers: 2 } }) .toPromise(); @@ -84,7 +86,9 @@ describe('Jest Builder', () => { ci: true, updateSnapshot: true, onlyChanged: true, - passWithNoTests: true + passWithNoTests: true, + runInBand: true, + maxWorkers: 2 }, ['./jest.config.js'] ); diff --git a/packages/builders/src/jest/jest.builder.ts b/packages/builders/src/jest/jest.builder.ts index 24f60f35e1591f..10f4ec5c8c5553 100644 --- a/packages/builders/src/jest/jest.builder.ts +++ b/packages/builders/src/jest/jest.builder.ts @@ -18,7 +18,9 @@ export interface JestBuilderOptions { ci?: boolean; codeCoverage?: boolean; onlyChanged?: boolean; + maxWorkers?: number; passWithNoTests?: boolean; + runInBand?: boolean; setupFile?: string; updateSnapshot?: boolean; } @@ -35,6 +37,7 @@ export default class JestBuilder implements Builder { updateSnapshot: options.updateSnapshot, onlyChanged: options.onlyChanged, passWithNoTests: options.passWithNoTests, + runInBand: options.runInBand, globals: JSON.stringify({ 'ts-jest': { tsConfigFile: path.relative(builderConfig.root, options.tsConfig) @@ -43,6 +46,10 @@ export default class JestBuilder implements Builder { }) }; + if (options.maxWorkers) { + config.maxWorkers = options.maxWorkers; + } + if (options.setupFile) { config.setupTestFrameworkScriptFile = path.join( '', diff --git a/packages/builders/src/jest/schema.json b/packages/builders/src/jest/schema.json index 35bd8e1581d541..9e91dcb676f0cd 100644 --- a/packages/builders/src/jest/schema.json +++ b/packages/builders/src/jest/schema.json @@ -49,6 +49,16 @@ "type": "boolean", "description": "Fail on missing snapshots. (https://jestjs.io/docs/en/cli#ci)" + }, + "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"]