Skip to content

Commit

Permalink
fix(ssr): fix bundleRenderer Promise rejection regression
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Sep 14, 2017
1 parent 5376dab commit 0c9534f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/server/bundle-renderer/create-bundle-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export function createBundleRunner (entry, files, basedir, runInNewContext) {
// slightly differently.
let runner // lazy creation so that errors can be caught by user
let initialContext
return (userContext = {}) => new Promise(resolve => {
return (userContext = {}) => new Promise((resolve, reject) => {
if (!runner) {
const sandbox = runInNewContext === 'once'
? createSandbox()
Expand Down Expand Up @@ -143,7 +143,7 @@ export function createBundleRunner (entry, files, basedir, runInNewContext) {

const res = runner(userContext)
if (typeof res.then === 'function') {
res.then(exposeStylesAndResolve)
res.then(exposeStylesAndResolve).catch(reject)
} else {
exposeStylesAndResolve(res)
}
Expand Down
3 changes: 3 additions & 0 deletions test/ssr/fixtures/promise-rejection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default () => {
return Promise.reject(new Error('foo'))
}
19 changes: 19 additions & 0 deletions test/ssr/ssr-bundle-render.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ function createAssertions (runInNewContext) {
})
})

it('renderToString catch Promise rejection', done => {
createRenderer('promise-rejection.js', { runInNewContext }, renderer => {
renderer.renderToString(err => {
expect(err.message).toBe('foo')
done()
})
})
})

it('renderToStream catch error', done => {
createRenderer('error.js', { runInNewContext }, renderer => {
const stream = renderer.renderToStream()
Expand All @@ -85,6 +94,16 @@ function createAssertions (runInNewContext) {
})
})

it('renderToStream catch Promise rejection', done => {
createRenderer('error.js', { runInNewContext }, renderer => {
const stream = renderer.renderToStream()
stream.on('error', err => {
expect(err.message).toBe('foo')
done()
})
})
})

it('render with cache (get/set)', done => {
const cache = {}
const get = jasmine.createSpy('get')
Expand Down

0 comments on commit 0c9534f

Please sign in to comment.