Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 4002774

Browse files
sqsburmudar
andauthored
reapply "switch from jest to vitest for faster, simpler tests (#57886)" (#58145)
* reapply "switch from jest to vitest for faster, simpler tests (https://github.com/sourcegraph/sourcegraph/pull/57886)" This was reverted in https://github.com/sourcegraph/sourcegraph/pull/58116 due to an issue with the browser tests. * include fetch-mock * fix flakiness * rm mock that did not work in experimentalVmThreads * fix * timeout * fixup --------- Co-authored-by: William Bezuidenhout <[email protected]>
1 parent e0f401a commit 4002774

File tree

570 files changed

+2033
-3463
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

570 files changed

+2033
-3463
lines changed

Diff for: .eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const config = {
2222
'**/*.json',
2323
'**/*.d.ts',
2424
'eslint-relative-formatter.js',
25-
'jest.config.js',
2625
'typedoc.js',
2726
'bundlesize.config.js',
2827
],
@@ -135,6 +134,7 @@ See https://handbook.sourcegraph.com/community/faq#is-all-of-sourcegraph-open-so
135134
'!@sourcegraph/*/src/stories',
136135
'!@sourcegraph/build-config/src/esbuild/*',
137136
'!@sourcegraph/build-config/src/*',
137+
'!@sourcegraph/testing/src/jestDomMatchers',
138138
],
139139
message:
140140
'Imports from package internals are banned. Add relevant export to the entry point of the package to import it from the outside world.',

Diff for: .mocharc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = {
55
require: [
66
...(IS_BAZEL ? [] : ['ts-node/register/transpile-only']),
77
'abort-controller/polyfill',
8-
rootDir + '/client/shared/dev/fetch',
8+
rootDir + '/client/testing/src/fetch',
99
rootDir + '/client/shared/dev/suppressPollyErrors',
1010
],
1111
reporter: rootDir + '/client/shared/dev/customMochaSpecReporter.js',

Diff for: .vscode/extensions.json

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"exiasr.hadolint",
1212
"bierner.markdown-mermaid",
1313
"ecmel.vscode-html-css",
14-
"orta.vscode-jest",
1514
"dbaeumer.vscode-eslint",
1615
"foxundermoon.shell-format",
1716
"timonwong.shellcheck",

Diff for: .vscode/launch.json

-22
Original file line numberDiff line numberDiff line change
@@ -74,28 +74,6 @@
7474
"E2E_BROWSER": "chrome"
7575
}
7676
},
77-
{
78-
"type": "node",
79-
"name": "vscode-jest-tests",
80-
"request": "launch",
81-
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
82-
"args": [
83-
"--color",
84-
"--runInBand"
85-
// "path/to/test/file",
86-
// "-t",
87-
// "test name",
88-
],
89-
"cwd": "${workspaceFolder}",
90-
"console": "integratedTerminal",
91-
"internalConsoleOptions": "neverOpen",
92-
"skipFiles": [
93-
"**/async_hooks.js",
94-
"**/inspector_async_hook.js"
95-
// "**/node_modules/rxjs",
96-
],
97-
"smartStep": false
98-
},
9977
{
10078
"name": "Webapp Chrome",
10179
"type": "chrome",

Diff for: .vscode/settings.json

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
"build.allowImplicitNetworkAccess": true,
3838
"local": "github.com/sourcegraph/sourcegraph"
3939
},
40-
"jest.jestCommandLine": "pnpm run test",
4140
"npm.packageManager": "pnpm",
4241
"npm.runSilent": true,
4342
"typescript.preferences.quoteStyle": "single",

Diff for: BUILD.bazel

+4-42
Original file line numberDiff line numberDiff line change
@@ -83,58 +83,20 @@ copy_to_bin(
8383
)
8484

8585
js_library(
86-
name = "jest_config",
86+
name = "vitest_config",
8787
testonly = True,
8888
srcs = [
89-
"jest.config.base.js",
90-
],
91-
data = [
92-
"jest.snapshot-resolver.js",
89+
"vitest.shared.ts",
9390
],
9491
visibility = ["//visibility:public"],
9592
deps = [
96-
":babel_config_jest",
9793
"//:node_modules/@testing-library/jest-dom",
9894
"//:node_modules/abort-controller",
99-
"//:node_modules/babel-jest",
10095
"//:node_modules/core-js",
10196
"//:node_modules/identity-obj-proxy",
10297
"//:node_modules/message-port-polyfill",
10398
"//:node_modules/regenerator-runtime",
104-
"//client/shared/dev:mock",
105-
],
106-
)
107-
108-
js_library(
109-
name = "babel_config_jest",
110-
testonly = True,
111-
srcs = [
112-
"babel.config.jest.js",
113-
],
114-
visibility = ["//visibility:public"],
115-
deps = [
116-
"//:node_modules/@babel/preset-env",
117-
"//:node_modules/@babel/runtime",
118-
"//:node_modules/signale",
119-
],
120-
)
121-
122-
js_library(
123-
name = "babel_config",
124-
srcs = [
125-
"babel.config.js",
126-
],
127-
data = [
128-
":package_json",
129-
],
130-
visibility = ["//visibility:public"],
131-
deps = [
132-
"//:node_modules/@babel/preset-env",
133-
"//:node_modules/@babel/preset-react",
134-
"//:node_modules/@babel/preset-typescript",
135-
"//:node_modules/@babel/runtime",
136-
"//:node_modules/semver",
137-
"//:node_modules/signale",
99+
"//client/testing:testing_lib",
138100
],
139101
)
140102

