-
Notifications
You must be signed in to change notification settings - Fork 576
/
vitest.vue.config.ts
56 lines (54 loc) · 1.68 KB
/
vitest.vue.config.ts
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
import vue from '@vitejs/plugin-vue'
import ui from './src/vite'
import { defineConfig } from 'vitest/config'
import { glob } from 'tinyglobby'
import { resolve } from 'pathe'
const components = await glob('./src/runtime/components/*.vue', { absolute: true })
const vueComponents = await glob('./src/runtime/vue/components/*.vue', { absolute: true })
export default defineConfig({
test: {
environment: 'happy-dom',
silent: true,
include: ['./test/components/**.spec.ts'],
setupFiles: ['./test/utils/setup.ts'],
resolveSnapshotPath(path, extension) {
return path.replace(/\/([^/]+)\.spec\.ts$/, `/__snapshots__/$1-vue.spec.ts${extension}`)
}
},
plugins: [
vue(),
ui({ dts: false }),
{
name: 'nuxt-ui-test:components',
enforce: 'pre',
resolveId(id) {
if (id === '@nuxt/test-utils/runtime') {
return resolve('./test/utils/mount')
}
}
},
{
name: 'nuxt-ui-test:components',
enforce: 'pre',
resolveId(id) {
if (id === '#components') {
return '#components'
}
},
load(id) {
if (id === '#components' || id === '?#components') {
const resolvedComponents = [...vueComponents, ...components]
const renderedComponents = new Set<string>()
return resolvedComponents.map((file) => {
const componentName = file.split('/').pop()!.replace('.vue', '')
if (renderedComponents.has(componentName)) {
return ''
}
renderedComponents.add(componentName)
return `export { default as U${componentName} } from '${file}'`
}).join('\n')
}
}
}
]
})