import Vue from '../../dist/vue.common.js' import { compileToFunctions } from '../../packages/vue-template-compiler' import createRenderer from '../../packages/vue-server-renderer' const { renderToStream } = createRenderer() describe('SSR: renderToStream', () => { it('should render to a stream', done => { const stream = renderVmWithOptions({ template: `

yoyo

{{ test }}
`, data: { test: 'hi', isRed: true, testClass: 'a' }, components: { bComp (resolve) { return resolve({ render () { return this.$createElement('test-async-2') }, components: { testAsync2 (resolve) { return resolve({ created () { this.$parent.$parent.testClass = 'b' }, render () { return this.$createElement('div', { class: [this.$parent.$parent.testClass] }, 'test') } }) } } }) }, cComp: { render () { return this.$createElement('div', { class: [this.$parent.testClass] }, 'test') } } } }) let res = '' stream.on('data', chunk => { res += chunk }) stream.on('end', () => { expect(res).toContain( '
' + '

yoyo

' + '
' + 'hi ' + ' ' + '
test
' + '
test
' + '
' ) done() }) }) it('should catch error', done => { const stream = renderToStream(new Vue({ render () { throw new Error('oops') } })) stream.on('error', err => { expect(err.toString()).toMatch(/oops/) done() }) stream.on('data', _ => _) }) }) function renderVmWithOptions (options) { const res = compileToFunctions(options.template) Object.assign(options, res) delete options.template return renderToStream(new Vue(options)) }