-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvitest.config.ts
More file actions
78 lines (76 loc) · 2.89 KB
/
Copy pathvitest.config.ts
File metadata and controls
78 lines (76 loc) · 2.89 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
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { storybookTest } from '@storybook/addon-vitest/vitest-plugin';
import storycapPlugin from '@storycap-testrun/browser/vitest-plugin';
import { playwright } from '@vitest/browser-playwright';
import type { PluginOption } from 'vite';
import { defineConfig } from 'vitest/config';
const dirname = typeof __dirname !== 'undefined' ? __dirname : path.dirname(fileURLToPath(import.meta.url));
const screenshotMode = !!process.env.SCREENSHOT_MODE; // Enable screenshot capture and comparison
const setupFile = screenshotMode ? '.storybook/vitest.setup.screenshots.ts' : '.storybook/vitest.setup.ts';
export default defineConfig({
test: {
globals: true,
environment: 'node',
coverage: { reporter: ['text', 'json'] },
projects: [
{
test: {
name: 'unit',
include: ['**/*.spec.ts', '**/*.test.ts'],
},
},
{
optimizeDeps: {
include: ['react', 'react-dom', 'react/jsx-dev-runtime'],
},
extends: true,
plugins: [
storybookTest({
configDir: path.join(dirname, '.storybook'),
}),
...(screenshotMode
? [
storycapPlugin({
output: {
// Screenshots are captured to .screenshots-temp/actual/ for comparison
// If baseline doesn't exist, screenshot-compare.ts auto-creates it in component directory
dir: path.join(dirname, '.screenshots-temp/actual'),
file: (context) => {
// Generate path: lib/components/Button/__screenshots__/Button/Default.png
const storyFileDir = path.dirname(context.file);
const storyFileName = path.basename(context.file);
// Extract component name by removing .stories.tsx/.stories.ts extension
const componentName = storyFileName.replace(/\.stories\.(tsx|ts)$/, '');
return path.join(
storyFileDir,
'__screenshots__',
componentName, // Use component name instead of full story filename
`${context.name}.png`,
);
},
},
}) as PluginOption,
]
: []),
],
test: {
environment: 'node',
name: 'storybook',
browser: {
enabled: true,
headless: true,
isolate: false,
provider: playwright({
launchOptions: {
args: ['--font-render-hinting=none', '--disable-font-subpixel-positioning'],
},
}),
instances: [{ browser: 'firefox' }],
},
setupFiles: [setupFile],
},
},
],
},
});