|
1 | 1 | import { useHead, useSeoMeta } from 'unhead'
|
2 | 2 | import { renderSSRHead } from 'unhead/server'
|
| 3 | +import { transformHtmlTemplate } from 'unhead/server/transformHtmlTemplate' |
| 4 | +import { extractTagsFromHtml } from 'unhead/server/util/extractTagsFromHtml' |
3 | 5 | import { describe, it } from 'vitest'
|
4 | 6 | import { basicSchema } from '../../fixtures'
|
5 | 7 | import { createServerHeadWithContext } from '../../util'
|
@@ -214,4 +216,91 @@ describe('ssr', () => {
|
214 | 216 | }
|
215 | 217 | `)
|
216 | 218 | })
|
| 219 | + it('vite template', async () => { |
| 220 | + const html = `<!doctype html> |
| 221 | + <html lang="en"> |
| 222 | + <head> |
| 223 | + <meta charset="UTF-8" /> |
| 224 | + <link rel="icon" type="image/svg+xml" href="/vite.svg" /> |
| 225 | + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| 226 | + <title>Vite + Vue + TS</title> |
| 227 | + <!--app-head--> |
| 228 | + </head> |
| 229 | + <body> |
| 230 | + <div id="app"><!--app-html--></div> |
| 231 | + <script type="module" src="/src/entry-client.ts"></script> |
| 232 | + </body> |
| 233 | + </html>` |
| 234 | + const head = createServerHeadWithContext() |
| 235 | + head.push({ |
| 236 | + title: 'new title', |
| 237 | + meta: [ |
| 238 | + { charset: 'utf-16' }, |
| 239 | + ], |
| 240 | + }) |
| 241 | + expect(await transformHtmlTemplate(head, html)).toMatchInlineSnapshot(` |
| 242 | + "<!doctype html> |
| 243 | + <html lang="en"> |
| 244 | + <head> |
| 245 | + <!--app-head--> |
| 246 | + <meta charset="utf-16"> |
| 247 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 248 | + <title>new title</title> |
| 249 | + <link rel="icon" type="image/svg+xml" href="/vite.svg"></head> |
| 250 | + <body> |
| 251 | + <div id="app"><!--app-html--></div> |
| 252 | + <script type="module" src="/src/entry-client.ts"></script> |
| 253 | + </body> |
| 254 | + </html>" |
| 255 | + `) |
| 256 | + }) |
| 257 | + it('random template', async () => { |
| 258 | + const html = ` |
| 259 | + <html lang="en"> |
| 260 | + <head> |
| 261 | + <meta charset="UTF-8"> |
| 262 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 263 | + <title>Document</title> |
| 264 | + <link rel="stylesheet" href="style.css"> |
| 265 | + <script src="script.js" async type="module"></script> |
| 266 | + </head> |
| 267 | + <body style="accent-color: red;"> |
| 268 | + <div>hello</div> |
| 269 | + <script src="ssr.test.ts"></script> |
| 270 | + <script> |
| 271 | + console.log('hello') |
| 272 | +</script> |
| 273 | + </body> |
| 274 | + </html> |
| 275 | + ` |
| 276 | + const head = createServerHeadWithContext() |
| 277 | + head.push({ |
| 278 | + title: 'new title', |
| 279 | + bodyAttrs: { |
| 280 | + style: 'background-color: blue;', |
| 281 | + }, |
| 282 | + meta: [ |
| 283 | + { charset: 'utf-16' }, |
| 284 | + ], |
| 285 | + }) |
| 286 | + expect(await transformHtmlTemplate(head, html)).toMatchInlineSnapshot(` |
| 287 | + " |
| 288 | + <html lang="en"> |
| 289 | + <head> |
| 290 | + <meta charset="utf-16"> |
| 291 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 292 | + <title>new title</title> |
| 293 | + <link rel="stylesheet" href="style.css"> |
| 294 | + <script src="script.js" type="module"></script></head> |
| 295 | + <body style="background-color: blue; accent-color: red"> |
| 296 | + <div>hello</div> |
| 297 | + <script src="ssr.test.ts"></script> |
| 298 | + <script> |
| 299 | + console.log('hello') |
| 300 | + </script> |
| 301 | + </body> |
| 302 | + </html> |
| 303 | + " |
| 304 | + `) |
| 305 | + }) |
217 | 306 | })
|
0 commit comments