2017-11-24 17:02:53 +00:00
|
|
|
import test from 'ava'
|
2017-12-12 09:42:29 +00:00
|
|
|
import { Nuxt, Generator } from '..'
|
2017-11-24 17:02:53 +00:00
|
|
|
|
|
|
|
test('initRoutes with routes (fn => array)', async t => {
|
|
|
|
const array = ['/1', '/2', '/3', '/4']
|
|
|
|
const config = {
|
|
|
|
generate: {
|
|
|
|
routes: array
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const nuxt = new Nuxt(config)
|
|
|
|
const generator = new Generator(nuxt)
|
|
|
|
const routes = await generator.initRoutes()
|
|
|
|
|
|
|
|
t.is(routes.length, array.length)
|
|
|
|
routes.map((route, index) => {
|
|
|
|
t.is(route.route, array[index])
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
test('initRoutes with routes (fn())', async t => {
|
|
|
|
const array = ['/1', '/2', '/3', '/4']
|
|
|
|
const config = {
|
|
|
|
generate: {
|
|
|
|
routes() {
|
|
|
|
return array
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const nuxt = new Nuxt(config)
|
|
|
|
const generator = new Generator(nuxt)
|
|
|
|
const routes = await generator.initRoutes()
|
|
|
|
|
|
|
|
t.is(routes.length, array.length)
|
|
|
|
routes.map((route, index) => {
|
|
|
|
t.is(route.route, array[index])
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
test('initRoutes with routes (fn(args))', async t => {
|
|
|
|
const config = {
|
|
|
|
generate: {
|
|
|
|
routes(array) {
|
|
|
|
return array
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const nuxt = new Nuxt(config)
|
|
|
|
const generator = new Generator(nuxt)
|
|
|
|
const array = ['/1', '/2', '/3', '/4']
|
|
|
|
const routes = await generator.initRoutes(array)
|
|
|
|
|
|
|
|
t.is(routes.length, array.length)
|
|
|
|
routes.map((route, index) => {
|
|
|
|
t.is(route.route, array[index])
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
test('initRoutes with routes (fn(cb, args))', async t => {
|
|
|
|
const config = {
|
|
|
|
generate: {
|
|
|
|
routes(cb, arg1, arg2, arg3, arg4) {
|
2018-01-13 05:22:11 +00:00
|
|
|
cb(null, [arg1, arg2, arg3, arg4])
|
2017-11-24 17:02:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const nuxt = new Nuxt(config)
|
|
|
|
const generator = new Generator(nuxt)
|
|
|
|
const array = ['/1', '/2', '/3', '/4']
|
|
|
|
const routes = await generator.initRoutes(...array)
|
|
|
|
|
|
|
|
t.is(routes.length, array.length)
|
|
|
|
routes.map((route, index) => {
|
|
|
|
t.is(route.route, array[index])
|
|
|
|
})
|
|
|
|
})
|