-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjest.config.ts
123 lines (117 loc) · 4.32 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
import type { Config } from '@jest/types'
import { createDefaultEsmPreset } from 'ts-jest'
const packages: [name: string, directory?: string, sourceDirectory?: string][] = [
['@content-ui/diff', 'diff'],
['@content-ui/input', 'input'],
['@content-ui/md', 'md'],
['@content-ui/md-mui', 'md-mui'],
['@content-ui/react', 'react'],
['@content-ui/struct', 'struct'],
]
const toPackageDirectory = (pkg: [name: string, directory?: string, sourceDirectory?: string]) => {
return pkg[1] || pkg[0]
}
const toPackageSourceDirectory = (pkg: [name: string, directory?: string, sourceDirectory?: string]) => {
return pkg[2] ? '/' + pkg[2] : ''
}
// todo: For tests in ESM sometimes `React` is undefined, yet somehow could not make it reproducible.
// It is the `import React from 'react'` vs `import * as React from 'react'` thing.
// - somehow it first failed, then worked with `"jsx": "react-jsxdev"`, afterwards some kind of caching?!
// - not depending on disabling transform of packages
const base: Config.InitialProjectOptions = {
cacheDirectory: '<rootDir>/node_modules/.cache/jest-tmp',
transformIgnorePatterns: [
`node_modules/?!(${[
...packages,
['@mui'] as [name: string, directory?: string],
].map(toPackageDirectory).join('|')})/`,
// `node_modules/?!(@mui)/`,
],
transform: {
...createDefaultEsmPreset({
babelConfig: {
plugins: [
'./babelImportDefaultPlugin.js',
// ['transform-imports', { // not validated/checked
// 'react': {
// // 'transform': 'import * as React from 'react'',
// // 'preventFullImport': true,
// },
// }],
],
},
}).transform,// ts/tsx to ESM, js/jsx as-is
},
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
// '^(\\.{1,2}/.*)\\.ts$': '$1',
// '^(\\.{1,2}/.*)\\.tsx$': '$1',
...packages.reduce((nameMapper, pkg) => {
nameMapper[`^${pkg[0]}\\/(.*)$`] = `<rootDir>/packages/${toPackageDirectory(pkg)}${toPackageSourceDirectory(pkg)}/$1`
nameMapper[`^${pkg[0]}$`] = `<rootDir>/packages/${toPackageDirectory(pkg)}${toPackageSourceDirectory(pkg)}`
return nameMapper
}, {}),
},
moduleFileExtensions: [
'ts',
'tsx',
'js',
'jsx',
'json',
'node',
],
extensionsToTreatAsEsm: ['.ts', '.tsx'],
coveragePathIgnorePatterns: [
'(tests/.*.mock).(jsx?|tsx?|ts?|js?)$',
'.*.(test|spec).(js|ts|tsx)$',
'<rootDir>/apps/demo',
'<rootDir>/apps/sandbox',
'<rootDir>/server/feed',
],
testPathIgnorePatterns: [
'<rootDir>/dist',
'<rootDir>/apps/demo/build',
'<rootDir>/server/feed/build',
],
watchPathIgnorePatterns: [
'<rootDir>/dist',
'<rootDir>/node_modules',
'<rootDir>/apps/.+/node_modules',
'<rootDir>/server/.+/node_modules',
'<rootDir>/packages/.+/node_modules',
],
modulePathIgnorePatterns: [
'<rootDir>/dist',
'<rootDir>/apps/.+/build',
'<rootDir>/server/.+/build',
],
}
const config: Config.InitialOptions = {
...base,
collectCoverage: true,
verbose: true,
coverageDirectory: '<rootDir>/coverage',
projects: [
{
displayName: 'test-apps-demo',
...base,
moduleDirectories: ['node_modules', '<rootDir>/apps/demo/node_modules'],
testMatch: [
'<rootDir>/apps/demo/src/**/*.(test|spec).(js|ts|tsx)',
'<rootDir>/apps/demo/tests/**/*.(test|spec).(js|ts|tsx)',
],
},
...packages.map(pkg => ({
displayName: 'test-' + pkg[0],
...base,
moduleDirectories: [
'node_modules', '<rootDir>/packages/' + toPackageDirectory(pkg) + '/node_modules',
],
testMatch: [
'<rootDir>/packages/' + toPackageDirectory(pkg) + toPackageSourceDirectory(pkg) + '/**/*.(test|spec).(js|ts|tsx)',
'<rootDir>/packages/' + toPackageDirectory(pkg) + '/tests/**/*.(test|spec).(js|ts|tsx)',
],
})),
],
}
export default config