diff --git a/test/unhead/e2e/ssrHash.test.ts b/test/unhead/e2e/ssrHash.test.ts deleted file mode 100644 index 94472b50..00000000 --- a/test/unhead/e2e/ssrHash.test.ts +++ /dev/null @@ -1,201 +0,0 @@ -import { describe, it } from 'vitest' -import { HashHydrationPlugin, createHead, useHead, useServerHead } from 'unhead' -import { renderSSRHead } from '@unhead/ssr' -import { renderDOMHead } from '@unhead/dom' -import type { Head } from '@unhead/schema' -import { useDom } from '../../fixtures' - -describe('unhead e2e ssrHash', () => { - it('basic hydration', async () => { - // scenario: we are injecting root head schema which will not have a hydration step, - // but we are also injecting a child head schema which will have a hydration step - const ssrHead = createHead({ - plugins: [ - HashHydrationPlugin(), - ], - }) - // i.e App.vue - useServerHead({ - title: 'My amazing site', - htmlAttrs: { - lang: 'en', - }, - script: [ - { - src: 'https://analytics.example.com/script.js', - defer: true, - async: true, - }, - ], - meta: [ - { - name: 'description', - content: 'My amazing site', - }, - { - property: 'og:title', - content: 'My amazing site', - }, - { - property: 'og:description', - content: 'This is my amazing site', - }, - { - property: 'og:image', - content: [ - 'https://cdn.example.com/image.jpg', - 'https://cdn.example.com/image2.jpg', - ], - }, - { - charset: 'utf-8', - }, - ], - }) - // i.e pages/index.vue - const HomeHead: Head = { - title: 'Home', - script: [ - { - src: 'https://my-app.com/home.js', - }, - ], - meta: [ - { - property: 'og:title', - content: 'Home', - }, - { - name: 'description', - content: 'This is the home page', - }, - ], - } - useHead(HomeHead) - - const data = await renderSSRHead(ssrHead) - - expect(data).toMatchInlineSnapshot(` - { - "bodyAttrs": "", - "bodyTags": "", - "bodyTagsOpen": "", - "headTags": " - Home - - - - - - - - ", - "htmlAttrs": " lang=\\"en\\"", - } - `) - - const dom = useDom(data) - - const csrHead = createHead({ - document: dom.window.document, - plugins: [ - HashHydrationPlugin(), - ], - }) - csrHead.push(HomeHead) - - let renderingTags = false - csrHead.hooks.hook('dom:rendered', (ctx) => { - // renderingTags = true - renderingTags = true - }) - - await renderDOMHead(csrHead, { document: dom.window.document }) - - // didn't render any tags, we hydrated - expect(renderingTags).toBe(false) - - expect(dom.serialize()).toMatchInlineSnapshot(` - " - - Home - - - - - - - - - - - -
-

hello world

-
- - - - " - `) - }) - - it('ssr to csr', async () => { - // scenario: we are injecting root head schema which will not have a hydration step, - // but we are also injecting a child head schema which will have a hydration step - const ssrHead = createHead({ - plugins: [ - HashHydrationPlugin(), - ], - }) - // i.e App.vue - useServerHead({ - title: 'My amazing site', - }) - - const data = await renderSSRHead(ssrHead) - - expect(data).toMatchInlineSnapshot(` - { - "bodyAttrs": "", - "bodyTags": "", - "bodyTagsOpen": "", - "headTags": "My amazing site - - ", - "htmlAttrs": "", - } - `) - - const dom = useDom(data) - - const csrHead = createHead({ - document: dom.window.document, - plugins: [ - HashHydrationPlugin(), - ], - }) - csrHead.push({ - title: 'new title', - }) - - await renderDOMHead(csrHead, { document: dom.window.document }) - - expect(dom.serialize()).toMatchInlineSnapshot(` - " - new title - - - - - -
-

hello world

-
- - - - " - `) - }) -})