From 979e15db2a7512a89a2accbae5cd3ae37ffbedc5 Mon Sep 17 00:00:00 2001 From: Sebastien Chopin Date: Tue, 30 May 2017 18:18:01 +0200 Subject: [PATCH] Update JSDOM logic --- lib/render.js | 7 ++++--- test/error.test.js | 8 ++------ test/fixtures/with-config/app.html | 2 +- test/fixtures/with-config/pages/error.vue | 2 +- test/with-config.test.js | 2 +- 5 files changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/render.js b/lib/render.js index 92b4cf789e..ccdaefc07f 100644 --- a/lib/render.js +++ b/lib/render.js @@ -153,7 +153,7 @@ export async function renderAndGetWindow (url, opts = {}) { let options = { resources: 'usable', // load subresources (https://github.com/tmpvar/jsdom#loading-subresources) runScripts: 'dangerously', - beforeParse(window) { + beforeParse (window) { // Mock window.scrollTo window.scrollTo = () => {} } @@ -164,9 +164,10 @@ export async function renderAndGetWindow (url, opts = {}) { url = url || 'http://localhost:3000' const { window } = await jsdom.JSDOM.fromURL(url, options) // If Nuxt could not be loaded (error from the server-side) - if (!window.__NUXT__) { + const nuxtExists = window.document.body.innerHTML.includes('window.__NUXT__') + if (!nuxtExists) { let error = new Error('Could not load the nuxt app') - error.body = window.document.getElementsByTagName('body')[0].innerHTML + error.body = window.document.body.innerHTML throw error } // Used by nuxt.js to say when the components are loaded and the app ready diff --git a/test/error.test.js b/test/error.test.js index e12120ed2e..709b37b347 100644 --- a/test/error.test.js +++ b/test/error.test.js @@ -33,12 +33,8 @@ test('/404 should display an error too', async t => { }) test('/ with renderAndGetWindow()', async t => { - try { - await nuxt.renderAndGetWindow(url('/')) - } catch (e) { - t.true(e.message.includes('Could not load the nuxt app')) - t.true(e.body.includes('render function or template not defined in component')) - } + const err = await t.throws(nuxt.renderAndGetWindow(url('/'))) + t.is(err.response.statusCode, 500) }) // Close server and ask nuxt to stop listening to file changes diff --git a/test/fixtures/with-config/app.html b/test/fixtures/with-config/app.html index 86e25a09a2..97480a711e 100644 --- a/test/fixtures/with-config/app.html +++ b/test/fixtures/with-config/app.html @@ -4,7 +4,7 @@ {{ HEAD }} - {{ APP }}

Made by Nuxt.js team

+ {{ APP }} diff --git a/test/fixtures/with-config/pages/error.vue b/test/fixtures/with-config/pages/error.vue index f309c03407..a707538cd6 100644 --- a/test/fixtures/with-config/pages/error.vue +++ b/test/fixtures/with-config/pages/error.vue @@ -5,7 +5,7 @@ diff --git a/test/with-config.test.js b/test/with-config.test.js index bbce95a138..0e40937b32 100644 --- a/test/with-config.test.js +++ b/test/with-config.test.js @@ -78,7 +78,7 @@ test('/test/error', async t => { test('/test/user-agent', async t => { const window = await nuxt.renderAndGetWindow(url('/test/user-agent')) const html = window.document.body.innerHTML - t.true(html.includes('
Node.js'))
+  t.true(html.includes('
Mozilla'))
 })
 
 test('/test/about-bis (added with extendRoutes)', async t => {