forked from react-hook-form/react-hook-form
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.config.js
93 lines (85 loc) · 1.99 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
/* eslint-disable @typescript-eslint/no-var-requires */
const { defaults: tsjPresets } = require('ts-jest/presets');
const jestPresets = require('@testing-library/react-native/jest-preset');
const getTestMatch = (name) =>
['**/+([a-zA-Z])', name, '(spec|test).ts?(x)'].filter(Boolean).join('.');
const common = {
roots: ['<rootDir>/src'],
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
globals: {
'ts-jest': {
tsConfig: 'tsconfig.jest.json',
},
},
transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$'],
moduleFileExtensions: ['ts', 'tsx', 'js'],
};
const web = {
...common,
displayName: {
name: 'Web',
color: 'cyan',
},
testMatch: [getTestMatch()],
setupFilesAfterEnv: ['<rootDir>/setup.ts'],
};
const server = {
...common,
displayName: {
name: 'Server',
color: 'blue',
},
testMatch: [getTestMatch('server')],
testEnvironment: 'node',
};
const native = {
...common,
displayName: {
name: 'Native',
color: 'magenta',
},
preset: '@testing-library/react-native',
testMatch: [getTestMatch('native')],
transform: {
...tsjPresets.transform,
'^.+\\.tsx?$': 'ts-jest',
'^.+\\.jsx?$': '<rootDir>/node_modules/react-native/jest/preprocessor.js',
},
globals: {
'ts-jest': {
tsConfig: 'tsconfig.jest.json',
babelConfig: true,
},
},
transformIgnorePatterns: [
'[/\\\\]node_modules[/\\\\](?!react-native)[/\\\\].+',
],
setupFiles: [...jestPresets.setupFiles],
setupFilesAfterEnv: ['<rootDir>/setup.native.ts'],
};
const getProjects = () => {
const testEnv = process.env.TEST_ENV;
if (!testEnv) {
return [web, server, native];
}
switch (testEnv) {
case 'web':
return [web];
case 'server':
return [server];
case 'native':
return [native];
}
};
module.exports = {
collectCoverageFrom: [
'**/**/*.{ts,tsx}',
'!**/**/*.test.{ts,tsx}',
'!**/src/types/**',
'!**/node_modules/**',
'!**/dist/**',
],
projects: getProjects(),
};