|
1 | 1 | import { fileURLToPath } from 'node:url' |
2 | | -import { defineVitestConfig } from '@nuxt/test-utils/config' |
| 2 | +import { defineVitestProject } from '@nuxt/test-utils/config' |
| 3 | +import { defineConfig } from 'vitest/config' |
| 4 | +import vue from '@vitejs/plugin-vue' |
| 5 | +import ui from './src/vite' |
| 6 | +import { resolve } from 'pathe' |
| 7 | +import { glob } from 'tinyglobby' |
3 | 8 |
|
4 | | -export default defineVitestConfig({ |
| 9 | +const components = await glob('./src/runtime/components/*.vue', { absolute: true }) |
| 10 | +const vueComponents = await glob('./src/runtime/vue/components/*.vue', { absolute: true }) |
| 11 | + |
| 12 | +export default defineConfig({ |
5 | 13 | test: { |
6 | | - testTimeout: 1000, |
| 14 | + testTimeout: 5000, |
7 | 15 | globals: true, |
8 | 16 | silent: true, |
9 | | - include: ['./test/components/**/**.spec.ts', './test/composables/**.spec.ts', './test/utils/**/**.spec.ts'], |
10 | | - environment: 'nuxt', |
11 | | - environmentOptions: { |
12 | | - nuxt: { |
13 | | - rootDir: fileURLToPath(new URL('test/nuxt/', import.meta.url)) |
| 17 | + resolveSnapshotPath(path, extension, { config }) { |
| 18 | + if (config.name === 'vue') { |
| 19 | + return path.replace(/\/([^/]+)\.spec\.ts$/, `/__snapshots__/$1-vue.spec.ts${extension}`) |
| 20 | + } else { |
| 21 | + return path.replace(/\/([^/]+)\.spec\.ts$/, `/__snapshots__/$1.spec.ts${extension}`) |
14 | 22 | } |
15 | 23 | }, |
16 | | - setupFiles: fileURLToPath(new URL('test/nuxt/setup.ts', import.meta.url)) |
| 24 | + projects: [ |
| 25 | + await defineVitestProject({ |
| 26 | + extends: true, |
| 27 | + test: { |
| 28 | + name: 'nuxt', |
| 29 | + include: ['./test/components/**/**.spec.ts', './test/composables/**.spec.ts', './test/utils/**/**.spec.ts'], |
| 30 | + environment: 'nuxt', |
| 31 | + environmentOptions: { |
| 32 | + nuxt: { |
| 33 | + rootDir: fileURLToPath(new URL('test/nuxt/', import.meta.url)) |
| 34 | + } |
| 35 | + }, |
| 36 | + setupFiles: fileURLToPath(new URL('test/nuxt/setup.ts', import.meta.url)) |
| 37 | + } |
| 38 | + }), |
| 39 | + { |
| 40 | + extends: true, |
| 41 | + test: { |
| 42 | + name: 'vue', |
| 43 | + environment: 'happy-dom', |
| 44 | + include: ['./test/components/**.spec.ts', './test/composables/**.spec.ts'], |
| 45 | + setupFiles: ['./test/utils/setup.ts'] |
| 46 | + }, |
| 47 | + plugins: [ |
| 48 | + vue(), |
| 49 | + ui({ dts: false }), |
| 50 | + { |
| 51 | + name: 'nuxt-ui-test:components', |
| 52 | + enforce: 'pre', |
| 53 | + resolveId(id) { |
| 54 | + if (id === '@nuxt/test-utils/runtime') { |
| 55 | + return resolve('./test/utils/mount') |
| 56 | + } |
| 57 | + } |
| 58 | + }, |
| 59 | + { |
| 60 | + name: 'nuxt-ui-test:components', |
| 61 | + enforce: 'pre', |
| 62 | + resolveId(id) { |
| 63 | + if (id === '#components') { |
| 64 | + return '#components' |
| 65 | + } |
| 66 | + }, |
| 67 | + load(id) { |
| 68 | + if (id === '#components' || id === '?#components') { |
| 69 | + const resolvedComponents = [...vueComponents, ...components] |
| 70 | + const renderedComponents = new Set<string>() |
| 71 | + return resolvedComponents.map((file) => { |
| 72 | + const componentName = file.split('/').pop()!.replace('.vue', '') |
| 73 | + if (renderedComponents.has(componentName)) { |
| 74 | + return '' |
| 75 | + } |
| 76 | + renderedComponents.add(componentName) |
| 77 | + return `export { default as U${componentName} } from '${file}'` |
| 78 | + }).join('\n') |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | + ] |
| 83 | + } |
| 84 | + ] |
17 | 85 | } |
18 | 86 | }) |
0 commit comments