-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvitest.config.ts
More file actions
88 lines (84 loc) · 2.7 KB
/
Copy pathvitest.config.ts
File metadata and controls
88 lines (84 loc) · 2.7 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
import type { Plugin } from 'vite-plus'
import { storybookTest } from '@storybook/addon-vitest/vitest-plugin'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { defineConfig } from 'vite-plus'
import { playwright } from 'vite-plus/test/browser-playwright'
const testTimeout = Number(process.env['TEST_TIMEOUT'])
const coverageThresholds = {
lines: Number(process.env['COVERAGE_THRESHOLD_LINES']),
branches: Number(process.env['COVERAGE_THRESHOLD_BRANCHES']),
functions: Number(process.env['COVERAGE_THRESHOLD_FUNCTIONS']),
statements: Number(process.env['COVERAGE_THRESHOLD_STATEMENTS']),
}
const storybookFocusVisibleCompat = {
name: 'storybook-focus-visible-compat',
enforce: 'pre',
transform(code, id) {
if (!id.endsWith('/storybook/dist/csf/index.js')) return
return code.replace(
'let originalFocus = HTMLElement.prototype.focus, currentFocus = HTMLElement.prototype.focus, noopFocus = () => {',
'let originalFocus = Object.getOwnPropertyDescriptor(HTMLElement.prototype, "focus")?.value ?? HTMLElement.prototype.focus, currentFocus = HTMLElement.prototype.focus, noopFocus = () => {',
)
},
} satisfies Plugin
export default defineConfig({
optimizeDeps: {
include: ['react', 'react/jsx-dev-runtime'],
},
test: {
globals: true,
coverage: {
provider: 'v8',
reportsDirectory: '.var/coverage',
include: ['src/**/*.{ts,tsx}'],
exclude: [
'src/**/*.stories.tsx',
'src/**/*.test.{ts,tsx}',
'src/shared/styled-system/**',
'src/shared/components/ui/**',
'src/main.tsx',
],
thresholds: coverageThresholds,
},
projects: [
{
extends: true,
test: {
name: 'unit',
include: ['src/**/*.test.{ts,tsx}'],
exclude: ['src/**/*.stories.tsx'],
testTimeout: testTimeout,
hookTimeout: testTimeout,
environment: 'node',
},
},
{
extends: true,
plugins: [
storybookFocusVisibleCompat,
// The plugin will run tests for the stories defined in your Storybook config
// See options at: https://storybook.js.org/docs/next/writing-tests/integrations/vitest-addon#storybooktest
storybookTest({
configDir: path.join(path.dirname(fileURLToPath(import.meta.url)), '.storybook'),
}),
],
test: {
name: 'storybook',
testTimeout: testTimeout,
hookTimeout: testTimeout,
browser: {
enabled: true,
headless: true,
// Artifact-on-failure, mirroring a CodeceptJS-style reporter
// (see docs/testing.md, Failure diagnostics). Screenshots land in
// __screenshots__/ next to the story file (gitignored).
screenshotFailures: true,
provider: playwright(),
instances: [{ browser: 'chromium' }],
},
},
},
],
},
} as never)