-
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathvitest.config.ts
More file actions
89 lines (81 loc) · 2.66 KB
/
vitest.config.ts
File metadata and controls
89 lines (81 loc) · 2.66 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
import { defineConfig, configDefaults } from 'vitest/config';
import { playwright } from '@vitest/browser-playwright';
import tsconfigPaths from 'vite-tsconfig-paths';
import type { BrowserCommand } from 'vitest/node';
import axe from 'axe-core';
type AxeCommandContext = {
provider?: { name?: string };
frame?: () => Promise<{
evaluate: <T>(fnOrSource: unknown, ...args: unknown[]) => Promise<T>;
}>;
};
const axeCheck: BrowserCommand<[selector?: string]> = async (ctx, selector = 'body') => {
const { provider, frame: frameResolver } = ctx as unknown as AxeCommandContext;
if (provider?.name !== 'playwright') {
throw new Error(`axeCheck only supports playwright provider, got: ${provider?.name}`);
}
if (typeof frameResolver !== 'function') {
const keys = Object.keys(ctx as unknown as Record<string, unknown>);
throw new Error(`axeCheck command context has no 'frame()' resolver. Context keys: ${keys.join(', ')}`);
}
const frame = await frameResolver();
// Inject axe-core into the test iframe, then run within that frame.
// Using the iframe frame avoids failures from Vitest's outer orchestrator page.
await frame.evaluate(axe.source);
const results = (await frame.evaluate(async (scopeSelector: string) => {
// @ts-expect-error - injected by axe.source
return await window.axe.run(scopeSelector);
}, selector)) as { violations?: unknown[] };
return (results.violations || []) as unknown[];
};
export default defineConfig({
plugins: [
tsconfigPaths({
configNames: ['tsconfig.node.json'],
}),
],
resolve: {
alias: {
vue: 'vue/dist/vue.esm-bundler.js',
},
},
test: {
testTimeout: 5000,
retry: 3,
browser: {
enabled: true,
provider: playwright(),
instances: [{ browser: 'chromium' }],
commands: {
axeCheck,
},
},
setupFiles: ['./vitest.setup.ts', 'vitest-browser-vue'],
globals: true,
exclude: ['docs/*', ...configDefaults.exclude],
coverage: {
provider: 'v8',
reporter: ['html', 'json'],
include: [...(configDefaults.coverage.include || [])],
exclude: [
'**/*/devtools.ts',
'packages/**/dist/**',
'packages/playground/**',
'packages/test-utils/**',
'packages/starter-kits/**',
'./*.ts',
'./*.js',
'docs/*',
'scripts/**',
...(configDefaults.coverage.exclude || []),
],
},
},
define: {
__DEV__: JSON.stringify(true),
__VERSION__: JSON.stringify('1.0.0'),
__VUE_OPTIONS_API__: JSON.stringify(true),
__VUE_PROD_DEVTOOLS__: JSON.stringify(false),
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: JSON.stringify(false),
},
});