-
Notifications
You must be signed in to change notification settings - Fork 832
Expand file tree
/
Copy pathjest.config.js
More file actions
93 lines (90 loc) · 4.18 KB
/
Copy pathjest.config.js
File metadata and controls
93 lines (90 loc) · 4.18 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// @kayahr/jest-electron-runner executes tests directly in an Electron
// BrowserWindow's native V8 context (via vm.Script#runInThisContext, not a
// proper vm sandbox). That context enforces V8's AllowCodeGenerationFromStrings
// restriction, which Istanbul's coverage instrumentation trips over: it injects
// `new Function(...)` counter calls into every instrumented module. This is not
// configurable via webPreferences (contextIsolation/nodeIntegration/sandbox all
// verified to have no effect) or CSP (the runner's own bootstrap HTML already
// allows 'unsafe-eval') — it's enforced at V8 context-creation time, which has
// no exposed Electron or Node API. The suites below all load preload/renderer-
// context modules and fail with "EvalError: Code generation from strings
// disallowed for this context" only when --coverage is active; they pass
// cleanly under plain `yarn test`. Excluded here (coverage runs only) so CI's
// `yarn test:coverage` stays green; they still run and gate on pass/fail via
// plain `yarn test`.
const COVERAGE_INCOMPATIBLE_SPECS = [
'<rootDir>/src/jitsi/__tests__/preload.spec.ts',
'<rootDir>/src/screenSharing/__tests__/preload.spec.ts',
'<rootDir>/src/servers/preload/__tests__/badge.spec.ts',
'<rootDir>/src/servers/preload/__tests__/clipboard.spec.ts',
'<rootDir>/src/servers/preload/__tests__/documentViewer.spec.ts',
'<rootDir>/src/servers/preload/__tests__/favicon.spec.ts',
'<rootDir>/src/servers/preload/__tests__/internalVideoChatWindow.spec.ts',
'<rootDir>/src/servers/preload/__tests__/presence.spec.ts',
'<rootDir>/src/servers/preload/__tests__/sidebar.spec.ts',
'<rootDir>/src/servers/preload/__tests__/uniqueID.spec.ts',
'<rootDir>/src/servers/preload/__tests__/userLoggedIn.spec.ts',
'<rootDir>/src/servers/preload/userRoles-server-url.spec.ts',
'<rootDir>/src/servers/preload/userRoles.spec.ts',
'<rootDir>/src/store/__tests__/index.spec.ts',
'<rootDir>/src/ui/components/utils/createAnchor.spec.ts',
'<rootDir>/src/ui/preload/__tests__/messageBox.spec.ts',
'<rootDir>/src/ui/preload/__tests__/sidebar.spec.ts',
'<rootDir>/src/whenReady.spec.ts',
];
const isCoverageRun = process.argv.includes('--coverage');
// Transpile-only ts-jest: every spec is compiled as an isolated module instead
// of building a full type-checking Program per file. Cold-cache transform time
// drops by roughly 60%, and CI always runs cold. Type errors in specs are still
// caught by `tsc --noEmit` in `yarn lint`, which covers src/** including specs.
// Passed as inline compiler options so tsconfig.json itself is unchanged.
const tsJestTransform = {
'^.+\\.tsx?$': ['ts-jest', { tsconfig: { isolatedModules: true } }],
};
module.exports = {
collectCoverageFrom: [
'src/**/*.{ts,tsx}',
'!src/**/*.spec.{ts,tsx}',
'!src/**/*.test.{ts,tsx}',
'!src/**/*.d.ts',
'!src/.jest/**',
'!src/public/**',
],
coverageReporters: ['text-summary', 'lcov', 'json-summary'],
coverageDirectory: 'coverage',
coveragePathIgnorePatterns: ['/node_modules/', '/app/', '/dist/'],
projects: [
{
transform: tsJestTransform,
errorOnDeprecated: true,
runner: '@kayahr/jest-electron-runner',
testEnvironment: '@kayahr/jest-electron-runner/environment',
testMatch: [
'<rootDir>/src/*/!(main)/**/*.(spec|test).{js,ts,tsx}',
'<rootDir>/src/**/renderer.(spec|test).{js,ts,tsx}',
'<rootDir>/src/whenReady.(spec|test).{js,ts,tsx}',
],
testPathIgnorePatterns: isCoverageRun ? COVERAGE_INCOMPATIBLE_SPECS : [],
setupFilesAfterEnv: ['./src/.jest/setup.ts'],
},
{
transform: tsJestTransform,
errorOnDeprecated: true,
runner: '@kayahr/jest-electron-runner/main',
testEnvironment: 'node',
testMatch: [
'<rootDir>/src/*/main/**/*.(spec|test).{js,ts,tsx}',
'<rootDir>/src/**/main.(spec|test).{js,ts,tsx}',
'<rootDir>/src/systemCertificates.(spec|test).{js,ts,tsx}',
'<rootDir>/src/constants.(spec|test).{js,ts,tsx}',
],
setupFilesAfterEnv: ['./src/.jest/setup.ts'],
},
{
transform: tsJestTransform,
errorOnDeprecated: true,
testEnvironment: 'node',
testMatch: ['<rootDir>/scripts/**/*.(spec|test).ts'],
},
],
};