Skip to content

Commit 63ede5a

Browse files
authored
test(ui): jest 30 (#93303)
[jest 30 changelog](https://jestjs.io/blog/2025/06/04/jest-30) the biggest change being the newer version of JSDOM which breaks a few things for us. Two major issues around window.location: > Can no longer assign mocks directly to the location object (location.assign(), location.replace()) now error when used. **solution:** test helper like `testableWindowLocation.assign()` that we mock out in tests > Can no longer directly set the url in tests `window.location.search = '?something=true'` **solution** make jsdom available as a global and use `jsdom.reconfigure({url: something})` which lets you set the url. getsentry/jest-sentry-environment#26
1 parent 9367b3f commit 63ede5a

File tree

14 files changed

+2104
-1740
lines changed

14 files changed

+2104
-1740
lines changed

babel.config.ts

Lines changed: 0 additions & 45 deletions
This file was deleted.

jest.config.ts

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,39 @@ import type {Config} from '@jest/types';
22
import path from 'node:path';
33
import process from 'node:process';
44
import {execFileSync} from 'node:child_process';
5+
import type {TransformOptions} from '@babel/core';
56

6-
import babelConfig from './babel.config';
7+
const babelConfig: TransformOptions = {
8+
presets: [
9+
[
10+
'@babel/preset-react',
11+
{
12+
runtime: 'automatic',
13+
importSource: '@emotion/react',
14+
},
15+
],
16+
[
17+
'@babel/preset-env',
18+
{
19+
useBuiltIns: 'usage',
20+
corejs: '3.41',
21+
targets: {
22+
node: 'current',
23+
},
24+
},
25+
],
26+
// TODO: Remove allowDeclareFields when we upgrade to Babel 8
27+
['@babel/preset-typescript', {allowDeclareFields: true, onlyRemoveTypeImports: true}],
28+
],
29+
plugins: [
30+
[
31+
'@emotion/babel-plugin',
32+
{
33+
sourceMap: false,
34+
},
35+
],
36+
],
37+
};
738

839
const {
940
CI,
@@ -18,14 +49,6 @@ const {
1849

1950
const IS_MASTER_BRANCH = GITHUB_PR_REF === 'refs/heads/master';
2051

21-
const BALANCE_RESULTS_PATH = path.resolve(
22-
__dirname,
23-
'tests',
24-
'js',
25-
'test-balancer',
26-
'jest-balance.json'
27-
);
28-
2952
const optionalTags: {
3053
balancer?: boolean;
3154
balancer_strategy?: string;
@@ -188,13 +211,22 @@ if (
188211
) {
189212
let balance: null | Record<string, number> = null;
190213

214+
const BALANCE_RESULTS_PATH = path.resolve(
215+
import.meta.dirname,
216+
'tests',
217+
'js',
218+
'test-balancer',
219+
'jest-balance.json'
220+
);
191221
try {
192222
balance = require(BALANCE_RESULTS_PATH);
193223
} catch (err) {
194224
// Just ignore if balance results doesn't exist
195225
}
196226
// Taken from https://github.com/facebook/jest/issues/6270#issue-326653779
197-
const envTestList: string[] = JEST_TESTS.map(file => file.replace(__dirname, ''));
227+
const envTestList: string[] = JEST_TESTS.map(file =>
228+
file.replace(import.meta.dirname, '')
229+
);
198230
const nodeTotal = Number(CI_NODE_TOTAL);
199231
const nodeIndex = Number(CI_NODE_INDEX);
200232

@@ -302,6 +334,7 @@ const config: Config.InitialOptions = {
302334
// To disable the sentry jest integration, set this to 'jsdom'
303335
testEnvironment: '@sentry/jest-environment/jsdom',
304336
testEnvironmentOptions: {
337+
globalsCleanup: 'on',
305338
sentryConfig: {
306339
init: {
307340
// jest project under Sentry organization (dev productivity team)

knip.config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ const config: KnipConfig = {
5959
},
6060
ignoreDependencies: [
6161
'core-js',
62-
'@babel/runtime', // used implicitly alongside @babel/plugin-transform-runtime
6362
'eslint-import-resolver-typescript', // used in eslint config
6463
'jest-environment-jsdom', // used as testEnvironment in jest config
6564
'swc-plugin-component-annotate', // used in rspack config, needs better knip plugin
@@ -69,7 +68,6 @@ const config: KnipConfig = {
6968
'@types/webpack-env', // needed to make require.context work
7069
'@types/stripe-v3', // needed for global `stripe` namespace typings
7170
'@types/gtag.js', // needed for global `gtag` namespace typings
72-
'@babel/plugin-transform-runtime', // Still used in jest
7371
'@babel/preset-env', // Still used in jest
7472
'@babel/preset-react', // Still used in jest
7573
'@babel/preset-typescript', // Still used in jest

package.json

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@
99
},
1010
"dependencies": {
1111
"@amplitude/analytics-browser": "^1.5.3",
12-
"@babel/core": "~7.26.10",
13-
"@babel/plugin-transform-runtime": "~7.26.10",
14-
"@babel/preset-env": "~7.26.9",
15-
"@babel/preset-react": "^7.26.3",
16-
"@babel/preset-typescript": "^7.26.0",
17-
"@babel/runtime": "~7.26.10",
12+
"@babel/core": "~7.28.0",
13+
"@babel/preset-env": "~7.28.0",
14+
"@babel/preset-react": "^7.27.1",
15+
"@babel/preset-typescript": "^7.27.1",
1816
"@dnd-kit/core": "^6.1.0",
1917
"@dnd-kit/sortable": "^8.0.0",
2018
"@dnd-kit/utilities": "^3.2.2",
@@ -86,7 +84,7 @@
8684
"@types/gtag.js": "^0.0.12",
8785
"@types/history": "^3.2.5",
8886
"@types/invariant": "^2.2.35",
89-
"@types/jest": "29.5.14",
87+
"@types/jest": "30.0.0",
9088
"@types/js-beautify": "^1.14.3",
9189
"@types/js-cookie": "3.0.6",
9290
"@types/lodash": "^4.14.182",
@@ -184,7 +182,7 @@
184182
"@emotion/eslint-plugin": "^11.12.0",
185183
"@eslint/js": "^9.22.0",
186184
"@sentry-internal/rrweb-types": "2.34.0",
187-
"@sentry/jest-environment": "6.0.0",
185+
"@sentry/jest-environment": "6.1.0",
188186
"@sentry/profiling-node": "9.35.0",
189187
"@styled/typescript-styled-plugin": "^1.0.1",
190188
"@tanstack/eslint-plugin-query": "^5.66.1",
@@ -194,13 +192,13 @@
194192
"@testing-library/user-event": "14.6.1",
195193
"@types/gettext-parser": "8.0.0",
196194
"@types/node": "^22.9.1",
197-
"babel-jest": "29.7.0",
195+
"babel-jest": "30.0.4",
198196
"eslint": "^9.22.0",
199197
"eslint-config-prettier": "^10.1.2",
200198
"eslint-import-resolver-typescript": "^3.8.3",
201199
"eslint-plugin-boundaries": "^5.0.1",
202200
"eslint-plugin-import": "2.32.0",
203-
"eslint-plugin-jest": "^28.11.0",
201+
"eslint-plugin-jest": "29.0.1",
204202
"eslint-plugin-jest-dom": "^5.5.0",
205203
"eslint-plugin-mdx": "^3.4.2",
206204
"eslint-plugin-no-relative-import-paths": "^1.6.1",
@@ -213,10 +211,10 @@
213211
"eslint-plugin-unicorn": "^57.0.0",
214212
"expect-type": "1.2.1",
215213
"globals": "^15.14.0",
216-
"jest": "29.7.0",
214+
"jest": "30.0.4",
217215
"jest-canvas-mock": "^2.5.2",
218-
"jest-environment-jsdom": "29.7.0",
219-
"jest-fail-on-console": "3.3.0",
216+
"jest-environment-jsdom": "30.0.4",
217+
"jest-fail-on-console": "3.3.1",
220218
"jest-junit": "16.0.0",
221219
"knip": "^5.60.0",
222220
"postcss-styled-syntax": "0.7.0",
@@ -244,11 +242,11 @@
244242
"APIMethod": "stub",
245243
"proxyURL": "http://localhost:8000",
246244
"scripts": {
247-
"test": "node scripts/test.js --watch",
248-
"test-ci": "node scripts/test.js --ci --maxWorkers=100% --colors",
249-
"test-debug": "node --inspect-brk scripts/test.js --runInBand",
250-
"test-precommit": "node scripts/test.js --bail --findRelatedTests -u",
251-
"test-staged": "node scripts/test.js --findRelatedTests $(git diff --name-only --cached)",
245+
"test": "NODE_OPTIONS='--experimental-transform-types' node scripts/test.js --watch",
246+
"test-ci": "NODE_OPTIONS='--experimental-transform-types' node scripts/test.js --ci --maxWorkers=100% --colors",
247+
"test-debug": "NODE_OPTIONS='--experimental-transform-types' node --inspect-brk scripts/test.js --runInBand",
248+
"test-precommit": "NODE_OPTIONS='--experimental-transform-types' node scripts/test.js --bail --findRelatedTests -u",
249+
"test-staged": "NODE_OPTIONS='--experimental-transform-types' node scripts/test.js --findRelatedTests $(git diff --name-only --cached)",
252250
"lint": "pnpm run lint:prettier && pnpm run lint:js && pnpm run lint:css",
253251
"lint:js": "eslint",
254252
"lint:css": "stylelint '**/*.[jt]sx'",
@@ -275,7 +273,7 @@
275273
"validate-api-examples": "pnpm run --dir api-docs openapi-examples-validator ../tests/apidocs/openapi-derefed.json --no-additional-properties",
276274
"mkcert-localhost": "mkcert -key-file config/localhost-key.pem -cert-file config/localhost.pem localhost 127.0.0.1 dev.getsentry.net *.dev.getsentry.net && mkcert -install",
277275
"https-proxy": "caddy run --config - <<< '{\"apps\":{\"http\":{\"servers\":{\"srv0\":{\"listen\":[\":8003\"],\"routes\":[{\"handle\":[{\"handler\":\"reverse_proxy\",\"upstreams\":[{\"dial\":\"localhost:8000\"}]}]}],\"tls_connection_policies\":[{\"certificate_selection\":{\"any_tag\":[\"cert0\"]}}]}}},\"tls\":{\"certificates\":{\"load_files\":[{\"certificate\":\"./config/localhost.pem\",\"key\":\"./config/localhost-key.pem\",\"tags\":[\"cert0\"]}]}}}}'",
278-
"knip": "knip --treat-config-hints-as-errors",
276+
"knip": "NODE_OPTIONS='--experimental-transform-types' knip --treat-config-hints-as-errors",
279277
"knip:prod": "pnpm run knip --production --exclude exports,types,dependencies,unresolved"
280278
},
281279
"browserslist": {

0 commit comments

Comments
 (0)