Skip to content

Commit 85415e4

Browse files
refactor: Switch to Vitest from Jest (#4955)
* refactor: Switch from jest to vitest * test: Update all tests to use vi instead of jest
1 parent e4eb732 commit 85415e4

File tree

10 files changed

+434
-3192
lines changed

10 files changed

+434
-3192
lines changed

.tours/app.tour

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
},
3939
{
4040
"file": "app/src/components/trace/__tests__/utils.test.ts",
41-
"description": "The fontend also utilizes `jest` to run unit tests to make sure certain code paths are properly tested. All tests can be run via the `npm` command `npm run test` which runs all the tests that fall under `__tests__` directories with the postfix `.test.ts`.",
41+
"description": "The fontend also utilizes `vitest` to run unit tests to make sure certain code paths are properly tested. All tests can be run via the `npm` command `npm run test` which runs all the tests that fall under `__tests__` directories with the postfix `.test.ts`.",
4242
"line": 4
4343
},
4444
{
@@ -57,4 +57,4 @@
5757
"line": 3
5858
}
5959
]
60-
}
60+
}

app/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ The web build ensures that the UI as well as the data-fetching layer is fully ty
3636

3737
## Test
3838

39-
The Phoenix app is statically analyzed for type safety via `typescript`, statically analyzed for best practices via [eslint](https://eslint.org/), and the formatting is enforced via the `prettier` code formatter. For unit testing, the app leverages [jest](https://jestjs.io/) as a unit testing framework. Lastly, for integration tests (e.g. end-to-end or e2e), [playwright](playwright.dev) is used. The following `pnpm` commands correspond to the above safeguards.
39+
The Phoenix app is statically analyzed for type safety via `typescript`, statically analyzed for best practices via [eslint](https://eslint.org/), and the formatting is enforced via the `prettier` code formatter. For unit testing, the app leverages [vitest](https://vitest.dev/) as a unit testing framework. Lastly, for integration tests (e.g. end-to-end or e2e), [playwright](playwright.dev) is used. The following `pnpm` commands correspond to the above safeguards.
4040

4141
```shell
4242
pnpm run typecheck

app/__tests__/authFetch.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import { authFetch } from "@phoenix/authFetch";
2-
jest.mock("@phoenix/config");
2+
vi.mock("@phoenix/config");
33

44
describe("authFetch", () => {
55
const _fetch = global.fetch;
66
afterEach(() => {
7-
jest.clearAllMocks();
7+
vi.clearAllMocks();
88
});
99

1010
afterEach(() => {
1111
global.fetch = _fetch;
1212
});
1313
it("should call fetch with the provided input and init", async () => {
1414
// @ts-expect-error mock global fetch
15-
global.fetch = jest.fn(() =>
15+
global.fetch = vi.fn(() =>
1616
Promise.resolve({
1717
json: () => Promise.resolve({ data: "12345" }),
1818
})
@@ -31,7 +31,7 @@ describe("authFetch", () => {
3131
it("should try to refresh the tokens if it gets a 401", async () => {
3232
let count = 0;
3333
// @ts-expect-error mock global fetch
34-
global.fetch = jest.fn(() => {
34+
global.fetch = vi.fn(() => {
3535
count += 1;
3636
return Promise.resolve({
3737
status: count === 1 ? 401 : 200,

app/jest.config.js

-17
This file was deleted.

app/package.json

+4-7
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
"@types/d3-format": "^3.0.4",
5555
"@types/d3-scale-chromatic": "^3.0.3",
5656
"@types/d3-time-format": "^4.0.3",
57-
"@types/jest": "^29.5.12",
5857
"@types/lodash": "^4.17.7",
5958
"@types/node": "^22.5.4",
6059
"@types/react": "18.3.10",
@@ -67,30 +66,28 @@
6766
"@typescript-eslint/parser": "^7.16.1",
6867
"@vitejs/plugin-react": "^4.3.1",
6968
"cpy-cli": "^5.0.0",
70-
"esbuild-jest": "^0.5.0",
7169
"eslint": "^8.57.0",
7270
"eslint-plugin-react": "^7.34.4",
7371
"eslint-plugin-react-compiler": "0.0.0-experimental-42acc6a-20241001",
7472
"eslint-plugin-react-hooks": "^4.6.2",
7573
"eslint-plugin-simple-import-sort": "^10.0.0",
7674
"graphql": "^16.9.0",
77-
"jest": "^29.7.0",
78-
"jest-environment-jsdom": "^29.7.0",
75+
"jsdom": "^25.0.1",
7976
"only-allow": "^1.2.1",
8077
"prettier": "^3.3.3",
8178
"relay-compiler": "^16.2.0",
8279
"rollup-plugin-visualizer": "^5.12.0",
83-
"ts-jest": "^29.2.2",
8480
"typescript": "~5.4.5",
8581
"vite": "^5.3.6",
86-
"vite-plugin-relay": "^2.1.0"
82+
"vite-plugin-relay": "^2.1.0",
83+
"vitest": "^2.1.2"
8784
},
8885
"scripts": {
8986
"preinstall": "npx only-allow pnpm",
9087
"build": "pnpm run build:relay && vite build",
9188
"build:static": "cpy ./static ../src/phoenix/server",
9289
"build:relay": "relay-compiler",
93-
"test": "jest --config ./jest.config.js",
90+
"test": "vitest run",
9491
"test:e2e": "playwright test",
9592
"test:e2e:ui": "playwright test --ui",
9693
"dev": "pnpm run dev:server & pnpm run build:static && pnpm run build:relay && vite",

0 commit comments

Comments
 (0)