forked from microsoft/fluentui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.preset.js
65 lines (59 loc) · 2.38 KB
/
jest.preset.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// @ts-check
const path = require('path');
const { pathsToModuleNameMapper } = require('ts-jest');
const tsConfig = require('./tsconfig.base.json');
const tsPathAliases = pathsToModuleNameMapper(tsConfig.compilerOptions.paths, {
prefix: `<rootDir>/${path.relative(process.cwd(), __dirname)}/`,
});
/**
* @type {import('@jest/types').Config.InitialOptions}
*/
const baseConfig = {
transform: {
'^.+\\.ts$': 'ts-jest',
},
testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
testPathIgnorePatterns: ['/node_modules/', '/lib/', '/lib-commonjs/', '/dist/'],
testEnvironment: 'jsdom',
moduleNameMapper: { ...tsPathAliases },
cacheDirectory: '<rootDir>/node_modules/.cache/jest',
clearMocks: true,
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
snapshotFormat: {
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:**
*
* 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%',
};
module.exports = {
...baseConfig,
/* TODO: Update to latest Jest snapshotFormat
* By default Nx has kept the older style of Jest Snapshot formats
* to prevent breaking of any existing tests with snapshots.
* It's recommend you update to the latest format.
* You can do this by removing snapshotFormat property
* and running tests with --update-snapshot flag.
* Example: "nx affected --targets=test --update-snapshot"
* More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
*/
snapshotFormat: { escapeString: true, printBasicPrototype: true },
};
function isCI() {
return (
(process.env.CI && process.env.CI !== 'false') ||
(process.env.TF_BUILD && process.env.TF_BUILD.toLowerCase() === 'true') ||
process.env.GITHUB_ACTIONS === 'true'
);
}