mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-06 21:10:38 +00:00
Fix tests
This commit is contained in:
parent
8cdd10274f
commit
3fcfe4e026
@ -1,42 +1,16 @@
|
|||||||
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!')
|
})
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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()
|
||||||
|
12
test/fixtures/basic/nuxt.config.js
vendored
12
test/fixtures/basic/nuxt.config.js
vendored
@ -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 }
|
]
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user