diff --git a/src/server/bundle-renderer/create-bundle-runner.js b/src/server/bundle-renderer/create-bundle-runner.js index b5594a8b2a..dd1e537393 100644 --- a/src/server/bundle-renderer/create-bundle-runner.js +++ b/src/server/bundle-renderer/create-bundle-runner.js @@ -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() @@ -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) } diff --git a/test/ssr/fixtures/promise-rejection.js b/test/ssr/fixtures/promise-rejection.js new file mode 100644 index 0000000000..40dcccf3dd --- /dev/null +++ b/test/ssr/fixtures/promise-rejection.js @@ -0,0 +1,3 @@ +export default () => { + return Promise.reject(new Error('foo')) +} diff --git a/test/ssr/ssr-bundle-render.spec.js b/test/ssr/ssr-bundle-render.spec.js index 0c0343f43c..6b9588e926 100644 --- a/test/ssr/ssr-bundle-render.spec.js +++ b/test/ssr/ssr-bundle-render.spec.js @@ -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() @@ -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')