Repository navigation
Expand file tree
/
Copy pathjest.config.js
More file actions
172 lines (164 loc) · 5.33 KB
/
Copy pathjest.config.js
File metadata and controls
172 lines (164 loc) · 5.33 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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/* global require, module, __dirname */
process.env.ANANSI_JEST_BABELCONFIG = 'babel.config.js';
process.env.ANANSI_JEST_TSCONFIG = 'tsconfig.test.json';
const fs = require('fs');
const path = require('path');
const rnPreset = require('@react-native/jest-preset');
// ESM-only dependencies tests import; Jest must compile them to CommonJS
const esmModules = 'temporal-polyfill|temporal-utils';
const baseConfig = {
transformIgnorePatterns: [
`/node_modules/(?!@babel/runtime|${esmModules})`,
'\\.pnp\\.[^\\/]+$',
],
testEnvironmentOptions: {
globalsCleanup: 'on',
url: 'http://localhost',
},
preset: '@anansi/jest-preset',
moduleFileExtensions: [
'ts',
'tsx',
'cts',
'mts',
'mtsx',
'js',
'jsx',
'mjs',
'cjs',
'json',
],
coveragePathIgnorePatterns: [
'node_modules',
'/__tests__',
'DevtoolsManager',
'packages/vue/src/test',
'packages/test',
'packages/graphql',
// dev-time migration tooling: tested, but not held to the library's coverage floors
'packages/codemods',
'packages/rest/src/next',
'packages/core/src/next',
'packages/core/src/mock',
'packages/react/src/next',
'packages/react/src/server',
'packages/react/src/components/DevToolsButton.tsx',
// website code is tested but not published, so it isn't tracked
'<rootDir>/website/',
],
/** TODO: Remove once we move to 'publishConfig' */
moduleNameMapper: {
'^__tests__/(.*)$': '<rootDir>/__tests__/$1',
'@data-client/react/redux$': ['<rootDir>/packages/react/src/server/redux'],
'@data-client/([^/]+)(/.*|[^/]*)$': ['<rootDir>/packages/$1/src$2'],
},
};
const packages = [
'endpoint',
'rest',
'graphql',
'core',
'react',
'vue',
'normalizr',
'use-enhanced-reducer',
'img',
'codemods',
'test',
];
// CircleCI persist_to_workspace omits most of website/; only include these
// roots when the tree is present (full checkout / when CI persists them).
const websiteRoots = [
'website/src/components/Playground',
'website/src/components/motion',
];
const reactDomRoots = [
...packages.map(pkgName => `<rootDir>/packages/${pkgName}/src`),
...websiteRoots
.filter(root => fs.existsSync(path.join(__dirname, root)))
.map(root => `<rootDir>/${root}`),
];
const projects = [
{
...baseConfig,
rootDir: __dirname,
roots: reactDomRoots,
displayName: 'ReactDOM',
moduleNameMapper: {
...baseConfig.moduleNameMapper,
// Docusaurus modules the website's tested components import
'^@docusaurus/Translate$':
'<rootDir>/website/src/components/Playground/testing/docusaurusTranslate.tsx',
'^@docusaurus/theme-common$':
'<rootDir>/website/src/components/Playground/testing/docusaurusThemeCommon.ts',
'^@docusaurus/theme-common/internal$':
'<rootDir>/website/src/components/Playground/testing/docusaurusThemeCommonInternal.ts',
'^@docusaurus/BrowserOnly$':
'<rootDir>/website/src/components/Playground/testing/docusaurusBrowserOnly.tsx',
'^@docusaurus/useIsBrowser$':
'<rootDir>/website/src/components/Playground/testing/docusaurusUseIsBrowser.ts',
'^@docusaurus/useIsomorphicLayoutEffect$':
'<rootDir>/website/src/components/Playground/testing/docusaurusUseIsomorphicLayoutEffect.ts',
'^@theme/CodeBlock$':
'<rootDir>/website/src/components/Playground/testing/themeCodeBlock.tsx',
},
setupFiles: ['<rootDir>/scripts/testSetup.js'],
testEnvironment: 'jsdom',
testRegex: [
'((/__tests__/(?!.*\\.(node|native)).*)|(\\.|/)(test|spec))\\.(j|t)sx?$',
],
},
{
...baseConfig,
rootDir: __dirname,
roots: packages.map(pkgName => `<rootDir>/packages/${pkgName}/src`),
displayName: 'Node',
setupFiles: ['<rootDir>/scripts/testSetupNode.js'],
testEnvironment: 'node',
transform: {
...baseConfig.transform,
'^.+\\.(j)sx?$': [
'babel-jest',
{ rootMode: 'upward', targets: { node: 'current' } },
],
},
transformIgnorePatterns: [
...baseConfig.transformIgnorePatterns,
'<rootDir>/.*__tests__/[^/]+\\.(web|native)\\.(j|t)sx?$',
],
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.node\\.(j|t)sx?$',
},
{
// Layers @react-native/jest-preset on @anansi/jest-preset (jest takes one preset)
...baseConfig,
rootDir: __dirname,
roots: packages.map(pkgName => `<rootDir>/packages/${pkgName}/src`),
displayName: 'ReactNative',
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.native\\.(j|t)sx?$',
resolver: rnPreset.resolver,
moduleNameMapper: {
...baseConfig.moduleNameMapper,
// aliases react-native's `exports`-only entry points, which its resolver strips
...rnPreset.moduleNameMapper,
},
testEnvironment: rnPreset.testEnvironment,
transformIgnorePatterns: [
`node_modules\\/(?!(((jest-)?react-native)|@react-native(-community)?|@react-navigation|${esmModules}))`,
'<rootDir>/.*__tests__/[^/]+\\.(web|node)\\.(j|t)sx?$',
'<rootDir>/scripts',
],
setupFiles: [
...rnPreset.setupFiles,
'<rootDir>/scripts/testSetupNative.js',
],
transform: {
...baseConfig.transform,
'^.+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$':
require.resolve('@react-native/jest-preset/jest/assetFileTransformer.js'),
},
haste: rnPreset.haste,
},
];
module.exports = {
projects,
};