-
Notifications
You must be signed in to change notification settings - Fork 2
/
jest.config.js
75 lines (70 loc) · 2.24 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
/** @typedef {import('@jest/types').Config.InitialOptions} JestConfig */
const {ifAnyDep, hasFile, fromRoot, hasDevDep} = require('../utils')
const {
testMatch,
testMatchGlob,
testMatchExtensions,
} = require('./helpers/test-match')
const ignores = [
'/node_modules/',
'/__fixtures__/',
'/fixtures/',
'/__tests__/helpers/',
'/__tests__/utils/',
'__mocks__',
]
/** @type JestConfig */
const jestConfig = {
roots: [fromRoot('.')],
// Here we're preserving Jest <= 28 snapshot format to prevent the need
// to update snapshots when upgrading Jest via @hover/javascript, see:
// https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
snapshotFormat: {escapeString: true, printBasicPrototype: true},
testEnvironment: ifAnyDep(['webpack', 'rollup', 'react'], 'jsdom', 'node'),
testEnvironmentOptions: {url: 'http://localhost'},
moduleFileExtensions: testMatchExtensions.concat('json'),
collectCoverageFrom: [`**/${testMatchGlob}`],
testMatch,
testPathIgnorePatterns: [...ignores, '<rootDir>/dist'],
testLocationInResults: true,
// The default transform is now SWC, however, `ts-jest` will
// still be used if it is installed in the host project
transform: hasDevDep('ts-jest')
? Object.fromEntries(
// Ensure we can resolve the preset even when
// it's in a nested `node_modules` installation
Object.entries(require('ts-jest/presets').transform).map(
([glob, transformer]) => [
glob,
[require.resolve(transformer), {diagnostics: {warnOnly: true}}],
],
),
)
: {'^.+\\.(t|j)sx?$': ['@swc/jest']},
coveragePathIgnorePatterns: [
...ignores,
'src/(umd|cjs|esm)-entry.js$',
'<rootDir>/dist',
],
transformIgnorePatterns: [
'[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$',
'/dist/',
],
watchPathIgnorePatterns: ['<rootDir>/dist'],
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100,
},
},
watchPlugins: [
require.resolve('jest-watch-typeahead/filename'),
require.resolve('jest-watch-typeahead/testname'),
],
setupFilesAfterEnv: hasFile('tests/setup-env.js')
? [fromRoot('tests/setup-env.js')]
: undefined,
}
module.exports = jestConfig