forked from lobehub/lobehub
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.config.mts
More file actions
167 lines (159 loc) · 5.98 KB
/
Copy pathvitest.config.mts
File metadata and controls
167 lines (159 loc) · 5.98 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import { dirname, join, resolve } from 'node:path';
import tsconfigPaths from 'vite-tsconfig-paths';
import { coverageConfigDefaults, defineConfig } from 'vitest/config';
if (process.env.NODE_ENV === 'production') {
Reflect.set(process.env, 'NODE_ENV', 'test');
}
const alias = {
// Downstream workspaces sometimes pnpm-override @lobechat/business-* packages to
// internal implementations whose source files import alias paths that only exist
// in the outer workspace, causing vite import-analysis to fail when running tests
// from this repo. Pin the package to the local stub so tests here stay hermetic.
'@lobechat/business-model-runtime': resolve(
__dirname,
'./packages/business/model-runtime/src/index.ts',
),
'@lobechat/business-model-bank/model-config': resolve(
__dirname,
'./packages/business/model-bank/src/model-config.ts',
),
'@lobechat/business-model-bank': resolve(
__dirname,
'./packages/business/model-bank/src/index.ts',
),
'@emoji-mart/data': resolve(__dirname, './tests/mocks/emojiMartData.ts'),
'@emoji-mart/react': resolve(__dirname, './tests/mocks/emojiMartReact.tsx'),
'@/utils/client/switchLang': resolve(__dirname, './src/utils/client/switchLang'),
'@/const/locale': resolve(__dirname, './src/const/locale'),
// TODO: after refactor the errorResponse, we can remove it
'@/utils/errorResponse': resolve(__dirname, './src/utils/errorResponse'),
'@/utils/unzipFile': resolve(__dirname, './src/utils/unzipFile'),
'@/utils/server': resolve(__dirname, './src/utils/server'),
'@/utils/identifier': resolve(__dirname, './src/utils/identifier'),
'@/utils/electron': resolve(__dirname, './src/utils/electron'),
'@/utils/markdownToTxt': resolve(__dirname, './src/utils/markdownToTxt'),
'@/utils/sanitizeFileName': resolve(__dirname, './src/utils/sanitizeFileName'),
// Workspace store lives in the cloud repo; submodule-only tests get a stub
// that reports no active workspace so workspace-aware nav helpers behave
// like plain react-router.
'@/store/workspace': resolve(__dirname, './tests/mocks/storeWorkspace.ts'),
'~test-utils': resolve(__dirname, './tests/utils.tsx'),
'lru_map': resolve(__dirname, './tests/mocks/lru_map'),
};
export default defineConfig({
define: {
'__CI__': process.env.CI === 'true' ? 'true' : 'false',
'__DEV__': process.env.NODE_ENV !== 'production' ? 'true' : 'false',
'__ELECTRON__': 'false',
'__MOBILE__': 'false',
'__TEST__': 'true',
},
optimizeDeps: {
exclude: ['crypto', 'util', 'tty'],
include: ['@lobehub/tts'],
},
plugins: [
tsconfigPaths({ projects: ['.'] }),
// Let `.md` imports resolve to their raw text content so Rollup/Vitest
// doesn't try to parse Markdown as JavaScript.
{
name: 'raw-md',
transform(_, id) {
if (id.endsWith('.md'))
return { code: 'export default ""', map: null };
},
},
/**
* @lobehub/fluent-emoji@4.0.0 ships `es/FluentEmoji/style.js` but its `es/FluentEmoji/index.js`
* imports `./style/index.js` which doesn't exist.
*
* In app bundlers this can be tolerated/rewritten, but Vite/Vitest resolves it strictly and
* fails the whole test run. Redirect it to the real file.
*/
{
enforce: 'pre',
name: 'fix-lobehub-fluent-emoji-style-import',
resolveId(id, importer) {
if (!importer) return null;
const isFluentEmojiEntry =
importer.endsWith('/@lobehub/fluent-emoji/es/FluentEmoji/index.js') ||
importer.includes('/@lobehub/fluent-emoji/es/FluentEmoji/index.js?');
const isMissingStyleIndex =
id === './style/index.js' ||
id.endsWith('/@lobehub/fluent-emoji/es/FluentEmoji/style/index.js') ||
id.endsWith('/@lobehub/fluent-emoji/es/FluentEmoji/style/index.js?') ||
id.endsWith('/FluentEmoji/style/index.js') ||
id.endsWith('/FluentEmoji/style/index.js?');
if (isFluentEmojiEntry && isMissingStyleIndex)
return resolve(dirname(importer), 'style.js');
return null;
},
},
],
resolve: {
alias,
},
test: {
alias,
coverage: {
all: false,
exclude: [
// https://github.com/lobehub/lobe-chat/pull/7265
...coverageConfigDefaults.exclude,
'__mocks__/**',
'**/packages/**',
// just ignore the migration code
// we will use pglite in the future
// so the coverage of this file is not important
'src/utils/fetch/fetchEventSource/*.ts',
],
provider: 'v8',
reporter: ['text', 'json', 'lcov', 'text-summary'],
reportsDirectory: './coverage/app',
},
environment: 'happy-dom',
// Frontend (src/**) needs a DOM, but apps/server is backend code that runs
// under Node in production. Forcing Node here makes `typeof window` undefined
// so the t3-env server/client guard reads server config instead of throwing
// "server-side environment variable on the client" — the failure the full
// `Test Server` run hit non-deterministically (it depended on which
// ModelRuntime-importing suite a happy-dom worker evaluated first). Per-file
// `// @vitest-environment` directives still win over this.
environmentMatchGlobs: [['**/apps/server/**', 'node']],
exclude: [
'**/node_modules/**',
'**/.*/**',
'**/dist/**',
'**/build/**',
'**/tmp/**',
'**/temp/**',
'**/docs/**',
'**/locales/**',
'**/public/**',
'**/apps/desktop/**',
'**/apps/mobile/**',
'**/apps/cli/**',
'**/packages/**',
'**/e2e/**',
],
globals: true,
server: {
deps: {
inline: [
'vitest-canvas-mock',
/@emoji-mart/,
'emoji-mart',
'@lobehub/ui',
'@lobehub/fluent-emoji',
'@pierre/diffs',
'@pierre/diffs/react',
'lru_map',
'lexical',
/@lexical\//,
/@lobehub\//,
],
},
},
setupFiles: join(__dirname, './tests/setup.ts'),
},
});