Skip to content

Commit 611c19f

Browse files
authored
Move Jest config from package.json to jest.config.js (#5680)
Having this config outside of package.json is consistent with the rest of our configurations. It also lets us add comments. And it will make it easier to add other test environments, for example if we want to test how code runs in a pure node environment rather than in the browser-like environment.
2 parents 5b5dbc8 + d871bb8 commit 611c19f

File tree

2 files changed

+40
-33
lines changed

2 files changed

+40
-33
lines changed

jest.config.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
module.exports = {
6+
testMatch: ['<rootDir>/src/**/*.test.{js,jsx,ts,tsx}'],
7+
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx'],
8+
9+
testEnvironment: './src/test/custom-environment',
10+
setupFilesAfterEnv: ['jest-extended/all', './src/test/setup.ts'],
11+
12+
collectCoverageFrom: [
13+
'src/**/*.{js,jsx,ts,tsx}',
14+
'!**/node_modules/**',
15+
'!src/types/libdef/**',
16+
],
17+
18+
// Transform ESM modules to CommonJS for Jest
19+
// These packages ship as pure ESM and need to be transformed by Babel
20+
transformIgnorePatterns: [
21+
'/node_modules/(?!(query-string|decode-uri-component|iongraph-web|split-on-first|filter-obj|fetch-mock)/)',
22+
],
23+
24+
// Mock static assets (images, CSS, etc.)
25+
moduleNameMapper: {
26+
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|ftl)$':
27+
'<rootDir>/src/test/fixtures/mocks/file-mock.ts',
28+
'\\.(css|less)$': '<rootDir>/src/test/fixtures/mocks/style-mock.ts',
29+
},
30+
31+
globals: {
32+
AVAILABLE_STAGING_LOCALES: null,
33+
},
34+
35+
snapshotFormat: {
36+
escapeString: true,
37+
printBasicPrototype: true,
38+
},
39+
verbose: false,
40+
};

package.json

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -194,39 +194,6 @@
194194
"@types/react-splitter-layout/@types/react": "^18.3.26",
195195
"@types/trusted-types": "^2.0.7"
196196
},
197-
"jest": {
198-
"collectCoverageFrom": [
199-
"src/**/*.{js,jsx,ts,tsx}",
200-
"!**/node_modules/**",
201-
"!src/types/libdef/**"
202-
],
203-
"moduleFileExtensions": [
204-
"js",
205-
"jsx",
206-
"ts",
207-
"tsx"
208-
],
209-
"transformIgnorePatterns": [
210-
"/node_modules/(?!(query-string|decode-uri-component|iongraph-web|split-on-first|filter-obj|fetch-mock)/)"
211-
],
212-
"moduleNameMapper": {
213-
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|ftl)$": "<rootDir>/src/test/fixtures/mocks/file-mock.ts",
214-
"\\.(css|less)$": "<rootDir>/src/test/fixtures/mocks/style-mock.ts"
215-
},
216-
"setupFilesAfterEnv": [
217-
"jest-extended/all",
218-
"./src/test/setup.ts"
219-
],
220-
"globals": {
221-
"AVAILABLE_STAGING_LOCALES": null
222-
},
223-
"snapshotFormat": {
224-
"escapeString": true,
225-
"printBasicPrototype": true
226-
},
227-
"testEnvironment": "./src/test/custom-environment",
228-
"verbose": false
229-
},
230197
"husky": {
231198
"hooks": {
232199
"post-checkout": "node bin/post-checkout.js",

0 commit comments

Comments
 (0)