@@ -93,6 +93,21 @@ async function runPluginTransform(plugin: any, code: string, id: string, context
9393 return await transformHandler ( plugin ) . call ( context , code , id )
9494}
9595
96+ function assertTransformResult ( result : unknown , name : string ) {
97+ if (
98+ typeof result === 'string'
99+ || (
100+ typeof result === 'object'
101+ && result !== null
102+ && 'code' in result
103+ && typeof ( result as { code ?: unknown } ) . code === 'string'
104+ )
105+ ) {
106+ return
107+ }
108+ throw new TypeError ( `${ name } benchmark did not transform its fixture` )
109+ }
110+
96111describe ( 'unplugin transform CPU' , ( ) => {
97112 bench ( 'transformInclude mixed ids' , ( ) => {
98113 const seo = UseSeoMetaTransform . vite ( { } ) as any
@@ -112,17 +127,25 @@ describe('unplugin transform CPU', () => {
112127
113128 bench ( 'useSeoMetaTransform static calls' , async ( ) => {
114129 const plugin = UseSeoMetaTransform . vite ( { } ) as any
115- await runPluginTransform ( plugin , seoCode , '/project/src/page.ts' )
130+ const result = await runPluginTransform ( plugin , seoCode , '/project/src/page.ts' )
131+ assertTransformResult ( result , plugin . name )
116132 } )
117133
118134 bench ( 'minifyTransform inline script/style' , async ( ) => {
119135 const plugin = MinifyTransform . vite ( { js : mockJSMinifier , css : mockCSSMinifier } ) as any
120- await runPluginTransform ( plugin , minifyCode , '/project/src/page.ts' )
136+ const result = await runPluginTransform ( plugin , minifyCode , '/project/src/page.ts' )
137+ assertTransformResult ( result , plugin . name )
121138 } )
122139
123140 bench ( 'treeshakeServerComposables many calls' , async ( ) => {
124141 const plugin = TreeshakeServerComposables . vite ( { } ) as any
125- await runPluginTransform ( plugin , treeshakeCode , '/project/src/page.ts' )
142+ const result = await runPluginTransform (
143+ plugin ,
144+ treeshakeCode ,
145+ '/project/src/page.ts' ,
146+ { environment : { config : { consumer : 'client' } } } ,
147+ )
148+ assertTransformResult ( result , plugin . name )
126149 } )
127150
128151 bench ( 'treeshakeServerComposables skip unrelated code' , async ( ) => {
@@ -133,7 +156,8 @@ describe('unplugin transform CPU', () => {
133156 bench ( 'ssrStaticReplace many head.ssr reads' , async ( ) => {
134157 const plugin = SSRStaticReplace . vite ( { } ) as any
135158 plugin . apply ( { } , { command : 'build' , isSsrBuild : false } )
136- await runPluginTransform ( plugin , ssrStaticReplaceCode , '/project/node_modules/unhead/dist/index.mjs' )
159+ const result = await runPluginTransform ( plugin , ssrStaticReplaceCode , '/project/node_modules/unhead/dist/index.mjs' )
160+ assertTransformResult ( result , plugin . name )
137161 } )
138162
139163 bench ( 'ssrStaticReplace skip unrelated code' , async ( ) => {
@@ -154,7 +178,8 @@ describe('unplugin transform CPU', () => {
154178 } )
155179 const plugin = CreateHeadTransform ( ctx ) as any
156180 plugin . configResolved ( { root : '/project' } )
157- await plugin . transform . handler . call ( { environment : { config : { consumer : 'client' } } } , createHeadCode , '/project/src/head.ts' )
181+ const result = await plugin . transform . handler . call ( { environment : { config : { consumer : 'client' } } } , createHeadCode , '/project/src/head.ts' )
182+ assertTransformResult ( result , plugin . name )
158183 } )
159184
160185 bench ( 'react streaming skip JSX without head calls' , async ( ) => {
@@ -164,7 +189,8 @@ describe('unplugin transform CPU', () => {
164189
165190 bench ( 'react streaming transform JSX with head calls' , async ( ) => {
166191 const plugin = unheadReactStreamingPlugin . vite ( { } ) as any
167- await plugin . transform . handler . call ( { environment : { name : 'client' } } , jsxWithHeadCode , '/project/src/page.tsx' )
192+ const result = await plugin . transform . handler . call ( { environment : { name : 'client' } } , jsxWithHeadCode , '/project/src/page.tsx' )
193+ assertTransformResult ( result , plugin . name )
168194 } )
169195
170196 bench ( 'solid streaming skip JSX without head calls' , async ( ) => {
0 commit comments