Fix tests

This commit is contained in:
Sébastien Chopin 2017-03-17 18:52:46 +01:00
parent 8cdd10274f
commit 3fcfe4e026
3 changed files with 21 additions and 49 deletions

View File

@ -1,45 +1,19 @@
import test from 'ava' import test from 'ava'
import { resolve } from 'path' import { resolve } from 'path'
test('Fail to generate without routeParams', t => { test('Fail with routes() which throw an error', t => {
const Nuxt = require('../')
const options = {
rootDir: resolve(__dirname, 'fixtures/basic'),
dev: false
// no generate.routeParams
}
const nuxt = new Nuxt(options)
return new Promise((resolve) => {
var oldExit = process.exit
var oldCE = console.error // eslint-disable-line no-console
var _log = ''
console.error = (s) => { _log += s } // eslint-disable-line no-console
process.exit = (code) => {
process.exit = oldExit
console.error = oldCE // eslint-disable-line no-console
t.is(code, 1)
t.true(_log.includes('Could not generate the dynamic route /users/:id'))
resolve()
}
nuxt.generate()
})
})
test('Fail with routeParams which throw an error', t => {
const Nuxt = require('../') const Nuxt = require('../')
const options = { const options = {
rootDir: resolve(__dirname, 'fixtures/basic'), rootDir: resolve(__dirname, 'fixtures/basic'),
dev: false, dev: false,
generate: { generate: {
routeParams: { routes: function () {
'/users/:id': function () {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
reject('Not today!') reject('Not today!')
}) })
} }
} }
} }
}
const nuxt = new Nuxt(options) const nuxt = new Nuxt(options)
return new Promise((resolve) => { return new Promise((resolve) => {
var oldExit = process.exit var oldExit = process.exit
@ -50,7 +24,7 @@ test('Fail with routeParams which throw an error', t => {
process.exit = oldExit process.exit = oldExit
console.error = oldCE // eslint-disable-line no-console console.error = oldCE // eslint-disable-line no-console
t.is(code, 1) t.is(code, 1)
t.true(_log.includes('Could not resolve routeParams[/users/:id]')) t.true(_log.includes('Could not resolve routes'))
resolve() resolve()
} }
nuxt.generate() nuxt.generate()

View File

@ -1,11 +1,9 @@
module.exports = { module.exports = {
generate: { generate: {
routeParams: { routes: [
'/users/:id?': [ '/users/1',
{ id: 1 }, '/users/2',
{ id: 2 }, '/users/3'
{ id: 3 }
] ]
} }
} }
}

View File

@ -37,9 +37,9 @@ test('urlJoin', t => {
t.is(utils.urlJoin('test', '/about'), 'test/about') t.is(utils.urlJoin('test', '/about'), 'test/about')
}) })
test('promisifyRouteParams (array)', t => { test('promisifyRoute (array)', t => {
const array = [1] const array = [1]
const promise = utils.promisifyRouteParams(array) const promise = utils.promisifyRoute(array)
t.is(typeof promise, 'object') t.is(typeof promise, 'object')
return promise return promise
.then((res) => { .then((res) => {
@ -47,12 +47,12 @@ test('promisifyRouteParams (array)', t => {
}) })
}) })
test('promisifyRouteParams (fn => array)', t => { test('promisifyRoute (fn => array)', t => {
const array = [1, 2] const array = [1, 2]
const fn = function () { const fn = function () {
return array return array
} }
const promise = utils.promisifyRouteParams(fn) const promise = utils.promisifyRoute(fn)
t.is(typeof promise, 'object') t.is(typeof promise, 'object')
return promise return promise
.then((res) => { .then((res) => {
@ -60,14 +60,14 @@ test('promisifyRouteParams (fn => array)', t => {
}) })
}) })
test('promisifyRouteParams (fn => promise)', t => { test('promisifyRoute (fn => promise)', t => {
const array = [1, 2, 3] const array = [1, 2, 3]
const fn = function () { const fn = function () {
return new Promise((resolve) => { return new Promise((resolve) => {
resolve(array) resolve(array)
}) })
} }
const promise = utils.promisifyRouteParams(fn) const promise = utils.promisifyRoute(fn)
t.is(typeof promise, 'object') t.is(typeof promise, 'object')
return promise return promise
.then((res) => { .then((res) => {
@ -75,11 +75,11 @@ test('promisifyRouteParams (fn => promise)', t => {
}) })
}) })
test('promisifyRouteParams (fn(cb) with error)', t => { test('promisifyRoute (fn(cb) with error)', t => {
const fn = function (cb) { const fn = function (cb) {
cb('Error here') cb('Error here')
} }
const promise = utils.promisifyRouteParams(fn) const promise = utils.promisifyRoute(fn)
t.is(typeof promise, 'object') t.is(typeof promise, 'object')
return promise return promise
.catch((e) => { .catch((e) => {
@ -87,12 +87,12 @@ test('promisifyRouteParams (fn(cb) with error)', t => {
}) })
}) })
test('promisifyRouteParams (fn(cb) with result)', t => { test('promisifyRoute (fn(cb) with result)', t => {
const array = [1, 2, 3, 4] const array = [1, 2, 3, 4]
const fn = function (cb) { const fn = function (cb) {
cb(null, array) cb(null, array)
} }
const promise = utils.promisifyRouteParams(fn) const promise = utils.promisifyRoute(fn)
t.is(typeof promise, 'object') t.is(typeof promise, 'object')
return promise return promise
.then((res) => { .then((res) => {