mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 12:14:41 +01:00
feat(module): add support for vue using unplugin (#2416)
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
55
vitest.vue.config.ts
Normal file
55
vitest.vue.config.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
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',
|
||||
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')
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
Reference in New Issue
Block a user