-
Notifications
You must be signed in to change notification settings - Fork 395
/
jest.config.js
133 lines (128 loc) · 4.23 KB
/
jest.config.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
const { pathsToModuleNameMapper } = require('ts-jest');
const tsconfig = require('./configs/ts/tsconfig.resolve.json');
const tsModuleNameMapper = pathsToModuleNameMapper(tsconfig.compilerOptions.paths, { prefix: '<rootDir>/configs/' });
/**
* @type {import('@jest/types').Config.InitialOptions}
*/
const baseConfig = {
preset: 'ts-jest',
resolver: '<rootDir>/tools/dev-tool/src/jest-resolver.js',
maxWorkers: 2,
collectCoverageFrom: [
'packages/*/src/**/*.ts',
'!packages/**/*.contribution.ts',
// 部分contribution文件为-contribution结尾
'!packages/**/*-contribution.ts',
'!packages/startup/**/*.ts',
// Test 功能暂未完成
'!packages/testing/**/*.ts',
// CLI 不需要测试
'!packages/remote-cli/**/*.ts',
'!packages/core-electron-main/**/*.ts',
'!packages/*/src/electron-main/**/*.ts',
],
moduleNameMapper: {
...tsModuleNameMapper,
'^vscode-languageserver-types$': '<rootDir>/node_modules/vscode-languageserver-types/lib/umd/main.js',
'^ws$': '<rootDir>/node_modules/ws/index.js',
'.*\\.(css|less)$': '<rootDir>/tools/dev-tool/src/mock-exports.js',
},
testPathIgnorePatterns: [
'/dist/',
'/node_modules/',
'/tools/workspace/',
'/tools/template/',
'/tools/extensions/',
'/packages/status-bar/entry',
'/packages/startup/entry',
'/__mocks__/',
'/packages/quick-open/entry',
// 终端渲染测试暂时不跟随单元测试
'/packages/terminal-next/__tests__/browser/render.test.ts',
],
modulePathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/tools/workspace/'],
coveragePathIgnorePatterns: [
'/dist/',
'/node_modules/',
'/mocks/',
'/tools/template/',
'/tools/workspace/',
'/packages/startup/entry',
],
coverageThreshold: {
global: {
branches: 0,
functions: 0,
lines: 0,
statements: 0,
},
},
};
if (process.env.JEST_COVERAGE_PROVIDER) {
baseConfig.coverageProvider = process.env.JEST_COVERAGE_PROVIDER;
}
/**
* @type {import('@jest/types').Config.InitialOptions}
*/
module.exports = {
...baseConfig,
coverageReporters: ['json', 'clover'],
projects: [
{
...baseConfig,
displayName: 'node',
testEnvironment: 'node',
setupFiles: ['./jest.setup.node.js'],
testMatch: [
// 有个 webview 的 case 应该放在 electron 下测,也会被第一条规则匹配到
// - packages/webview/__tests__/webview/webview.channel.test.ts
'**/packages/*/__test?(s)__/!(browser)/**/?(*.)+(spec|test).[jt]s?(x)',
'**/packages/{core-common,core-electron-main,core-node,utils,i18n}/__tests__/**/?(*.)+(spec|test).[jt]s?(x)',
// exclude 的要放最后
'!**/packages/{components,core-browser}/__tests__/**',
'!**/packages/extension/__tests__/{hosted,common}/**',
],
},
{
...baseConfig,
displayName: 'jsdom',
testEnvironment: 'jsdom',
testEnvironmentOptions: {
html: `<html>
<body>
<div id="main"></div>
</body>
</html>`,
runScripts: 'dangerously',
url: 'http://localhost/?id=1',
userAgent: `Mozilla/5.0 (${
process.platform === 'darwin' ? 'Macintosh' : process.platform === 'win32' ? 'Windows' : 'Linux'
}) AppleWebKit/537.36 (KHTML, like Gecko) jsdom/v16.7.0`,
},
setupFiles: ['./jest.setup.jsdom.js'],
testMatch: [
'**/packages/*/__test?(s)__/browser/**/?(*.)+(spec|test).[jt]s?(x)',
'**/packages/*/__test?(s)__/common/**/?(*.)+(spec|test).[jt]s?(x)',
'**/tools/*/__tests__/**/?(*.)+(spec|test).[jt]s?(x)',
'**/packages/extension/__tests__/{hosted,common}/**/?(*.)+(spec|test).[jt]s?(x)',
'**/packages/{components,core-browser,core-common,electron-basic}/__tests__/**/?(*.)+(spec|test).[jt]s?(x)',
],
transformIgnorePatterns: ['/node_modules/(?!(@opensumi/monaco-editor-core)/)'],
transform: {
'^.+\\.(js)$': [
'ts-jest',
{
isolatedModules: true,
tsconfig: {
allowJs: true,
module: 'NodeNext',
moduleResolution: 'node',
esModuleInterop: true,
skipLibCheck: true,
},
},
],
},
},
],
};