-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjest.config.ts
141 lines (123 loc) · 4.45 KB
/
jest.config.ts
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
134
135
136
137
138
139
140
141
import type { Config } from '@jest/types';
const DIR_SRC = 'src/main/resources';
const DIR_SRC_JEST = 'src/jest';
const DIR_SRC_JEST_CLIENT = `${DIR_SRC_JEST}/client`;
const DIR_SRC_JEST_SERVER = `${DIR_SRC_JEST}/server`;
const AND_BELOW = '**';
const SOURCE_FILES = `*.{ts,tsx}`;
const TEST_EXT = `{spec,test}.{ts,tsx}`;
const TEST_FILES = `*.${TEST_EXT}`;
const commonConfig: Config.InitialProjectOptions = {
collectCoverageFrom: [
`${DIR_SRC}/${AND_BELOW}/${SOURCE_FILES}`,
],
// Insert Jest's globals (expect, test, describe, beforeEach etc.) into the
// global environment. If you set this to false, you should import from @jest/globals, e.g.
// injectGlobals: true, // Doesn't seem to work?
};
const clientSideConfig: Config.InitialProjectOptions = {
...commonConfig,
displayName: {
color: 'white',
name: 'CLIENT',
},
// A map from regular expressions to module names or to arrays of module
// names that allow to stub out resources, like images or styles with a
// single module.
// Use <rootDir> string token to refer to rootDir value if you want to use
// file paths.
// Additionally, you can substitute captured regex groups using numbered
// backreferences.
moduleNameMapper: {
'/assets/(.*)': `<rootDir>/${DIR_SRC}/assets/$1`,
},
// Run clientside tests with DOM globals such as document and window
testEnvironment: 'jsdom',
// The glob patterns Jest uses to detect test files. By default it looks for
// .js, .jsx, .ts and .tsx files inside of __tests__ folders, as well as any
// files with a suffix of .test or .spec (e.g. Component.test.js or
// Component.spec.js). It will also find files called test.js or spec.js.
// (default: [
// "**/__tests__/**/*.[jt]s?(x)",
// "**/?(*.)+(spec|test).[jt]s?(x)"
// ])
testMatch: [
`<rootDir>/${DIR_SRC_JEST_CLIENT}/${AND_BELOW}/${TEST_FILES}`,
],
transform: {
"^.+\\.(ts|js)x?$": [
'ts-jest',
{
tsconfig: `${DIR_SRC_JEST_CLIENT}/tsconfig.json`
}
]
}
};
const serverSideConfig: Config.InitialProjectOptions = {
...commonConfig,
displayName: {
color: 'blue',
name: 'SERVER',
},
// A set of global variables that need to be available in all test
// environments.
// If you specify a global reference value (like an object or array) here,
// and some code mutates that value in the midst of running a test, that
// mutation will not be persisted across test runs for other test files.
// In addition, the globals object must be json-serializable, so it can't be
// used to specify global functions. For that, you should use setupFiles.
globals: {
app: {
name: 'com.example.myproject',
config: {},
version: '1.0.0'
},
},
// A map from regular expressions to module names or to arrays of module
// names that allow to stub out resources, like images or styles with a
// single module.
// Use <rootDir> string token to refer to rootDir value if you want to use
// file paths.
// Additionally, you can substitute captured regex groups using numbered
// backreferences.
moduleNameMapper: {
'/lib/enonic/react4xp/(.*)': `<rootDir>/${DIR_SRC}/lib/enonic/react4xp/$1`,
},
// A list of paths to modules that run some code to configure or set up the
// testing environment. Each setupFile will be run once per test file. Since
// every test runs in its own environment, these scripts will be executed in
// the testing environment before executing setupFilesAfterEnv and before
// the test code itself.
setupFiles: [
`<rootDir>/${DIR_SRC_JEST_SERVER}/setupFile.ts`,
`<rootDir>/${DIR_SRC_JEST_SERVER}/mockXP.ts`
],
// Run serverside tests without DOM globals such as document and window
testEnvironment: 'node',
// testEnvironment: 'jsdom', // "Graal"
// The glob patterns Jest uses to detect test files. By default it looks for
// .js, .jsx, .ts and .tsx files inside of __tests__ folders, as well as any
// files with a suffix of .test or .spec (e.g. Component.test.js or
// Component.spec.js). It will also find files called test.js or spec.js.
// (default: [
// "**/__tests__/**/*.[jt]s?(x)",
// "**/?(*.)+(spec|test).[jt]s?(x)"
// ])
testMatch: [
`<rootDir>/${DIR_SRC_JEST_SERVER}/${AND_BELOW}/${TEST_FILES}`,
],
transform: {
"^.+\\.(ts|js)x?$": [
'ts-jest',
{
tsconfig: `${DIR_SRC_JEST_SERVER}/tsconfig.json`
}
]
},
};
const customJestConfig: Config.InitialOptions = {
coverageProvider: 'v8', // To get correct line numbers under jsdom
passWithNoTests: true,
projects: [clientSideConfig, serverSideConfig],
};
export default customJestConfig;