11import type { Nuxt } from 'nuxt/schema'
2- import type { ResolvedConfig } from 'vite'
2+ import type { ResolvedConfig , ViteDevServer } from 'vite'
33import {
44 getDataSource ,
55 resetDataSources ,
@@ -50,12 +50,23 @@ function fakeViteConfig(overrides: Partial<ResolvedConfig> = {}): ResolvedConfig
5050 } as unknown as ResolvedConfig
5151}
5252
53- /** Drive Nuxt's `vite:configResolved` hook for one environment. */
54- async function captureViteEnv ( fake : FakeNuxt , envName : 'client' | 'ssr' , config : ResolvedConfig ) {
55- await fake . callHook ( 'vite:configResolved' , config , {
56- isClient : envName === 'client' ,
57- isServer : envName === 'ssr' ,
58- } )
53+ /**
54+ * Minimal Vite dev server stub. The resolved config lives at `.config`, and the
55+ * runtime environments at `.environments`, mirroring `ViteDevServer`.
56+ */
57+ function fakeViteServer ( config : ResolvedConfig = fakeViteConfig ( ) ) : ViteDevServer {
58+ return {
59+ config,
60+ environments : { client : { name : 'client' } , ssr : { name : 'ssr' } } ,
61+ } as unknown as ViteDevServer
62+ }
63+
64+ /**
65+ * Drive Nuxt's `vite:serverCreated` hook. Nuxt 5 unified the client and SSR
66+ * Vite servers into a single instance, so this fires once with one dev server.
67+ */
68+ async function captureVite ( fake : FakeNuxt , server : ViteDevServer ) {
69+ await fake . callHook ( 'vite:serverCreated' , server )
5970}
6071
6172beforeEach ( ( ) => {
@@ -77,16 +88,18 @@ describe('data-inspector source registration', () => {
7788 expect ( typeof entry ! . data ) . toBe ( 'function' )
7889 } )
7990
80- it ( 'exposes the four read-only suggested queries with function exclusion' , ( ) => {
91+ it ( 'exposes the read-only suggested queries with function exclusion' , ( ) => {
8192 const { nuxt } = fakeNuxt ( )
8293 setup ( { nuxt } as any )
8394
8495 const queries = getDataSource ( 'nuxt:application' ) ! . queries !
8596 expect ( queries ) . toEqual ( [
8697 { title : 'Overview' , query : '' , excludeFunctions : true } ,
87- { title : 'Nuxt options' , query : 'nuxt' , excludeFunctions : true } ,
88- { title : 'Nitro options' , query : 'nitro' , excludeFunctions : true } ,
89- { title : 'Vite configs' , query : 'vite' , excludeFunctions : true } ,
98+ { title : 'Nuxt modules' , query : 'nuxt.modules' , excludeFunctions : true } ,
99+ { title : 'Vite plugins' , query : 'vite.config.plugins' , excludeFunctions : true } ,
100+ { title : 'Vite config' , query : 'vite.config' , excludeFunctions : true } ,
101+ { title : 'Vite environments' , query : 'vite.environments' , excludeFunctions : true } ,
102+ { title : 'Nitro routes' , query : 'nitro.handlers' , excludeFunctions : true } ,
90103 ] )
91104 } )
92105
@@ -98,26 +111,25 @@ describe('data-inspector source registration', () => {
98111 const data = await resolveSourceData ( getDataSource ( 'nuxt:application' ) ! ) as any
99112 expect ( data . nuxt ) . toBe ( options )
100113 expect ( data . nitro ) . toBeUndefined ( )
101- expect ( data . vite ) . toEqual ( { client : undefined , ssr : undefined } )
114+ expect ( data . vite ) . toBeUndefined ( )
102115 } )
103116
104- it ( 'populates Nitro and raw Vite configs after the hooks fire' , async ( ) => {
117+ it ( 'populates Nitro and the raw unified Vite dev server after the hooks fire' , async ( ) => {
105118 const fake = fakeNuxt ( )
106119 setup ( { nuxt : fake . nuxt } as any )
107120
108121 const nitro = { options : { preset : 'node' } }
109122 await fake . callHook ( 'nitro:build:before' , nitro )
110123
111- const client = fakeViteConfig ( { marker : 'client' } as any )
112- const ssr = fakeViteConfig ( { marker : 'ssr' } as any )
113- await captureViteEnv ( fake , 'client' , client )
114- await captureViteEnv ( fake , 'ssr' , ssr )
124+ const server = fakeViteServer ( fakeViteConfig ( { marker : 'vite' } as any ) )
125+ await captureVite ( fake , server )
115126
116127 const data = await resolveSourceData ( getDataSource ( 'nuxt:application' ) ! ) as any
117128 expect ( data . nitro ) . toBe ( nitro . options )
118- // The live source hands the RAW config objects to the Data Inspector engine.
119- expect ( data . vite . client ) . toBe ( client )
120- expect ( data . vite . ssr ) . toBe ( ssr )
129+ // The live source hands the RAW dev server instance to the Data Inspector
130+ // engine; the resolved config is reachable at `vite.config`.
131+ expect ( data . vite ) . toBe ( server )
132+ expect ( data . vite . config ) . toBe ( server . config )
121133 } )
122134
123135 it ( 'unregisters the source on the Nuxt `close` hook' , async ( ) => {
@@ -131,28 +143,32 @@ describe('data-inspector source registration', () => {
131143} )
132144
133145describe ( 'getServerData deprecated shim' , ( ) => {
134- it ( 'returns the legacy `vite: { server, client }` shape with normalized configs ' , async ( ) => {
146+ it ( 'projects the unified config onto the legacy `vite: { server, client }` shape, normalized' , async ( ) => {
135147 const options = { appId : 'app' }
136148 const fake = fakeNuxt ( options )
137149 setup ( { nuxt : fake . nuxt } as any )
138150
139151 const nitro = { options : { preset : 'node' } }
140152 await fake . callHook ( 'nitro:build:before' , nitro )
141- await captureViteEnv ( fake , 'client' , fakeViteConfig ( ) )
142- await captureViteEnv ( fake , 'ssr' , fakeViteConfig ( ) )
153+ await captureVite ( fake , fakeViteServer ( ) )
143154
144155 const warn = vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } )
145156 const data = getServerData ( fake . nuxt )
146157 warn . mockRestore ( )
147158
148159 expect ( data . nuxt ) . toBe ( options )
149160 expect ( data . nitro ) . toBe ( nitro . options )
150- // Legacy field naming: `ssr` capture maps to `vite.server`.
161+ // Nuxt 5 has one Vite dev server; the shim reads its resolved config
162+ // (`server.config`) and projects it onto both fields.
151163 expect ( data . vite ) . toHaveProperty ( 'server' )
152164 expect ( data . vite ) . toHaveProperty ( 'client' )
165+ // Each field is normalized independently (separate object identities).
166+ expect ( data . vite . server ) . not . toBe ( data . vite . client )
153167 // Normalization strips the live Vite branches for RPC transport.
154168 expect ( data . vite . server ! . inlineConfig ) . toBeNull ( )
155169 expect ( ( data . vite . server ! . plugins [ 0 ] as any ) . api ) . toBeUndefined ( )
170+ expect ( data . vite . client ! . inlineConfig ) . toBeNull ( )
171+ expect ( ( data . vite . client ! . plugins [ 0 ] as any ) . api ) . toBeUndefined ( )
156172 } )
157173
158174 it ( 'emits the NDT_DEP_0009 deprecation once per process' , ( ) => {
0 commit comments