-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathvitest.config.ts
More file actions
96 lines (94 loc) · 3.16 KB
/
vitest.config.ts
File metadata and controls
96 lines (94 loc) · 3.16 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
90
91
92
93
94
95
96
import { fileURLToPath } from 'node:url'
import { defineVitestProject } from '@nuxt/test-utils/config'
import { defineConfig } from 'vitest/config'
import vue from '@vitejs/plugin-vue'
import bitrix24UIPluginVite from './src/vite'
import { glob } from 'tinyglobby'
const components = await glob('./src/runtime/components/*.vue', { absolute: true })
const vueComponents = await glob('./src/runtime/vue/components/*.vue', { absolute: true })
const vueRouterOverrides = await glob('./src/runtime/vue/overrides/vue-router/*.vue', { absolute: true })
export default defineConfig({
test: {
testTimeout: 5000,
globals: true,
silent: true,
resolveSnapshotPath(path, extension, { config }) {
if (config.name === 'vue') {
return path.replace(/\/([^/]+)\.spec\.ts$/, `/__snapshots__/$1-vue.spec.ts${extension}`)
} else {
return path.replace(/\/([^/]+)\.spec\.ts$/, `/__snapshots__/$1.spec.ts${extension}`)
}
},
projects: [
await defineVitestProject({
extends: true,
test: {
name: 'nuxt',
dir: './test',
include: [
'components/**/**.spec.ts',
'composables/**.spec.ts',
'utils/**/**.spec.ts'
],
environment: 'nuxt',
environmentOptions: {
nuxt: {
rootDir: fileURLToPath(new URL('test/nuxt/', import.meta.url))
}
},
setupFiles: fileURLToPath(new URL('test/nuxt/setup.ts', import.meta.url))
}
}),
{
extends: true,
test: {
name: 'vue',
environment: 'happy-dom',
dir: './test',
include: [
'components/**.spec.ts',
'composables/**.spec.ts',
'utils/**/**.spec.ts'
],
setupFiles: ['./test/utils/setup.ts']
},
plugins: [
vue(),
bitrix24UIPluginVite({ dts: false }),
{
name: 'bitrix24-ui-test:components',
enforce: 'pre',
resolveId(id) {
if (id === '@nuxt/test-utils/runtime') {
return fileURLToPath(new URL('test/utils/mount.ts', import.meta.url))
}
}
},
{
name: 'bitrix24-ui-test:components',
enforce: 'pre',
resolveId(id) {
if (id === '#components') {
return '#components'
}
},
load(id) {
if (id === '#components' || id === '?import#components') {
const resolvedComponents = [...vueRouterOverrides, ...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 B24${componentName} } from '${file}'`
}).join('\n')
}
}
}
]
}
]
}
})