-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathvitest.config.js
More file actions
40 lines (37 loc) · 1.34 KB
/
vitest.config.js
File metadata and controls
40 lines (37 loc) · 1.34 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
import { defineConfig } from 'vitest/config'
import { transformWithOxc } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'path'
const ROOT = path.resolve(__dirname)
const SRC = path.join(ROOT, 'src')
// Vite 7's vite:oxc transformer keys JSX detection off the file extension
// (filepath.endsWith('x')), so JSX written inside our .js source files
// (e.g. src/components/repo-card.js) parses as plain JS and fails.
// Force-transform those files as JSX before vite:oxc gets a chance.
const jsxInJsPlugin = {
name: 'code-jsx-in-js',
enforce: 'pre',
async transform(code, id) {
const [filepath] = id.split('?')
if (!filepath.startsWith(SRC)) return null
if (!filepath.endsWith('.js')) return null
const result = await transformWithOxc(code, filepath, {
lang: 'jsx',
jsx: { runtime: 'automatic', importSource: 'react' }
})
return { code: result.code, map: result.map }
}
}
export default defineConfig({
plugins: [jsxInJsPlugin, react()],
test: {
environment: 'jsdom',
globals: true,
setupFiles: ['./vitest.setup.js'],
include: [
'tests/unit/**/*.{test,spec}.{js,jsx}',
'tests/integration/**/*.{test,spec}.{js,jsx}'
],
exclude: ['node_modules', '.next', 'out', 'tests/e2e']
}
})