forked from facebook/docusaurus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.config.mjs
109 lines (100 loc) · 3.6 KB
/
jest.config.mjs
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
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import {fileURLToPath} from 'url';
process.env.TZ = 'UTC';
const ignorePatterns = [
'/node_modules/',
'__fixtures__',
'__mocks__',
'/testUtils.ts',
'/packages/docusaurus/lib',
'/packages/docusaurus-logger/lib',
'/packages/docusaurus-utils/lib',
'/packages/docusaurus-utils-common/lib',
'/packages/docusaurus-utils-validation/lib',
'/packages/docusaurus-plugin-content-blog/lib',
'/packages/docusaurus-plugin-content-docs/lib',
'/packages/docusaurus-plugin-content-pages/lib',
'/packages/docusaurus-theme-classic/lib',
'/packages/docusaurus-theme-common/lib',
'/packages/docusaurus-migrate/lib',
'/jest',
'/argos',
];
export default {
rootDir: fileURLToPath(new URL('.', import.meta.url)),
verbose: true,
setupFiles: ['./jest/setup.js'],
testEnvironmentOptions: {
url: 'https://docusaurus.io/',
},
testEnvironment: 'node',
testPathIgnorePatterns: ignorePatterns,
// Default 5s timeout often fails on Windows :s,
// see https://github.com/facebook/docusaurus/pull/8259
testTimeout: 15000,
coveragePathIgnorePatterns: [
...ignorePatterns,
// We also ignore all package entry points
'/packages/docusaurus-utils/src/index.ts',
],
transform: {
'^.+\\.[jt]sx?$': [
'@swc/jest',
{
jsc: {
parser: {
syntax: 'typescript',
tsx: true,
},
target: 'es2020',
},
},
],
},
errorOnDeprecated: true,
reporters: ['default', 'github-actions'],
moduleNameMapper: {
// Jest can't resolve CSS or asset imports
'^.+\\.(css|jpe?g|png|svg|webp)$': '<rootDir>/jest/emptyModule.ts',
// Using src instead of lib, so we always get fresh source
'@docusaurus/(BrowserOnly|ComponentCreator|constants|ExecutionEnvironment|Head|Interpolate|isInternalUrl|Link|Noop|renderRoutes|router|Translate|use.*)':
'@docusaurus/core/src/client/exports/$1',
// TODO create dedicated testing utility for mocking contexts
// Maybe point to a fixture?
'@generated/.*': '<rootDir>/jest/emptyModule.ts',
// TODO use "projects" + multiple configs if we work on another theme?
'@theme/(.*)': '@docusaurus/theme-classic/src/theme/$1',
'@site/(.*)': 'website/$1',
// Using src instead of lib, so we always get fresh source
'@docusaurus/plugin-content-docs/client':
'@docusaurus/plugin-content-docs/src/client/index.ts',
'@testing-utils/(.*)': '<rootDir>/jest/utils/$1.ts',
// MDX packages are ESM-only and it is a pain to use in Jest
// So we use them in Jest tests as CJS versions
// see https://mdxjs.com/docs/troubleshooting-mdx/#problems-integrating-mdx
'^unified$': '<rootDir>/jest/vendor/unified@10.1.2.js',
'^@mdx-js/mdx$': '<rootDir>/jest/vendor/@mdx-js__mdx@2.1.5.js',
'^remark$': '<rootDir>/jest/vendor/remark@14.0.2.js',
'^remark-mdx$': '<rootDir>/jest/vendor/remark-mdx@2.1.5.js',
'^remark-directive$': '<rootDir>/jest/vendor/remark-directive@2.0.1.js',
'^remark-gfm$': '<rootDir>/jest/vendor/remark-gfm@3.0.1.js',
'^estree-util-value-to-estree$':
'<rootDir>/jest/vendor/estree-util-value-to-estree@2.1.0.js',
'^mdast-util-to-string$':
'<rootDir>/jest/vendor/mdast-util-to-string@3.1.0.js',
},
snapshotSerializers: [
'<rootDir>/jest/snapshotPathNormalizer.ts',
'jest-serializer-ansi-escapes',
'jest-serializer-react-helmet-async',
],
snapshotFormat: {
escapeString: false,
printBasicPrototype: false,
},
};