feat(ssr): serverPrefetch

This commit is contained in:
Evan You
2020-09-01 22:52:46 -04:00
parent 63f1f18064
commit c73b4a0e10
4 changed files with 55 additions and 5 deletions

View File

@@ -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>`)
})
})

View File

@@ -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>`)
})
})