feat(ssr): serverPrefetch
This commit is contained in:
@@ -15,6 +15,7 @@ import { renderToStream as _renderToStream } from '../src/renderToStream'
|
||||
import { Readable } from 'stream'
|
||||
import { ssrRenderSlot } from '../src/helpers/ssrRenderSlot'
|
||||
import { ssrRenderComponent } from '../src/helpers/ssrRenderComponent'
|
||||
|
||||
const promisifyStream = (stream: Readable) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
let result = ''
|
||||
@@ -599,4 +600,23 @@ describe('ssr: renderToStream', () => {
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
test('serverPrefetch', async () => {
|
||||
const msg = Promise.resolve('hello')
|
||||
const app = createApp({
|
||||
data() {
|
||||
return {
|
||||
msg: ''
|
||||
}
|
||||
},
|
||||
async serverPrefetch() {
|
||||
this.msg = await msg
|
||||
},
|
||||
render() {
|
||||
return h('div', this.msg)
|
||||
}
|
||||
})
|
||||
const html = await renderToStream(app)
|
||||
expect(html).toBe(`<div>hello</div>`)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -14,6 +14,7 @@ import { escapeHtml } from '@vue/shared'
|
||||
import { renderToString } from '../src/renderToString'
|
||||
import { ssrRenderSlot, SSRSlot } from '../src/helpers/ssrRenderSlot'
|
||||
import { ssrRenderComponent } from '../src/helpers/ssrRenderComponent'
|
||||
|
||||
describe('ssr: renderToString', () => {
|
||||
test('should apply app context', async () => {
|
||||
const app = createApp({
|
||||
@@ -580,4 +581,23 @@ describe('ssr: renderToString', () => {
|
||||
).toHaveBeenWarned()
|
||||
})
|
||||
})
|
||||
|
||||
test('serverPrefetch', async () => {
|
||||
const msg = Promise.resolve('hello')
|
||||
const app = createApp({
|
||||
data() {
|
||||
return {
|
||||
msg: ''
|
||||
}
|
||||
},
|
||||
async serverPrefetch() {
|
||||
this.msg = await msg
|
||||
},
|
||||
render() {
|
||||
return h('div', this.msg)
|
||||
}
|
||||
})
|
||||
const html = await renderToString(app)
|
||||
expect(html).toBe(`<div>hello</div>`)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user