Merge branch 'master' into nested-dynamic-routes

This commit is contained in:
Sébastien Chopin 2016-12-12 15:02:32 +01:00
commit b3df306c30
5 changed files with 89 additions and 8 deletions

View File

@ -41,7 +41,11 @@ function listenOnConfigChanges (nuxt, server) {
delete require.cache[nuxtConfigFile]
var options = {}
if (fs.existsSync(nuxtConfigFile)) {
options = require(nuxtConfigFile)
try {
options = require(nuxtConfigFile)
} catch (e) {
return console.error(e) // eslint-disable-line no-console
}
}
options.rootDir = rootDir
nuxt.close()
@ -52,7 +56,7 @@ function listenOnConfigChanges (nuxt, server) {
server.nuxt = nuxt
})
.catch((error) => {
console.error('Error while rebuild the app:', error)
console.error('Error while rebuild the app:', error) // eslint-disable-line no-console
process.exit(1)
})
}, 200)

View File

@ -22,8 +22,8 @@
</template>
<script>
import Post from '~components/post.vue'
import vP from '~components/paragraph.vue'
import Post from '~components/post'
import vP from '~components/paragraph'
const vHr = { render: (h) => h('hr', { class: 'hr' }) }
export default {

View File

@ -24,6 +24,7 @@ module.exports = function () {
publicPath: urlJoin(this.options.router.base, '/_nuxt/')
},
resolve: {
extensions: ['.js', '.vue'],
// Disable for now
alias: {
'~': join(this.srcDir),

View File

@ -37,10 +37,9 @@ exports.promisifyRouteParams = function (fn) {
if (Array.isArray(fn)) {
return Promise.resolve(fn)
}
let promise
// If routeParams[route] is a function expecting a callback
if (fn.length === 1) {
promise = new Promise((resolve, reject) => {
return new Promise((resolve, reject) => {
fn(function (err, routeParams) {
if (err) {
reject(err)
@ -48,9 +47,8 @@ exports.promisifyRouteParams = function (fn) {
resolve(routeParams)
})
})
} else {
promise = fn()
}
let promise = fn()
if (!(promise instanceof Promise)) {
promise = Promise.resolve(promise)
}

View File

@ -1,5 +1,6 @@
import test from 'ava'
const utils = require('../lib/utils')
const ansiHTML = require('ansi-html')
test('encodeHtml', t => {
const html = '<h1>Hello</h1>'
@ -14,3 +15,80 @@ test('getContext', t => {
t.is(ctx.req.a, 1)
t.is(ctx.res.b, 2)
})
test('setAnsiColors', t => {
utils.setAnsiColors(ansiHTML)
})
test('waitFor', function * (t) {
let s = Date.now()
yield utils.waitFor(100)
t.true(Date.now() - s >= 100)
})
test('urlJoin', t => {
t.is(utils.urlJoin('test', '/about'), 'test/about')
})
test('promisifyRouteParams (array)', t => {
const array = [1]
const promise = utils.promisifyRouteParams(array)
t.is(typeof promise, 'object')
return promise
.then((res) => {
t.is(res, array)
})
})
test('promisifyRouteParams (fn => array)', t => {
const array = [1, 2]
const fn = function () {
return array
}
const promise = utils.promisifyRouteParams(fn)
t.is(typeof promise, 'object')
return promise
.then((res) => {
t.is(res, array)
})
})
test('promisifyRouteParams (fn => promise)', t => {
const array = [1, 2, 3]
const fn = function () {
return new Promise((resolve) => {
resolve(array)
})
}
const promise = utils.promisifyRouteParams(fn)
t.is(typeof promise, 'object')
return promise
.then((res) => {
t.is(res, array)
})
})
test('promisifyRouteParams (fn(cb) with error)', t => {
const fn = function (cb) {
cb('Error here')
}
const promise = utils.promisifyRouteParams(fn)
t.is(typeof promise, 'object')
return promise
.catch((e) => {
t.is(e, 'Error here')
})
})
test('promisifyRouteParams (fn(cb) with result)', t => {
const array = [1, 2, 3, 4]
const fn = function (cb) {
cb(null, array)
}
const promise = utils.promisifyRouteParams(fn)
t.is(typeof promise, 'object')
return promise
.then((res) => {
t.is(res, array)
})
})