From 21ed8933cacef86b00f6dc77a4ae1e3953232ee1 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Fri, 6 Dec 2024 14:33:17 +0800 Subject: [PATCH 1/3] chore: setup vitest workspace --- .github/workflows/ci-v3.yml | 3 --- package.json | 3 ++- vitest.config.ts | 19 --------------- vitest.vue.config.ts => vitest.workspace.ts | 26 ++++++++++++++++++++- 4 files changed, 27 insertions(+), 24 deletions(-) delete mode 100644 vitest.config.ts rename vitest.vue.config.ts => vitest.workspace.ts (71%) diff --git a/.github/workflows/ci-v3.yml b/.github/workflows/ci-v3.yml index 728a1ad4a3..ab557d367a 100644 --- a/.github/workflows/ci-v3.yml +++ b/.github/workflows/ci-v3.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 1ac48e6f4e..0006a4450b 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.workspace.ts similarity index 71% rename from vitest.vue.config.ts rename to vitest.workspace.ts index f8be296ae9..aec9aebbea 100644 --- a/vitest.vue.config.ts +++ b/vitest.workspace.ts @@ -1,3 +1,6 @@ +import { fileURLToPath } from 'node:url' +import { defineVitestConfig } from '@nuxt/test-utils/config' +import { defaultExclude, defineWorkspace} from 'vitest/config' import vue from '@vitejs/plugin-vue' import ui from './src/vite' import { defineConfig } from 'vitest/config' @@ -7,8 +10,26 @@ 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({ +export default defineWorkspace([ + defineVitestConfig({ + test: { + name: 'nuxt', + 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)) + } + }), + defineConfig({ test: { + name: 'vue', environment: 'happy-dom', silent: true, include: ['./test/components/**.spec.ts'], @@ -54,3 +75,6 @@ export default defineConfig({ } ] }) + +]) + From 91c1105a05d166d5725663784bce1ee1c446ce50 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Fri, 6 Dec 2024 14:40:27 +0800 Subject: [PATCH 2/3] chore: lint --- vitest.workspace.ts | 89 ++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 45 deletions(-) diff --git a/vitest.workspace.ts b/vitest.workspace.ts index aec9aebbea..6dd2f0d32a 100644 --- a/vitest.workspace.ts +++ b/vitest.workspace.ts @@ -1,9 +1,8 @@ import { fileURLToPath } from 'node:url' import { defineVitestConfig } from '@nuxt/test-utils/config' -import { defaultExclude, defineWorkspace} from 'vitest/config' +import { defaultExclude, defineWorkspace, defineConfig } from 'vitest/config' import vue from '@vitejs/plugin-vue' import ui from './src/vite' -import { defineConfig } from 'vitest/config' import { glob } from 'tinyglobby' import { resolve } from 'pathe' @@ -11,6 +10,7 @@ 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', @@ -27,54 +27,53 @@ export default defineWorkspace([ 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') - } + 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}`) } }, - { - name: 'nuxt-ui-test:components', - enforce: 'pre', - resolveId(id) { - if (id === '#components') { - return '#components' + 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') + } } }, - 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') + { + 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') + } } } - } - ] -}) - + ] + }) ]) - From df182ca4ee4f93429f14be3a0f0df534ea6fdbd6 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Fri, 6 Dec 2024 15:48:29 +0800 Subject: [PATCH 3/3] chore: update --- vitest.workspace.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vitest.workspace.ts b/vitest.workspace.ts index 6dd2f0d32a..94776bbb47 100644 --- a/vitest.workspace.ts +++ b/vitest.workspace.ts @@ -17,7 +17,7 @@ export default defineWorkspace([ testTimeout: 1000, globals: true, silent: true, - exclude: [...defaultExclude, './test/vue/**.spec.ts'], + exclude: [...defaultExclude, './test/components/**.spec.ts'], environment: 'nuxt', environmentOptions: { nuxt: {