File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /**
2+ * Global setup for Nuxt vitest environment.
3+ *
4+ * This file stubs globals that are normally initialized by inline scripts
5+ * injected into the HTML document, which don't run in vitest's nuxt environment.
6+ */
7+
8+ // Stub the @nuxtjs /color-mode global helper
9+ // The color-mode module injects a script that initializes this on window,
10+ // but in vitest the script never runs since the HTML page isn't SSR'd.
11+ // See: https://github.com/nuxt-modules/color-mode/issues/335
12+ if ( typeof window !== 'undefined' ) {
13+ const globalName = '__NUXT_COLOR_MODE__'
14+
15+ // @ts -expect-error - dynamic global name
16+ if ( ! window [ globalName ] ) {
17+ // @ts -expect-error - dynamic global name
18+ window [ globalName ] = {
19+ preference : 'system' ,
20+ value : 'dark' ,
21+ getColorScheme : ( ) => 'dark' ,
22+ addColorScheme : ( ) => { } ,
23+ removeColorScheme : ( ) => { } ,
24+ }
25+ }
26+ }
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ export default defineConfig({
2525 name : 'nuxt' ,
2626 include : [ 'test/nuxt/**/*.{test,spec}.ts' ] ,
2727 environment : 'nuxt' ,
28+ setupFiles : [ './test/nuxt/setup.ts' ] ,
2829 environmentOptions : {
2930 nuxt : {
3031 rootDir : fileURLToPath ( new URL ( '.' , import . meta. url ) ) ,
@@ -59,6 +60,7 @@ export default defineConfig({
5960 'shared/utils/spdx.ts' ,
6061 'shared/utils/url.ts' ,
6162 'server/utils/readme.ts' ,
63+ 'server/utils/docs/text.ts' ,
6264 'server/utils/code-highlight.ts' ,
6365 'server/utils/npm.ts' ,
6466 'server/utils/shiki.ts' ,
You can’t perform that action at this time.
0 commit comments