Skip to content
Merged
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
26 changes: 26 additions & 0 deletions test/nuxt/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Global setup for Nuxt vitest environment.
*
* This file stubs globals that are normally initialized by inline scripts
* injected into the HTML document, which don't run in vitest's nuxt environment.
*/

// Stub the @nuxtjs/color-mode global helper
// The color-mode module injects a script that initializes this on window,
// but in vitest the script never runs since the HTML page isn't SSR'd.
// See: https://github.com/nuxt-modules/color-mode/issues/335
if (typeof window !== 'undefined') {
const globalName = '__NUXT_COLOR_MODE__'

// @ts-expect-error - dynamic global name
if (!window[globalName]) {
// @ts-expect-error - dynamic global name
window[globalName] = {
preference: 'system',
value: 'dark',
getColorScheme: () => 'dark',
addColorScheme: () => {},
removeColorScheme: () => {},
}
}
}
2 changes: 2 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default defineConfig({
name: 'nuxt',
include: ['test/nuxt/**/*.{test,spec}.ts'],
environment: 'nuxt',
setupFiles: ['./test/nuxt/setup.ts'],
environmentOptions: {
nuxt: {
rootDir: fileURLToPath(new URL('.', import.meta.url)),
Expand Down Expand Up @@ -59,6 +60,7 @@ export default defineConfig({
'shared/utils/spdx.ts',
'shared/utils/url.ts',
'server/utils/readme.ts',
'server/utils/docs/text.ts',
'server/utils/code-highlight.ts',
'server/utils/npm.ts',
'server/utils/shiki.ts',
Expand Down