diff --git a/.github/workflows/module.yml b/.github/workflows/module.yml index 24cbb8d6be..9df96423a5 100644 --- a/.github/workflows/module.yml +++ b/.github/workflows/module.yml @@ -55,9 +55,6 @@ jobs: - name: Test run: pnpm run test - - name: Test (vue) - run: pnpm run test:vue - - name: Build run: pnpm run build diff --git a/package.json b/package.json index babeef4e93..0990bf8924 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,8 @@ "lint:fix": "eslint . --fix", "typecheck": "vue-tsc --noEmit && nuxi typecheck playground && nuxi typecheck docs && nuxi typecheck devtools && cd playground-vue && vue-tsc --noEmit", "test": "vitest", - "test:vue": "vitest -c vitest.vue.config.ts", + "test:nuxt": "vitest --project nuxt", + "test:vue": "vitest --project vue", "test:vue:build": "vite build playground-vue", "release": "release-it --preRelease=alpha --npm.tag=next" }, diff --git a/vitest.config.ts b/vitest.config.ts deleted file mode 100644 index c2199d6582..0000000000 --- a/vitest.config.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { fileURLToPath } from 'node:url' -import { defineVitestConfig } from '@nuxt/test-utils/config' -import { defaultExclude } from 'vitest/config' - -export default defineVitestConfig({ - test: { - testTimeout: 1000, - globals: true, - silent: true, - exclude: [...defaultExclude, './test/vue/**.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)) - } -}) diff --git a/vitest.vue.config.ts b/vitest.vue.config.ts deleted file mode 100644 index f8be296ae9..0000000000 --- a/vitest.vue.config.ts +++ /dev/null @@ -1,56 +0,0 @@ -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() - 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') - } - } - } - ] -}) diff --git a/vitest.workspace.ts b/vitest.workspace.ts new file mode 100644 index 0000000000..94776bbb47 --- /dev/null +++ b/vitest.workspace.ts @@ -0,0 +1,79 @@ +import { fileURLToPath } from 'node:url' +import { defineVitestConfig } from '@nuxt/test-utils/config' +import { defaultExclude, defineWorkspace, defineConfig } from 'vitest/config' +import vue from '@vitejs/plugin-vue' +import ui from './src/vite' +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 defineWorkspace([ + // Nuxt Tests + defineVitestConfig({ + test: { + name: 'nuxt', + testTimeout: 1000, + globals: true, + silent: true, + exclude: [...defaultExclude, './test/components/**.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)) + } + }), + // Vue Tests + defineConfig({ + test: { + name: 'vue', + 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() + 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') + } + } + } + ] + }) +])