Skip to content
This repository was archived by the owner on Jul 8, 2025. It is now read-only.

Commit 9e1c7bf

Browse files
committed
chore: add mock on vitest
1 parent 3408147 commit 9e1c7bf

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

vite.config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { defineConfig } from "vite";
22
import path from "path";
33
import react from "@vitejs/plugin-react-swc";
4+
import tsconfigPaths from "vite-tsconfig-paths";
45

56
// https://vite.dev/config/
67
export default defineConfig({
7-
plugins: [react()],
8+
plugins: [tsconfigPaths(), react()],
89
base: "/",
910
build: {
1011
outDir: "dist",
@@ -17,5 +18,5 @@ export default defineConfig({
1718
"@": path.resolve(__dirname, "./src"),
1819
},
1920
},
20-
assetsInclude: ['**/*.md'],
21+
assetsInclude: ["**/*.md"],
2122
});

vitest.config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/// <reference types="vitest" />
22
import { defineConfig } from "vitest/config";
33
import react from "@vitejs/plugin-react-swc";
4+
import tsconfigPaths from "vite-tsconfig-paths";
45
import path from "path";
56

67
export default defineConfig({
7-
plugins: [react()],
8+
plugins: [tsconfigPaths(), react()],
89
resolve: {
910
alias: {
1011
"@": path.resolve(__dirname, "./src"),
@@ -14,6 +15,9 @@ export default defineConfig({
1415
globals: true,
1516
environment: "jsdom",
1617
setupFiles: "./vitest.setup.ts",
18+
env: {
19+
VITE_BASE_API_URL: "https://mock.codegate.ai",
20+
},
1721
exclude: [
1822
"**/node_modules/**",
1923
"**/dist/**",

vitest.setup.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as testingLibraryMatchers from "@testing-library/jest-dom/matchers";
33
import "@testing-library/jest-dom/vitest";
44
import { cleanup } from "@testing-library/react";
55
import { afterEach, expect, beforeAll, afterAll, vi } from "vitest";
6+
import failOnConsole from "vitest-fail-on-console";
67

78
expect.extend(testingLibraryMatchers);
89

@@ -14,9 +15,29 @@ beforeAll(() => {
1415
server.listen({
1516
onUnhandledRequest: "error",
1617
});
18+
19+
global.ResizeObserver = class ResizeObserver {
20+
disconnect() {
21+
// do nothing
22+
}
23+
observe() {
24+
// do nothing
25+
}
26+
unobserve() {
27+
// do nothing
28+
}
29+
};
1730
});
1831
afterEach(() => {
1932
server.resetHandlers();
2033
vi.clearAllMocks();
2134
});
2235
afterAll(() => server.close());
36+
37+
failOnConsole({
38+
shouldFailOnDebug: true,
39+
shouldFailOnError: true,
40+
shouldFailOnInfo: true,
41+
shouldFailOnLog: true,
42+
shouldFailOnWarn: true,
43+
});

0 commit comments

Comments
 (0)