Skip to content

chore(jest): Final Jest cleanup #15549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = {
},
},
{
files: ['jest/**/*.ts', 'scripts/**/*.ts'],
files: ['scripts/**/*.ts'],
parserOptions: {
project: ['tsconfig.dev.json'],
},
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ scratch/
# side effects of running AWS lambda layer zip action locally
dist-serverless/
sentry-node-serverless-*.zip
# transpiled transformers
jest/transformers/*.js
# node tarballs
packages/*/sentry-*.tgz
.nxcache
Expand Down
29 changes: 0 additions & 29 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,35 +52,6 @@
"internalConsoleOptions": "openOnSessionStart",
"outputCapture": "std"
},
// Run a specific test file in watch mode (must have file in currently active tab when hitting the play button).
// NOTE: If you try to run this and VSCode complains that the command `shellCommand.execute` can't be found, go
// install the recommended extension Tasks Shell Input.
{
"name": "Debug unit tests - just open file",
"type": "node",
"cwd": "${workspaceFolder}/packages/${input:getPackageName}",
"request": "launch",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": [
"--watch",
// this runs one test at a time, rather than running them in parallel (necessary for debugging so that you know
// you're hitting a single test's breakpoints, in order)
"--runInBand",
// coverage messes up the source maps
"--coverage",
"false",
// remove this to run all package tests
"${relativeFile}"
],
"sourceMaps": true,
"smartStep": true,
// otherwise it goes to the VSCode debug terminal, which prints the test output or console logs (depending on
// "outputCapture" option here; default is to show console logs), but not both
"console": "integratedTerminal",
// since we're not using it, don't automatically switch to it
"internalConsoleOptions": "neverOpen"
},

// Run a specific test file in watch mode (must have file in currently active tab when hitting the play button).
// NOTE: If you try to run this and VSCode complains that the command `shellCommand.execute` can't be found, go
// install the recommended extension Tasks Shell Input.
Expand Down
17 changes: 0 additions & 17 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,6 @@ the tests in each location. Check out the `scripts` entry of the corresponding `

Note: you must run `yarn build` before `yarn test` will work.

## Debugging Tests

If you run into trouble writing tests and need to debug one of them, you can do so using VSCode's debugger.

0. If you don't already have it installed, install the Tasks Shell Input extension, which you'll find in the Extensions
tab in the sidebar as one of the recommended workspace extensions.

1. Place breakpoints or `debugger` statements in the test or the underlying code wherever you'd like `jest` to pause.
2. Open the file containing the test in question, and make sure its tab is active (so you can see the file's contents).
3. Switch to the debugger in the sidebar and choose `Debug unit tests - just open file` from the dropdown.
4. Click the green "play" button to run the tests in the open file in watch mode.

Pro tip: If any of your breakpoints are in code run by multiple tests, and you run the whole test file, you'll land on
those breakpoints over and over again, in the middle of tests you don't care about. To avoid this, replace the test's
initial `it` or `test` with `it.only` or `test.only`. That way, when you hit a breakpoint, you'll know you got there are
part of the buggy test.

## Debug Build Flags

Throughout the codebase, you will find a `__DEBUG_BUILD__` constant. This flag serves two purposes:
Expand Down
1 change: 0 additions & 1 deletion dev-packages/node-integration-tests/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module.exports = {
env: {
node: true,
jest: true,
},
extends: ['../../.eslintrc.js'],
overrides: [
Expand Down
6 changes: 2 additions & 4 deletions dev-packages/node-integration-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ folders containing test scenarios and assertions.
`runServer` also accepts an optional `scenarioPath` argument for non-standard usage.

`test.ts` is required for each test case, and contains the server runner logic, request interceptors for Sentry
requests, and assertions. Test server, interceptors and assertions are all run on the same Jest thread.
requests, and assertions. Test server, interceptors and assertions are all run on the same Vitest thread.

### Utilities

Expand All @@ -40,12 +40,10 @@ Tests can be run locally with:

`yarn test`

To run tests with Jest's watch mode:
To run tests with Vitest's watch mode:

`yarn test:watch`

To filter tests by their title:

`yarn test -t "set different properties of a scope"`

You can refer to [Jest documentation](https://jestjs.io/docs/cli) for other CLI options.
2 changes: 1 addition & 1 deletion dev-packages/node-integration-tests/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"lib": ["DOM", "ES2018"],
// package-specific options
"esModuleInterop": true,
"types": ["node", "jest"]
"types": ["node"]
}
}
43 changes: 0 additions & 43 deletions jest/jest.config.js

This file was deleted.

7 changes: 1 addition & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"circularDepCheck": "lerna run circularDepCheck",
"clean": "run-s clean:build clean:caches",
"clean:build": "lerna run clean",
"clean:caches": "yarn rimraf eslintcache .nxcache .nx && yarn jest --clearCache",
"clean:caches": "yarn rimraf eslintcache .nxcache .nx",
"clean:deps": "lerna clean --yes && rm -rf node_modules && yarn",
"clean:tarballs": "rimraf {packages,dev-packages}/*/*.tgz",
"clean:watchman": "watchman watch-del \".\"",
Expand Down Expand Up @@ -110,17 +110,13 @@
"@rollup/pluginutils": "^5.1.0",
"@size-limit/file": "~11.1.6",
"@size-limit/webpack": "~11.1.6",
"@types/jest": "^27.4.1",
"@types/jsdom": "^21.1.6",
"@types/node": "^18.19.1",
"@vitest/coverage-v8": "^2.1.8",
"deepmerge": "^4.2.2",
"downlevel-dts": "~0.11.0",
"es-check": "^7.2.1",
"eslint": "7.32.0",
"jest": "^27.5.1",
"jest-environment-node": "^27.5.1",
"jest-junit": "^16.0.0",
"jsdom": "^21.1.2",
"lerna": "7.1.1",
"madge": "7.0.0",
Expand All @@ -133,7 +129,6 @@
"rollup-plugin-license": "^3.3.1",
"size-limit": "~11.1.6",
"sucrase": "^3.35.0",
"ts-jest": "^27.1.4",
"ts-node": "10.9.1",
"typescript": "~5.0.0",
"vitest": "^2.1.8",
Expand Down
2 changes: 0 additions & 2 deletions packages/core/test/utils-hoist/misc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,6 @@ describe('checkOrSetAlreadyCaught()', () => {

describe('uuid4 generation', () => {
const uuid4Regex = /^[0-9A-F]{12}[4][0-9A-F]{3}[89AB][0-9A-F]{15}$/i;
// Jest messes with the global object, so there is no global crypto object in any node version
// For this reason we need to create our own crypto object for each test to cover all the code paths
it('returns valid uuid v4 ids via Math.random', () => {
for (let index = 0; index < 1_000; index++) {
expect(uuid4()).toMatch(uuid4Regex);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/utils-hoist/normalize.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @jest-environment jsdom
* @vitest-environment jsdom
*/

import { describe, expect, test, vi } from 'vitest';
Expand Down
11 changes: 2 additions & 9 deletions packages/core/test/utils-hoist/object.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @jest-environment jsdom
* @vitest-environment jsdom
*/

import type { WrappedFunction } from '../../src/types-hoist';
Expand Down Expand Up @@ -331,17 +331,10 @@ describe('objectify()', () => {
});

describe('wraps other primitives with their respective object wrapper classes', () => {
// TODO: There's currently a bug in Jest - if you give it the `Boolean` class, it runs `typeof received ===
// 'boolean'` but not `received instanceof Boolean` (the way it correctly does for other primitive wrappers, like
// `Number` and `String). (See https://github.com/facebook/jest/pull/11976.) Once that is fixed and we upgrade jest,
// we can comment the test below back in. (The tests for symbols and bigints are working only because our current
// version of jest is sufficiently old that they're not even considered in the relevant check and just fall to the
// default `instanceof` check jest uses for all unknown classes.)

