From 8b6de871390b88f0244f743138dbc8f038a00b0b Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Wed, 24 Jul 2024 16:01:04 +0200 Subject: [PATCH 1/2] chore: improve jest speed on both local and CI --- jest.preset.js | 13 +++++++++++++ scripts/jest/src/environment.js | 3 --- scripts/jest/src/jest.preset.v0.js | 3 +-- scripts/jest/src/jest.preset.v8.js | 3 +-- scripts/jest/src/shared.js | 12 +++++++++++- 5 files changed, 26 insertions(+), 8 deletions(-) delete mode 100644 scripts/jest/src/environment.js diff --git a/jest.preset.js b/jest.preset.js index 1a4492c352a218..ce87bfff5c8bfb 100644 --- a/jest.preset.js +++ b/jest.preset.js @@ -9,6 +9,8 @@ const tsPathAliases = pathsToModuleNameMapper(tsConfig.compilerOptions.paths, { prefix: `/${path.relative(process.cwd(), __dirname)}/`, }); +const isCI = Boolean(process.env.TF_BUILD); + /** * @type {import('@jest/types').Config.InitialOptions} */ @@ -29,6 +31,17 @@ const baseConfig = { escapeString: true, printBasicPrototype: true, }, + /** + * **Local Machine:** + * + * jest is resource greedy. on local machine it will spawn workers into all your CPU threads which will provide additional heat up of your machine and everything else will be blocked. + * Based on tests on local machine, 50% of CPU threads is the best value for local development ( also the fastest). + * + * **CI:** + * + * not spawning additional workers provides FASTER jest runs on CI. + */ + maxWorkers: isCI ? 1 : '50%', }; module.exports = { diff --git a/scripts/jest/src/environment.js b/scripts/jest/src/environment.js deleted file mode 100644 index d74fcd0a0386da..00000000000000 --- a/scripts/jest/src/environment.js +++ /dev/null @@ -1,3 +0,0 @@ -const isCI = Boolean(process.env.TF_BUILD); - -exports.isCI = isCI; diff --git a/scripts/jest/src/jest.preset.v0.js b/scripts/jest/src/jest.preset.v0.js index fb69b222cd275b..49d114d83535a1 100644 --- a/scripts/jest/src/jest.preset.v0.js +++ b/scripts/jest/src/jest.preset.v0.js @@ -1,6 +1,5 @@ const { getWorkspaceProjectsAliases } = require('@fluentui/scripts-monorepo'); -const { isCI } = require('./environment'); const { workersConfig } = require('./shared'); // northstar packages should pull these from npm, not the repo @@ -21,7 +20,7 @@ const createConfig = (/** @type {import('@jest/types').Config.InitialOptions} */ testEnvironment: 'jsdom', restoreMocks: true, clearMocks: true, - ...(isCI ? workersConfig : null), + ...workersConfig, ...customConfig, moduleNameMapper: { ...getWorkspaceProjectsAliases({ diff --git a/scripts/jest/src/jest.preset.v8.js b/scripts/jest/src/jest.preset.v8.js index ac3924e0633f9a..84697ed4a74074 100644 --- a/scripts/jest/src/jest.preset.v8.js +++ b/scripts/jest/src/jest.preset.v8.js @@ -4,7 +4,6 @@ const path = require('path'); const { findRepoDeps } = require('@fluentui/scripts-monorepo'); const { findConfig, merge } = require('@fluentui/scripts-utils'); -const { isCI } = require('./environment'); const { workersConfig } = require('./shared'); const packageJsonPath = findConfig('package.json') ?? ''; @@ -84,7 +83,7 @@ const createConfig = (customConfig = {}) => { restoreMocks: true, clearMocks: true, - ...(isCI ? workersConfig : null), + ...workersConfig, watchPlugins: ['jest-watch-typeahead/filename', 'jest-watch-typeahead/testname'], // OLD format for migration to jest 29 - TODO: migrate to new format . https://jestjs.io/blog/2022/04/25/jest-28#future diff --git a/scripts/jest/src/shared.js b/scripts/jest/src/shared.js index 56ff838a941358..86d47eadd1e97f 100644 --- a/scripts/jest/src/shared.js +++ b/scripts/jest/src/shared.js @@ -1,3 +1,13 @@ -const workersConfig = { maxWorkers: 4 }; +/** + * **Local Machine:** + * + * jest is resource greedy. on local machine it will spawn workers into all your CPU threads which will provide additional heat up of your machine and everything else will be blocked. + * Based on tests on local machine, 50% of CPU threads is the best value for local development ( also the fastest). + * + * **CI:** + * + * based on testing the same setting is fastest on our CI env atm ( 8 Core machine, 16GB RAM) + */ +const workersConfig = { maxWorkers: '50%' }; exports.workersConfig = workersConfig; From 49a4846f64a438e59e557ceb7baac0bb49c85101 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Thu, 25 Jul 2024 10:57:39 +0200 Subject: [PATCH 2/2] fixup! chore: improve jest speed on both local and CI --- jest.preset.js | 2 +- scripts/jest/src/shared.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jest.preset.js b/jest.preset.js index ce87bfff5c8bfb..c7f77c03de37d1 100644 --- a/jest.preset.js +++ b/jest.preset.js @@ -39,7 +39,7 @@ const baseConfig = { * * **CI:** * - * not spawning additional workers provides FASTER jest runs on CI. + * based on testing not spawning additional workers and rely on task orchestrator (NX) parallelization is fastest on our CI env atm ( 8 Core machine, 16GB RAM) */ maxWorkers: isCI ? 1 : '50%', }; diff --git a/scripts/jest/src/shared.js b/scripts/jest/src/shared.js index 86d47eadd1e97f..fc5c5cc4a94230 100644 --- a/scripts/jest/src/shared.js +++ b/scripts/jest/src/shared.js @@ -6,7 +6,7 @@ * * **CI:** * - * based on testing the same setting is fastest on our CI env atm ( 8 Core machine, 16GB RAM) + * based on testing spawning only 50% of available workers is fastest on both Local Machine and CI env atm ( 8 Core machine, 16GB RAM) */ const workersConfig = { maxWorkers: '50%' };