-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathjest.js
More file actions
72 lines (66 loc) · 2.29 KB
/
jest.js
File metadata and controls
72 lines (66 loc) · 2.29 KB
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
66
67
68
69
70
71
72
// @ts-check
const path = require('path');
/** @typedef {import('@jest/types').Config.InitialProjectOptions} InitialProjectOptions */
/** @typedef {import('@jest/types').Config.InitialOptions} InitialOptions */
/**
* Get options that apply to individual projects, or to the top level if not using projects.
* @param {Partial<InitialProjectOptions>} [projectOverrides] Any project options to override
* @returns {InitialProjectOptions}
*/
function getProjectOptions(projectOverrides) {
return {
injectGlobals: false,
roots: ['<rootDir>/src'],
setupFilesAfterEnv: [path.resolve(__dirname, 'jestSetup.js')],
transform: {
'^.+\\.tsx?$': [
'ts-jest',
// in ts-jest, this means skip type checking (we already type check in the build step)
{ tsconfig: { isolatedModules: true } },
],
},
testEnvironment: 'node',
...projectOverrides,
};
}
/**
* Get options that can only be applied at the top level, not per-project.
* @returns {InitialOptions}
*/
function getTopLevelOptions() {
return {
reporters: ['default', 'github-actions'],
// Enable to locally test with coverage info (will only work properly with `yarn test`, not
// `test:all` or individual projects). This would be tricky to enable in CI due to the multiple
// test projects that run in sequence. Coverage also doesn't alone capture tricky scenarios.
// collectCoverage: true,
coveragePathIgnorePatterns: ['/node_modules/', '__fixtures__'],
};
}
/**
* Get a Jest config with multiple projects.
* @param {InitialProjectOptions[]} projects Projects with `displayName`, `testMatch`, and any other options
* @param {Partial<InitialOptions>} [overrides] Any top-level options to override
* @returns {InitialOptions}
*/
function getConfigWithProjects(projects, overrides) {
return {
...getTopLevelOptions(),
projects: projects.map(project => getProjectOptions(project)),
...overrides,
};
}
/**
* Get a normal jest config (no projects).
* @param {Partial<InitialOptions>} [overrides] Any options to override
* @returns {InitialProjectOptions}
*/
function getConfig(overrides) {
return {
...getTopLevelOptions(),
...getProjectOptions(),
testMatch: ['src/**/*.test.ts'],
...overrides,
};
}
module.exports = { getConfig, getConfigWithProjects };