-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.jest.config.mjs
55 lines (46 loc) · 1.31 KB
/
common.jest.config.mjs
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
import { accessSync, constants, readFileSync } from 'fs';
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';
export const isCI = !!process.env.CI;
function canRead(path) {
try {
accessSync(path, constants.R_OK);
return true;
} catch(_) {
return false;
}
}
export function config(importMeta, overrides = {}, { transformNodeModules = false } = {}) {
let swcjson = {};
const swcpath = join(dirname(fileURLToPath(importMeta.url)), '.swcrc');
if (canRead(swcpath)) {
swcjson = JSON.parse(readFileSync(swcpath, 'utf8'));
}
return {
setupFiles: ['<rootDir>/__tests__/setup.js'],
testRegex: '(\\.|/)(test|spec)\\.[jt]sx?$',
collectCoverageFrom: ['src/**/*.[jt]sx?'],
maxWorkers: isCI ? '100%' : '50%',
// workaround for memory leaks
workerIdleMemoryLimit: '512MB',
showSeed: true, // helps to reproduce order-dependence bugs
transform: {
'^.+\\.jsx?$': ['@swc/jest', {
...swcjson,
module: {
...swcjson.module,
type: 'commonjs',
},
...(transformNodeModules ? {
exclude: [],
} : {})
}],
},
...(transformNodeModules ? {
transformIgnorePatterns: [
`node_modules/(?!(${transformNodeModules.join('|')})/)`,
],
} : {}),
...overrides,
};
}