From bf1bc7d01caf08b251b234f494323febb9b5eefc Mon Sep 17 00:00:00 2001 From: daiwei Date: Fri, 15 Aug 2025 10:03:22 +0800 Subject: [PATCH] test: add test for vapor slot render non-compiled vdom component --- .../runtime-vapor/__tests__/hydration.spec.ts | 102 +++++++++++++++--- 1 file changed, 85 insertions(+), 17 deletions(-) diff --git a/packages/runtime-vapor/__tests__/hydration.spec.ts b/packages/runtime-vapor/__tests__/hydration.spec.ts index c356293e17..80283b3d6b 100644 --- a/packages/runtime-vapor/__tests__/hydration.spec.ts +++ b/packages/runtime-vapor/__tests__/hydration.spec.ts @@ -55,19 +55,33 @@ function compile( ) } -async function testHydrationInterop( +async function testWithVaporApp( code: string, components?: Record, data?: any, ) { - return testHydration(code, components, data, { interop: true, vapor: false }) + return testHydration(code, components, data, { + isVaporApp: true, + interop: true, + }) +} + +async function testWithVDOMApp( + code: string, + components?: Record, + data?: any, +) { + return testHydration(code, components, data, { + isVaporApp: false, + interop: true, + }) } async function testHydration( code: string, components: Record = {}, data: any = ref('foo'), - { interop = false, vapor = true } = {}, + { isVaporApp = true, interop = false } = {}, ) { const ssrComponents: any = {} const clientComponents: any = {} @@ -85,7 +99,10 @@ async function testHydration( }) } - const serverComp = compile(code, data, ssrComponents, { vapor, ssr: true }) + const serverComp = compile(code, data, ssrComponents, { + vapor: isVaporApp, + ssr: true, + }) const html = await VueServerRenderer.renderToString( runtimeDom.createSSRApp(serverComp), ) @@ -94,16 +111,20 @@ async function testHydration( container.innerHTML = html const clientComp = compile(code, data, clientComponents, { - vapor, + vapor: isVaporApp, ssr: false, }) let app - if (interop) { + if (isVaporApp) { + app = createVaporSSRApp(clientComp) + } else { app = runtimeDom.createSSRApp(clientComp) + } + + if (interop) { app.use(runtimeVapor.vaporInteropPlugin) - } else { - app = createVaporSSRApp(clientComp) } + app.mount(container) return { data, container } } @@ -2945,9 +2966,9 @@ describe('Vapor Mode hydration', () => { }) describe('VDOM interop', () => { - test('basic vapor component', async () => { + test('basic render vapor component', async () => { const data = ref(true) - const { container } = await testHydrationInterop( + const { container } = await testWithVDOMApp( `