@@ -146,9 +108,9 @@ js_library(
146108
],
147109
deps = [
148110
"//:node_modules/abort-controller",
149-
"//client/shared/dev:fetch-mock",
150111
"//client/shared/dev:mocha-reporter",
151112
"//client/shared/dev:suppress-polly-errors",
113+
"//client/testing:fetch-mock",
152114
],
153115
)
154116

Diff for: WORKSPACE

-23
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,6 @@ http_archive(
4242
url = "https://github.com/aspect-build/rules_ts/releases/download/v2.0.0/rules_ts-v2.0.0.tar.gz",
4343
)
4444

45-
http_archive(
46-
name = "aspect_rules_jest",
47-
sha256 = "bf8f4a4d2a833e4f96f866c686c38bcee69d3bdae8a827b1c9d2fdf92212bc0b",
48-
strip_prefix = "rules_jest-95d8f1961a9c6f3aee2929881b1b74461652e775",
49-
url = "https://github.com/aspect-build/rules_jest/archive/95d8f1961a9c6f3aee2929881b1b74461652e775.tar.gz",
50-
)
51-
5245
http_archive(
5346
name = "aspect_rules_swc",
5447
sha256 = "8eb9e42ed166f20cacedfdb22d8d5b31156352eac190fc3347db55603745a2d8",
@@ -197,22 +190,6 @@ load("@aspect_rules_ts//ts:repositories.bzl", "rules_ts_dependencies")
197190

198191
rules_ts_dependencies(ts_version = "4.9.5")
199192

200-
# rules_jest setup ==============================
201-
load("@aspect_rules_jest//jest:dependencies.bzl", "rules_jest_dependencies")
202-
203-
rules_jest_dependencies()
204-
205-
load("@aspect_rules_jest//jest:repositories.bzl", "jest_repositories")
206-
207-
jest_repositories(
208-
name = "jest",
209-
jest_version = "v28.1.0",
210-
)
211-
212-
load("@jest//:npm_repositories.bzl", jest_npm_repositories = "npm_repositories")
213-
214-
jest_npm_repositories()
215-
216193
# rules_swc setup ==============================
217194
load("@aspect_rules_swc//swc:dependencies.bzl", "rules_swc_dependencies")
218195

Diff for: babel.config.jest.js

-30
This file was deleted.

Diff for: babel.config.js

-36
This file was deleted.

Diff for: client/BUILD.bazel

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# gazelle:js_files globals.d.ts
66

77
# Test files, snapshots etc:
8-
# gazelle:js_test_files **/*.{spec,test}.{ts,tsx}
8+
# gazelle:js_test_files **/*.test.{ts,tsx}
99
# gazelle:js_test_files **/mock*.{ts,tsx}
1010
# gazelle:js_test_files **/*.{mock,mocks}.{ts,tsx}
1111
# gazelle:js_test_files **/mocks/**
@@ -16,6 +16,10 @@
1616
# gazelle:js_test_files **/WebStory.{ts,tsx}
1717
# TODO(bazel): sveltekit tests
1818
# gazelle:exclude **/web-sveltekit/**/*.ts
19+
# gazelle:exclude **/vitest.config.ts
20+
21+
# Otherwise it gets tripped up on the `declare module 'vitest'` directives to add custom matchers.
22+
# gazelle:js_resolve vitest //:node_modules/vitest
1923

2024
# TODO(bazel): put fixtures + testutils + ? into own rules
2125
# js_{fixture}_files **/*.{fixture,fixtures}.{ts,tsx}

Diff for: client/app-shell/tsconfig.json

-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
"extends": "../../tsconfig.base.json",
33
"compilerOptions": {
44
"module": "esnext",
5-
"baseUrl": ".",
6-
"paths": {
7-
"*": ["src/types/*", "../shared/src/types/*", "../common/src/types/*", "*"],
8-
},
95
"jsx": "react-jsx",
106
"rootDir": "./src",
117
"outDir": "out",

Diff for: client/branded/BUILD.bazel

+10-13
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
load("@npm//:defs.bzl", "npm_link_all_packages")
2-
load("//dev:defs.bzl", "jest_test", "npm_package", "sass", "ts_project")
2+
load("//dev:defs.bzl", "npm_package", "sass", "ts_project", "vitest_test")
33
load("//client/shared/dev:tools.bzl", "module_style_typings")
44
load("//dev:eslint.bzl", "eslint_config_and_lint_root", "eslint_test_with_types")
55

66
# TODO(bazel): storybook build
77
# gazelle:exclude **/*.story.{ts,tsx}
8-
# gazelle:exclude **/testGlobals.d.ts
98

109
# gazelle:js_resolve **/*.module.scss :module_style_typings
1110

@@ -25,7 +24,6 @@ eslint_test_with_types(
2524
]),
2625
config = ":eslint_config",
2726
deps = [
28-
"//:jest_config", # required for import/extensions rule not to fail on the `jest.config.base` import.
2927
"//:node_modules/@types/node",
3028
],
3129
)
@@ -36,8 +34,6 @@ ts_config(
3634
visibility = ["//client:__subpackages__"],
3735
deps = [
3836
"//:tsconfig",
39-
"//client/client-api:tsconfig",
40-
"//client/codeintellify:tsconfig",
4137
"//client/common:tsconfig",
4238
"//client/extension-api-types:tsconfig",
4339
"//client/observability-client:tsconfig",
@@ -170,7 +166,6 @@ ts_project(
170166
tsconfig = ":tsconfig",
171167
deps = [
172168
":module_style_typings",
173-
":node_modules/@sourcegraph/codeintellify", #keep
174169
":node_modules/@sourcegraph/common",
175170
":node_modules/@sourcegraph/http-client",
176171
":node_modules/@sourcegraph/observability-client",
@@ -191,7 +186,6 @@ ts_project(
191186
"//:node_modules/@types/react",
192187
"//:node_modules/@types/react-dom",
193188
"//:node_modules/classnames",
194-
"//:node_modules/comlink", #keep
195189
"//:node_modules/copy-to-clipboard",
196190
"//:node_modules/date-fns",
197191
"//:node_modules/dompurify",
@@ -241,7 +235,7 @@ ts_project(
241235
"src/search-ui/results/sidebar/SearchFilterSection.test.tsx",
242236
"src/search-ui/results/sidebar/helpers.test.ts",
243237
"src/search-ui/results/use-items-to-show.test.ts",
244-
"src/testGlobals.d.ts", #keep
238+
"src/testSetup.test.ts",
245239
],
246240
tsconfig = ":tsconfig",
247241
deps = [
@@ -251,7 +245,6 @@ ts_project(
251245
":node_modules/@sourcegraph/wildcard",
252246
"//:node_modules/@codemirror/autocomplete",
253247
"//:node_modules/@codemirror/state",
254-
"//:node_modules/@jest/globals",
255248
"//:node_modules/@testing-library/jest-dom", #keep
256249
"//:node_modules/@testing-library/react",
257250
"//:node_modules/@testing-library/user-event",
@@ -267,6 +260,7 @@ ts_project(
267260
"//:node_modules/react-dom",
268261
"//:node_modules/rxjs",
269262
"//:node_modules/sinon",
263+
"//:node_modules/vitest",
270264
],
271265
)
272266

@@ -279,13 +273,16 @@ npm_package(
279273
],
280274
)
281275

282-
jest_test(
276+
filegroup(
277+
name = "snapshots",
278+
srcs = glob(["src/**/__snapshots__/*"]),
279+
)
280+
281+
vitest_test(
283282
name = "test",
284283
timeout = "long",
285284
data = [
286285
":branded_tests",
286+
":snapshots",
287287
],
288-
patch_node_fs = False,
289-
shard_count = 6,
290-
tags = ["no-sandbox"],
291288
)

Diff for: client/branded/jest.config.js

-11
This file was deleted.

Diff for: client/branded/package.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99
"storybook": "STORIES_GLOB='client/branded/src/**/*.story.tsx' pnpm --filter @sourcegraph/storybook run start",
1010
"lint:js": "eslint --cache '**/*.[jt]s?(x)'",
1111
"lint:css": "stylelint 'src/**/*.scss' --quiet",
12-
"test": "jest"
12+
"test": "vitest"
1313
},
1414
"devDependencies": {
1515
"@sourcegraph/extension-api-types": "workspace:*",
1616
"@sourcegraph/testing": "workspace:*"
1717
},
1818
"dependencies": {
19-
"@sourcegraph/client-api": "workspace:*",
20-
"@sourcegraph/codeintellify": "workspace:*",
2119
"@sourcegraph/common": "workspace:*",
2220
"@sourcegraph/observability-client": "workspace:*",
2321
"@sourcegraph/shared": "workspace:*",

0 commit comments

Comments
 (0)