Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

chore(deps): update test packages #290

Closed
wants to merge 18 commits into from
Closed
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"devDependencies": {
"@nuxt/eslint-config": "0.2.0",
"@nuxt/schema": "3.7.4",
"@vitest/coverage-v8": "0.33.0",
"@vitest/coverage-v8": "0.34.6",
"changelogen": "0.5.5",
"eslint": "8.51.0",
"eslint-config-prettier": "9.0.0",
Expand All @@ -31,7 +31,7 @@
"prettier": "3.0.3",
"typescript": "5.2.2",
"unbuild": "2.0.0",
"vitest": "0.33.0",
"vitest": "0.34.6",
"vue": "3.3.4",
"vue-tsc": "1.8.19"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/nuxt-vitest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@
"@vitejs/plugin-vue": "*",
"@vitejs/plugin-vue-jsx": "*",
"vite": "*",
"vitest": "^0.24.5 || ^0.26.0 || ^0.27.0 || ^0.28.0 || ^0.29.0 || ^0.30.0 || ^0.33.0"
"vitest": "^0.24.5 || ^0.26.0 || ^0.27.0 || ^0.28.0 || ^0.29.0 || ^0.30.0 || ^0.33.0 || ^0.34.6"
},
"dependencies": {
"@nuxt/kit": "^3.7.4",
"@vitest/ui": "^0.33.0",
"@vitest/ui": "^0.34.0",
"defu": "^6.1.2",
"get-port-please": "^3.1.1",
"perfect-debounce": "^1.0.0",
Expand All @@ -62,6 +62,6 @@
"@nuxt/module-builder": "0.5.2",
"@nuxt/schema": "3.7.4",
"nuxt": "3.7.4",
"vitest": "0.33.0"
"vitest": "0.34.6"
}
}
74 changes: 50 additions & 24 deletions packages/nuxt-vitest/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ const vuePlugins = {

export async function getVitestConfigFromNuxt(
options?: GetVitestConfigOptions,
overrides?: NuxtConfig
overrides?: NuxtConfig,
userConfig?: InlineConfig
): Promise<InlineConfig & { test: VitestConfig }> {
const { rootDir = process.cwd(), ..._overrides } = overrides || {}
if (!options) options = await startNuxtAndGetViteConfig(rootDir, _overrides)
Expand Down Expand Up @@ -109,52 +110,77 @@ export async function getVitestConfigFromNuxt(
test: {
...options.viteConfig.test,
dir: process.cwd(),
...userConfig?.test,
environmentOptions: {
...options.viteConfig.test?.environmentOptions,
nuxt: {
rootId: options.nuxt.options.app.rootId || undefined,
...options.viteConfig.test?.environmentOptions?.nuxt,
},
nuxtRuntimeConfig: options.nuxt.options.runtimeConfig,
nuxtRouteRules: defu({}, options.nuxt.options.routeRules, options.nuxt.options.nitro?.routeRules)
nuxtRouteRules: defu({}, options.nuxt.options.routeRules, options.nuxt.options.nitro?.routeRules),
...userConfig?.test?.environmentOptions,
},
// TODO: remove workaround
deps: {
...options.viteConfig.test?.deps,
optimizer: {
...options.viteConfig.test?.deps?.optimizer,
web: {
enabled: false,
},
},
...userConfig?.test?.deps,
},
environmentMatchGlobs: [
['**/*.nuxt.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}', 'nuxt'],
['{test,tests}/nuxt/**.*', 'nuxt'],
...(options.viteConfig.test?.environmentMatchGlobs || []),
...(userConfig?.test?.environmentMatchGlobs || []),
],
deps: {
...options.viteConfig.test?.deps,
inline: [
// vite-node defaults
/\/node_modules\/(.*\/)?(nuxt|nuxt3)\//,
/^#/,
// additional deps
'vitest-environment-nuxt',
...(options.nuxt.options.build.transpile.filter(
r => typeof r === 'string' || r instanceof RegExp
) as Array<string | RegExp>),
...(typeof options.viteConfig.test?.deps?.inline !== 'boolean'
? typeof options.viteConfig.test?.deps?.inline
: []),
],
server: {
...options.viteConfig.test?.server,
deps: {
...options.viteConfig.test?.server?.deps,
inline: [
// vite-node defaults
/\/node_modules\/(.*\/)?(nuxt|nuxt3)\//,
/^#/,
// additional deps
'vitest-environment-nuxt',
...(options.nuxt.options.build.transpile.filter(
r => typeof r === 'string' || r instanceof RegExp
) as Array<string | RegExp>),
...(typeof options.viteConfig.test?.deps?.inline !== 'boolean'
? typeof options.viteConfig.test?.deps?.inline
: []),
],
},
...userConfig?.test?.server,
},
},
}
}

export function defineVitestConfig(config: InlineConfig = {}) {
export function defineVitestConfig(userConfig: InlineConfig = {}) {
return defineConfig(async () => {
// When Nuxt module calls `startVitest`, we don't need to call `getVitestConfigFromNuxt` again
if (process.env.__NUXT_VITEST_RESOLVED__) return config
if (process.env.__NUXT_VITEST_RESOLVED__) return userConfig

const overrides = config.test?.environmentOptions?.nuxt?.overrides || {}
overrides.rootDir = config.test?.environmentOptions?.nuxt?.rootDir
const overrides = userConfig.test?.environmentOptions?.nuxt?.overrides || {}
overrides.rootDir = userConfig.test?.environmentOptions?.nuxt?.rootDir

return mergeConfig(
await getVitestConfigFromNuxt(undefined, overrides),
config
const fromNuxt = await getVitestConfigFromNuxt(
undefined,
overrides,
userConfig
)
const merged = mergeConfig(fromNuxt, userConfig)

// `mergeConfig` does not handle `test` merging, we resolved it in `getVitestConfigFromNuxt`
merged.test = fromNuxt.test

return merged
})
}

Expand Down
23 changes: 5 additions & 18 deletions packages/vitest-environment-nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.11.0",
"description": "An vitest environment with support for testing code that needs a Nuxt runtime environment.",
"repository": "danielroe/nuxt-vitest",
"type": "module",
"keywords": [
"nuxt",
"vitest",
Expand All @@ -21,25 +22,11 @@
"release": "changelogen --release --no-commit --no-tag",
"prepublishOnly": "pnpm build"
},
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
"./utils": {
"types": "./dist/utils.d.ts",
"require": "./dist/utils.cjs",
"import": "./dist/utils.mjs"
},
"./module": {
"types": "./dist/module.d.ts",
"require": "./dist/module.cjs",
"import": "./dist/module.mjs"
},
".": {
"types": "./dist/index.d.ts",
"require": "./dist/index.cjs",
"import": "./dist/index.mjs"
}
"./utils": "./dist/utils.mjs",
"./module": "./dist/module.mjs",
".": "./dist/index.mjs"
},
"files": [
"dist",
Expand Down Expand Up @@ -69,7 +56,7 @@
"@testing-library/vue": "7.0.0",
"happy-dom": "^9.10.9 || ^10.0.0 || ^11.0.0 || ^12.0.0",
"jsdom": "^22.0.0",
"vitest": "^0.24.5 || ^0.26.0 || ^0.27.0 || ^0.28.0 || ^0.29.0 || ^0.30.0 || ^0.33.0",
"vitest": "^0.24.5 || ^0.26.0 || ^0.27.0 || ^0.28.0 || ^0.29.0 || ^0.30.0 || ^0.33.0 || ^0.34.6",
"vue": "^3.2.45",
"vue-router": "^4.0.0"
},
Expand Down
1 change: 1 addition & 0 deletions packages/vitest-environment-nuxt/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import jsdom from './env/jsdom'

export default <Environment>{
name: 'nuxt',
transformMode: 'web',
async setup(global, environmentOptions) {
const url = joinURL(
'http://localhost:3000',
Expand Down
11 changes: 6 additions & 5 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// https://v3.nuxtjs.org/api/configuration/nuxt.config
import { fileURLToPath } from 'node:url'

export default defineNuxtConfig({
modules: ['nuxt-vitest', '@nuxt/devtools', '~/modules/custom'],
vitest: {
Expand All @@ -15,12 +16,12 @@ export default defineNuxtConfig({
// TODO: fix bug with stubbing root package
resolve: {
alias: {
'nuxt-vitest/config': '../packages/vitest-environment-nuxt/src/config',
'nuxt-vitest/utils': '../packages/vitest-environment-nuxt/src/utils',
'nuxt-vitest/config': fileURLToPath(new URL('../packages/vitest-environment-nuxt/src/config', import.meta.url)),
'nuxt-vitest/utils': fileURLToPath(new URL('../packages/vitest-environment-nuxt/src/utils', import.meta.url)),
'vitest-environment-nuxt/utils':
'../packages/vitest-environment-nuxt/src/utils',
fileURLToPath(new URL('../packages/vitest-environment-nuxt/src/utils', import.meta.url)),
'vitest-environment-nuxt':
'../packages/vitest-environment-nuxt/src/index',
fileURLToPath(new URL('../packages/vitest-environment-nuxt/src/index', import.meta.url)),
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"nuxt": "3.7.4",
"nuxt-vitest": "0.11.0",
"typescript": "5.2.2",
"vitest": "0.33.0",
"vitest": "0.34.6",
"vitest-environment-nuxt": "0.11.0",
"vue-tsc": "1.8.19"
},
Expand Down
Loading
Loading