Repository navigation
Expand file tree
/
Copy pathvitest.config.mts
More file actions
98 lines (94 loc) · 3 KB
/
Copy pathvitest.config.mts
File metadata and controls
98 lines (94 loc) · 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
import { defineConfig, defaultExclude } from 'vitest/config';
import path from 'path';
import { readFileSync } from 'fs';
import type { Plugin } from 'vite';
import { fileURLToPath } from 'node:url';
const __dirname = import.meta.dirname;
/**
* Vite plugin that imports .md files as raw strings.
* Matches Vite's md-raw plugin behavior for markdown files.
*/
function rawMarkdownPlugin(): Plugin {
return {
name: 'raw-markdown',
transform(_code: string, id: string) {
if (id.endsWith('.md')) {
const content = readFileSync(id, 'utf-8');
return { code: `export default ${JSON.stringify(content)};`, map: null };
}
},
};
}
const sharedViteConfig = {
plugins: [rawMarkdownPlugin()],
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
'vscode-jsonrpc/browser': fileURLToPath(
new URL('../browser/main.js', import.meta.resolve('vscode-jsonrpc'))
),
},
},
};
/**
* Vitest Configuration for Excel AI Add-in
*
* Uses Vitest projects to consolidate unit and integration configs into a single
* file, preventing the VS Code Vitest extension from exceeding its 5-project limit.
*
* Projects:
* unit — jsdom, 30s timeout, all tests except tests/integration/ and *.integration.test.ts
* integration — jsdom, 60s timeout, tests/integration/ (including live Copilot WebSocket tests)
*
* Run all: vitest run
* Run integration: vitest run --project integration
* Watch: vitest
*/
export default defineConfig({
test: {
coverage: {
provider: 'v8',
include: ['src/**/*.ts', 'src/**/*.tsx'],
exclude: ['src/**/*.d.ts'],
},
projects: [
{
...sharedViteConfig,
define: {
// Override build-time env vars so tests start with blank defaults
'process.env.AZURE_OPENAI_ENDPOINT': JSON.stringify(''),
'process.env.AZURE_OPENAI_API_KEY': JSON.stringify(''),
},
test: {
name: 'unit',
// jsdom for all tests — needed by React component tests
environment: 'jsdom',
// All tests except server-dependent live Copilot WebSocket tests
include: ['tests/**/*.test.ts', 'tests/**/*.test.tsx'],
exclude: [
...defaultExclude,
// Skip live-server-dependent integration tests
'tests/**/*.integration.test.ts',
],
setupFiles: ['tests/setup.ts'],
testTimeout: 30000,
globals: true,
},
},
{
...sharedViteConfig,
test: {
name: 'integration',
// jsdom — React component integration tests need DOM
environment: 'jsdom',
// All tests in tests/integration/ including live Copilot WebSocket tests
include: ['tests/integration/**/*.test.ts', 'tests/integration/**/*.test.tsx'],
// 60s — live Copilot calls can be slow
testTimeout: 60000,
setupFiles: ['tests/setup.ts'],
globals: true,
},
},
],
},
});