Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: setup vitest workspace #2842

Draft
wants to merge 3 commits into
base: v3
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/ci-v3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
19 changes: 0 additions & 19 deletions vitest.config.ts

This file was deleted.

56 changes: 0 additions & 56 deletions vitest.vue.config.ts

This file was deleted.

79 changes: 79 additions & 0 deletions vitest.workspace.ts
Original file line number Diff line number Diff line change
@@ -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<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')
}
}
}
]
})
])
Loading