Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc627a68

Browse files
authored
chore: migrate some tests from jest to vitest (#20568)
1 parent7ae3fdc commitc627a68

File tree

77 files changed

+629
-375
lines changed

Some content is hidden

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

77 files changed

+629
-375
lines changed

‎site/.knip.jsonc‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88
"@types/react-virtualized-auto-sizer",
99
"jest_workaround",
1010
"ts-proto"
11-
]
11+
],
12+
"jest": {
13+
"entry":"./src/**/*.jest.{ts,tsx}"
14+
}
1215
}

‎site/jest.config.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = {
3131
testEnvironmentOptions:{
3232
customExportConditions:[""],
3333
},
34-
testRegex:"(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
34+
testRegex:"(/__tests__/.*|(\\.|/)(jest))\\.tsx?$",
3535
testPathIgnorePatterns:[
3636
"/node_modules/",
3737
"/e2e/",

‎site/package.json‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
"storybook":"STORYBOOK=true storybook dev -p 6006",
2828
"storybook:build":"storybook build",
2929
"storybook:ci":"storybook build --test",
30-
"test":"jest",
31-
"test:ci":"jest --selectProjects test --silent",
32-
"test:coverage":"jest --selectProjects test --collectCoverage",
33-
"test:watch":"jest --selectProjects test --watch",
30+
"test":"vitest run &&jest",
31+
"test:ci":"vitest run && jest --silent",
32+
"test:watch":"vitest",
33+
"test:watch-jest":"jest --watch",
3434
"stats":"STATS=true pnpm build && npx http-server ./stats -p 8081 -c-1",
3535
"update-emojis":"cp -rf ./node_modules/emoji-datasource-apple/img/apple/64/* ./static/emojis"
3636
},
@@ -133,7 +133,7 @@
133133
"@swc/core":"1.3.38",
134134
"@swc/jest":"0.2.37",
135135
"@tailwindcss/typography":"0.5.16",
136-
"@testing-library/jest-dom":"6.6.3",
136+
"@testing-library/jest-dom":"6.9.1",
137137
"@testing-library/react":"14.3.1",
138138
"@testing-library/user-event":"14.6.1",
139139
"@types/chroma-js":"2.4.0",
@@ -167,6 +167,7 @@
167167
"jest-location-mock":"2.0.0",
168168
"jest-websocket-mock":"2.5.0",
169169
"jest_workaround":"0.1.14",
170+
"jsdom":"27.0.1",
170171
"knip":"5.64.1",
171172
"msw":"2.4.8",
172173
"postcss":"8.5.6",
@@ -180,7 +181,8 @@
180181
"ts-proto":"1.181.2",
181182
"typescript":"5.6.3",
182183
"vite":"7.1.11",
183-
"vite-plugin-checker":"0.11.0"
184+
"vite-plugin-checker":"0.11.0",
185+
"vitest":"4.0.5"
184186
},
185187
"browserslist": [
186188
"chrome 110",

‎site/pnpm-lock.yaml‎

Lines changed: 543 additions & 15 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.
File renamed without changes.

‎site/src/api/api.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2759,7 +2759,7 @@ function getConfiguredAxiosInstance(): AxiosInstance {
27592759
}
27602760
}else{
27612761
// Do not write error logs if we are in a FE unit test.
2762-
if(process.env.JEST_WORKER_ID===undefined){
2762+
if(!process.env.JEST_WORKER_ID&&!process.env.VITEST){
27632763
console.error("CSRF token not found");
27642764
}
27652765
}

‎site/src/components/Dialogs/ConfirmDialog/ConfirmDialog.test.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { ConfirmDialog } from "./ConfirmDialog";
55
describe("ConfirmDialog",()=>{
66
it("onClose is called when cancelled",()=>{
77
// Given
8-
constonCloseMock=jest.fn();
8+
constonCloseMock=vi.fn();
99
constprops={
1010
cancelText:"CANCEL",
1111
hideCancel:false,
@@ -24,8 +24,8 @@ describe("ConfirmDialog", () => {
2424

2525
it("onConfirm is called when confirmed",()=>{
2626
// Given
27-
constonCloseMock=jest.fn();
28-
constonConfirmMock=jest.fn();
27+
constonCloseMock=vi.fn();
28+
constonConfirmMock=vi.fn();
2929
constprops={
3030
cancelText:"CANCEL",
3131
confirmText:"CONFIRM",

‎site/src/components/Dialogs/DeleteDialog/DeleteDialog.test.tsx‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ describe("DeleteDialog", () => {
2323
renderComponent(
2424
<DeleteDialog
2525
isOpen
26-
onConfirm={jest.fn()}
27-
onCancel={jest.fn()}
26+
onConfirm={vi.fn()}
27+
onCancel={vi.fn()}
2828
entity="template"
2929
name="MyTemplate"
3030
/>,
@@ -38,8 +38,8 @@ describe("DeleteDialog", () => {
3838
renderComponent(
3939
<DeleteDialog
4040
isOpen
41-
onConfirm={jest.fn()}
42-
onCancel={jest.fn()}
41+
onConfirm={vi.fn()}
42+
onCancel={vi.fn()}
4343
entity="template"
4444
name="MyTemplate"
4545
/>,
@@ -56,8 +56,8 @@ describe("DeleteDialog", () => {
5656
renderComponent(
5757
<DeleteDialog
5858
isOpen
59-
onConfirm={jest.fn()}
60-
onCancel={jest.fn()}
59+
onConfirm={vi.fn()}
60+
onCancel={vi.fn()}
6161
entity="template"
6262
name="MyTemplate"
6363
/>,

‎site/src/components/FileUpload/FileUpload.test.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { fireEvent, screen } from "@testing-library/react";
33
import{FileUpload}from"./FileUpload";
44

55
test("accepts files with the correct extension",async()=>{
6-
constonUpload=jest.fn();
6+
constonUpload=vi.fn();
77

88
renderComponent(
99
<FileUpload
@@ -21,14 +21,14 @@ test("accepts files with the correct extension", async () => {
2121
fireEvent.drop(dropZone,{
2222
dataTransfer:{files:[tarFile]},
2323
});
24-
expect(onUpload).toBeCalledWith(tarFile);
24+
expect(onUpload).toHaveBeenCalledWith(tarFile);
2525
onUpload.mockClear();
2626

2727
constzipFile=newFile([""],"file.zip");
2828
fireEvent.drop(dropZone,{
2929
dataTransfer:{files:[zipFile]},
3030
});
31-
expect(onUpload).toBeCalledWith(zipFile);
31+
expect(onUpload).toHaveBeenCalledWith(zipFile);
3232
onUpload.mockClear();
3333

3434
constunsupportedFile=newFile([""],"file.mp4");

‎site/src/components/GlobalSnackbar/utils.test.ts‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
importtype{Mock}from"vitest";
12
import{
23
displayError,
34
displaySuccess,
@@ -48,7 +49,7 @@ describe("Snackbar", () => {
4849

4950
describe("displaySuccess",()=>{
5051
constoriginalWindowDispatchEvent=window.dispatchEvent;
51-
typeTDispatchEventMock=jest.MockedFunction<
52+
typeTDispatchEventMock=Mock<
5253
(msg:CustomEvent<NotificationMsg>)=>boolean
5354
>;
5455
letdispatchEventMock:TDispatchEventMock;
@@ -67,7 +68,7 @@ describe("Snackbar", () => {
6768
};
6869

6970
beforeEach(()=>{
70-
dispatchEventMock=jest.fn();
71+
dispatchEventMock=vi.fn();
7172
window.dispatchEvent=
7273
dispatchEventMockasunknownastypeofwindow.dispatchEvent;
7374
});
@@ -114,16 +115,18 @@ describe("Snackbar", () => {
114115
});
115116

116117
describe("displayError",()=>{
117-
it("shows the title and the message",(done)=>{
118+
it("shows the title and the message",()=>{
118119
constmessage="Some error happened";
119120

120-
window.addEventListener(SnackbarEventType,(event)=>{
121-
constnotificationEvent=eventasCustomEvent<NotificationMsg>;
122-
expect(notificationEvent.detail.msg).toEqual(message);
123-
done();
124-
});
121+
returnnewPromise<void>((resolve)=>{
122+
window.addEventListener(SnackbarEventType,(event)=>{
123+
constnotificationEvent=eventasCustomEvent<NotificationMsg>;
124+
expect(notificationEvent.detail.msg).toEqual(message);
125+
resolve();
126+
});
125127

126-
displayError(message);
128+
displayError(message);
129+
});
127130
});
128131
});
129132
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp