mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
fix tests
This commit is contained in:
parent
8391f308b7
commit
56c39bea88
10
lib/build.js
10
lib/build.js
@ -43,6 +43,10 @@ let webpackStats = 'none'
|
|||||||
// force green color
|
// force green color
|
||||||
debug.color = 2
|
debug.color = 2
|
||||||
|
|
||||||
|
// temporary fix for vuejs/vue#5540 until new vue server renderer release
|
||||||
|
const uniq = require('lodash').uniq
|
||||||
|
const fixClientManifest = manifest => Object.assign(manifest, {initial: uniq(manifest.initial)})
|
||||||
|
|
||||||
const defaults = {
|
const defaults = {
|
||||||
analyze: false,
|
analyze: false,
|
||||||
publicPath: '/_nuxt/',
|
publicPath: '/_nuxt/',
|
||||||
@ -105,7 +109,7 @@ export function options () {
|
|||||||
if (fs.existsSync(bundlePath) && fs.existsSync(manifestPath)) {
|
if (fs.existsSync(bundlePath) && fs.existsSync(manifestPath)) {
|
||||||
const bundle = fs.readFileSync(bundlePath, 'utf8')
|
const bundle = fs.readFileSync(bundlePath, 'utf8')
|
||||||
const manifest = fs.readFileSync(manifestPath, 'utf8')
|
const manifest = fs.readFileSync(manifestPath, 'utf8')
|
||||||
createRenderer.call(this, JSON.parse(bundle), JSON.parse(manifest))
|
createRenderer.call(this, JSON.parse(bundle), fixClientManifest(JSON.parse(manifest)))
|
||||||
addAppTemplate.call(this)
|
addAppTemplate.call(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -431,7 +435,7 @@ function webpackWatchAndUpdate () {
|
|||||||
} else {
|
} else {
|
||||||
const bundle = serverFS.readFileSync(bundlePath, 'utf8')
|
const bundle = serverFS.readFileSync(bundlePath, 'utf8')
|
||||||
const manifest = clientFS.readFileSync(manifestPath, 'utf8')
|
const manifest = clientFS.readFileSync(manifestPath, 'utf8')
|
||||||
createRenderer.call(this, JSON.parse(bundle), JSON.parse(manifest))
|
createRenderer.call(this, JSON.parse(bundle), fixClientManifest(JSON.parse(manifest)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.watchHandler = watchHandler
|
this.watchHandler = watchHandler
|
||||||
@ -464,7 +468,7 @@ function webpackRunServer () {
|
|||||||
readFile(bundlePath, 'utf8')
|
readFile(bundlePath, 'utf8')
|
||||||
.then((bundle) => readFile(manifestPath, 'utf8')
|
.then((bundle) => readFile(manifestPath, 'utf8')
|
||||||
.then(manifest => {
|
.then(manifest => {
|
||||||
createRenderer.call(this, JSON.parse(bundle), JSON.parse(manifest))
|
createRenderer.call(this, JSON.parse(bundle), fixClientManifest(JSON.parse(manifest)))
|
||||||
resolve()
|
resolve()
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
|
@ -128,7 +128,8 @@ export function renderAndGetWindow (url, opts = {}) {
|
|||||||
/* istanbul ignore if */
|
/* istanbul ignore if */
|
||||||
if (!jsdom) {
|
if (!jsdom) {
|
||||||
try {
|
try {
|
||||||
jsdom = require('jsdom')
|
// https://github.com/tmpvar/jsdom/blob/master/lib/old-api.md
|
||||||
|
jsdom = require('jsdom/lib/old-api')
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Fail when calling nuxt.renderAndGetWindow(url)') // eslint-disable-line no-console
|
console.error('Fail when calling nuxt.renderAndGetWindow(url)') // eslint-disable-line no-console
|
||||||
console.error('jsdom module is not installed') // eslint-disable-line no-console
|
console.error('jsdom module is not installed') // eslint-disable-line no-console
|
||||||
@ -136,13 +137,14 @@ export function renderAndGetWindow (url, opts = {}) {
|
|||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let virtualConsole = new jsdom.VirtualConsole().sendTo(console)
|
let virtualConsole = jsdom.createVirtualConsole().sendTo(console)
|
||||||
|
// let virtualConsole = new jsdom.VirtualConsole().sendTo(console)
|
||||||
if (opts.virtualConsole === false) {
|
if (opts.virtualConsole === false) {
|
||||||
virtualConsole = undefined
|
virtualConsole = undefined
|
||||||
}
|
}
|
||||||
url = url || 'http://localhost:3000'
|
url = url || 'http://localhost:3000'
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
jsdom.env({
|
return jsdom.env({
|
||||||
url: url,
|
url: url,
|
||||||
features: {
|
features: {
|
||||||
FetchExternalResources: ['script', 'link'],
|
FetchExternalResources: ['script', 'link'],
|
||||||
|
@ -17,12 +17,11 @@ test.before('Init Nuxt.js', async t => {
|
|||||||
test('Check .nuxt/router.js', t => {
|
test('Check .nuxt/router.js', t => {
|
||||||
return readFile(resolve(__dirname, './fixtures/dynamic-routes/.nuxt/router.js'), 'utf-8')
|
return readFile(resolve(__dirname, './fixtures/dynamic-routes/.nuxt/router.js'), 'utf-8')
|
||||||
.then((routerFile) => {
|
.then((routerFile) => {
|
||||||
routerFile = routerFile.slice(
|
routerFile = routerFile
|
||||||
routerFile.indexOf('routes: ['),
|
.slice(routerFile.indexOf('routes: ['))
|
||||||
-3
|
.replace('routes: [', '[')
|
||||||
)
|
.replace(/ _[0-9A-z]+,/g, ' "",')
|
||||||
.replace('routes: [', '[')
|
.replace('})', '')
|
||||||
.replace(/ _[0-9A-z]+,/g, ' "",')
|
|
||||||
let routes = eval('( ' + routerFile + ')') // eslint-disable-line no-eval
|
let routes = eval('( ' + routerFile + ')') // eslint-disable-line no-eval
|
||||||
// pages/index.vue
|
// pages/index.vue
|
||||||
t.is(routes[0].path, '/')
|
t.is(routes[0].path, '/')
|
||||||
|
Loading…
Reference in New Issue
Block a user