Skip to content

Commit 9002f27

Browse files
chore(vitest): move vue config into vitest project (#5546)
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
1 parent 7e9127d commit 9002f27

File tree

5 files changed

+79
-73
lines changed

5 files changed

+79
-73
lines changed

.github/workflows/module.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ jobs:
5252
- name: Test
5353
run: pnpm run test run
5454

55-
- name: Test (vue)
56-
run: pnpm run test:vue run
57-
5855
- name: Build
5956
run: pnpm run build
6057

.github/workflows/release.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ jobs:
4545
- name: Test
4646
run: pnpm run test run
4747

48-
- name: Test (vue)
49-
run: pnpm run test:vue run
50-
5148
- name: Publish
5249
run: ./scripts/release.sh
5350
env:

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@
115115
"lint:fix": "eslint . --fix",
116116
"typecheck": "vue-tsc --noEmit && nuxt typecheck playgrounds/nuxt && nuxt typecheck docs && cd playgrounds/vue && vue-tsc --noEmit",
117117
"test": "vitest",
118-
"test:vue": "vitest -c vitest.vue.config.ts",
118+
"test:vue": "vitest --project vue",
119+
"test:nuxt": "vitest --project nuxt",
119120
"release": "release-it"
120121
},
121122
"dependencies": {

vitest.config.ts

Lines changed: 77 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,86 @@
11
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'
38

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({
513
test: {
6-
testTimeout: 1000,
14+
testTimeout: 5000,
715
globals: true,
816
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}`)
1422
}
1523
},
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+
]
1785
}
1886
})

vitest.vue.config.ts

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)