it.each([
['number', Number, 1121],
['string', String, 'Dogs are great!'],
// ["boolean", Boolean, true],
['boolean', Boolean, true],
['symbol', Symbol, Symbol('Maisey')],
])('%s', (_caseName, wrapperClass, primitive) => {
const objectifiedPrimitive = objectify(primitive);
Expand Down
1 change: 0 additions & 1 deletion packages/eslint-config-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-deprecation": "^1.5.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jest": "^27.2.2",
"eslint-plugin-jsdoc": "^30.0.3",
"eslint-plugin-simple-import-sort": "^5.0.3"
},
Expand Down
4 changes: 0 additions & 4 deletions packages/eslint-config-sdk/src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,6 @@ module.exports = {
},
},
{
// Configuration for files in test directories
env: {
jest: true,
},
files: [
'test.ts',
'*.test.ts',
Expand Down
1 change: 0 additions & 1 deletion packages/gatsby/tsconfig.plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

"compilerOptions": {
// should include all types from `./tsconfig.json` plus types for all test frameworks used
// "types": ["node", "jest"]
"declaration": true,
"declarationMap": false,
"emitDeclarationOnly": true,
Expand Down
1 change: 0 additions & 1 deletion packages/node/jest.config.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/node/test/helpers/conditional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const NODE_VERSION = parseSemver(process.versions.node).major;
* Returns`describe` or `describe.skip` depending on allowed major versions of Node.
*
* @param {{ min?: number; max?: number }} allowedVersion
* @return {*} {jest.Describe}
*/
export const conditionalTest = (allowedVersion: { min?: number; max?: number }) => {
if (!NODE_VERSION) {
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

"compilerOptions": {
// should include all types from `./tsconfig.json` plus types for all test frameworks used
"types": ["node", "vitest/globals"]
"types": ["node"]
}
}
2 changes: 1 addition & 1 deletion packages/react-router/tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"include": ["test/**/*", "vite.config.ts"],

"compilerOptions": {
"types": ["node", "vitest/globals"],
"types": ["node"],
}
}
2 changes: 1 addition & 1 deletion packages/remix/test/integration/tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"include": ["test/**/*"],

"compilerOptions": {
"types": ["node", "vitest/globals"]
"types": ["node"]
}
}
2 changes: 1 addition & 1 deletion packages/solidstart/tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

"compilerOptions": {
// should include all types from `./tsconfig.json` plus types for all test frameworks used
"types": ["node", "vitest/globals", "vite/client", "@testing-library/jest-dom"],
"types": ["node", "@testing-library/jest-dom"],

// other package-specific, test-specific options
"jsx": "preserve",
Expand Down
2 changes: 1 addition & 1 deletion tsconfig-templates/tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

"compilerOptions": {
// should include all types from `./tsconfig.json` plus types for all test frameworks used
"types": ["jest"]
"types": []

// other package-specific, test-specific options
}
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
{
"extends": "./tsconfig.json",

"include": ["**/scripts/**/*.ts", "jest/**/*.ts", "vite/**/*.ts"],
"include": ["**/scripts/**/*.ts", "vite/**/*.ts"],

"compilerOptions": {
"types": ["node", "jest", "vitest/globals"]
"types": ["node"]
}
}
Loading
Loading