-
-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathvitest.config.js
More file actions
104 lines (102 loc) · 3.3 KB
/
vitest.config.js
File metadata and controls
104 lines (102 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { defineConfig } from 'vitest/config';
import react from '@vitejs/plugin-react';
import { resolve } from 'node:path';
export default defineConfig({
plugins: [
react(),
{
name: 'mock-modules',
enforce: 'pre',
resolveId(id, importer) {
if (id === '@tanstack/react-query') {
return '\0' + id;
}
if (id === 'antd') {
return '\0' + id;
}
// Handle react/jsx-runtime imports - check if it's being imported as a file path
if (id === 'react/jsx-runtime' || id.endsWith('react/jsx-runtime')) {
const jsPath = resolve('node_modules/react/jsx-runtime.js');
return jsPath;
}
if (id === 'react/jsx-dev-runtime' || id.endsWith('react/jsx-dev-runtime')) {
const jsPath = resolve('node_modules/react/jsx-dev-runtime.js');
return jsPath;
}
return null;
},
load(id) {
// Also handle loading react/jsx-runtime if it comes through as a file path
if (
id === resolve('node_modules/react/jsx-runtime.js') ||
id.includes('react/jsx-runtime')
) {
return null; // Let vite handle it normally
}
if (
id === resolve('node_modules/react/jsx-dev-runtime.js') ||
id.includes('react/jsx-dev-runtime')
) {
return null; // Let vite handle it normally
}
if (id === '\0@tanstack/react-query') {
return `
export const useQuery = () => ({
data: undefined,
isLoading: false,
isError: false,
error: null,
refetch: () => Promise.resolve(),
});
export const useMutation = () => ({
mutate: () => {},
mutateAsync: () => Promise.resolve(),
isLoading: false,
isError: false,
error: null,
});
export class QueryClient {
constructor() {
this.setQueryData = () => {};
this.getQueryData = () => {};
this.invalidateQueries = () => {};
this.refetchQueries = () => {};
}
}
export const QueryClientProvider = ({ children }) => children;
`;
}
if (id === '\0antd') {
return `
import React from 'react';
export const Select = ({ children, ...props }) => React.createElement('select', props, children);
export const DatePicker = (props) => React.createElement('input', { type: 'date', ...props });
export const Spin = ({ children, ...props }) => React.createElement('div', props, children);
`;
}
},
},
],
resolve: {
alias: {
'~': resolve('src/'),
__tests__: resolve('src/__tests__'),
'joi-browser': resolve('node_modules/joi'),
'react/jsx-runtime$': resolve('node_modules/react/jsx-runtime.js'),
'react/jsx-dev-runtime$': resolve('node_modules/react/jsx-dev-runtime.js'),
},
},
css: {
modules: {
classNameStrategy: 'non-scoped',
},
},
optimizeDeps: {
include: ['react/jsx-runtime', 'react/jsx-dev-runtime'],
},
test: {
environment: 'jsdom',
globals: true,
setupFiles: ['./src/setupTests.js'],
},
});