Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve jest speed on both local and CI #32096

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions jest.preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const tsPathAliases = pathsToModuleNameMapper(tsConfig.compilerOptions.paths, {
prefix: `<rootDir>/${path.relative(process.cwd(), __dirname)}/`,
});

const isCI = Boolean(process.env.TF_BUILD);

/**
* @type {import('@jest/types').Config.InitialOptions}
*/
Expand All @@ -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 = {
Expand Down
3 changes: 0 additions & 3 deletions scripts/jest/src/environment.js

This file was deleted.

3 changes: 1 addition & 2 deletions scripts/jest/src/jest.preset.v0.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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({
Expand Down
3 changes: 1 addition & 2 deletions scripts/jest/src/jest.preset.v8.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') ?? '';
Expand Down Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion scripts/jest/src/shared.js
Original file line number Diff line number Diff line change
@@ -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;
Loading