-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathjest.config.js
50 lines (45 loc) · 1.44 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
const makeConfig = require('./packages/configs/jest/config')
const isRunningInEsmMode = !!process.env.TEST_ESM
/**
* These packages are authored using native ESModules, and so we want to configure jest differently to handle that
*
* TODO: determine this from "type": "module" in package.json
*/
const ESM_PACKAGES = ['content-conformance', 'remark-plugins', 'markdown-utils']
/**
* Override the base next jest-transformer to force it into ESM mode
*/
const esmConfig = {
extensionsToTreatAsEsm: ['.ts', '.tsx'],
transform: {
'^.+\\.(js|jsx|ts|tsx|mjs)$': [
require.resolve('next/dist/build/swc/jest-transformer.js'),
{
isEsmProject: true,
},
],
},
}
/**
* Exclude ESM-native packages from running when not in ESM mode
*/
const ignorePatternForModuleType = isRunningInEsmMode
? `<rootDir>/packages/(?!${ESM_PACKAGES.join('|')}).*/.*`
: `<rootDir>/packages/(${ESM_PACKAGES.join('|')})/.*`
module.exports = makeConfig({
testEnvironment: 'node',
verbose: true,
transformIgnorePatterns: [
'<rootDir>/packages/.*/__tests__/__fixtures__/.*',
'<rootDir>/packages/.*/__tests__/fixtures/.*.js',
],
testPathIgnorePatterns: [
ignorePatternForModuleType,
'<rootDir>/packages/.*/__tests__/fixtures/.*.js',
'<rootDir>/packages/.*/__tests__/__fixtures__/.*',
],
watchPathIgnorePatterns: [
'<rootDir>/packages/cli/__tests__/fixtures/prettier.js',
],
...(isRunningInEsmMode && esmConfig),
})