2018-03-27 22:28:17 +00:00
|
|
|
import { Nuxt, Generator } from '../utils'
|
2017-11-24 17:02:53 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
describe('generator', () => {
|
|
|
|
test('initRoutes with routes (fn => array)', async () => {
|
|
|
|
const array = ['/1', '/2', '/3', '/4']
|
|
|
|
const config = {
|
|
|
|
generate: {
|
|
|
|
routes: array
|
|
|
|
}
|
2017-11-24 17:02:53 +00:00
|
|
|
}
|
2018-03-18 19:31:32 +00:00
|
|
|
const nuxt = new Nuxt(config)
|
2019-03-08 20:43:23 +00:00
|
|
|
await nuxt.ready()
|
2018-03-18 19:31:32 +00:00
|
|
|
const generator = new Generator(nuxt)
|
2020-05-07 19:08:01 +00:00
|
|
|
generator.getAppRoutes = jest.fn(() => [])
|
2018-03-18 19:31:32 +00:00
|
|
|
const routes = await generator.initRoutes()
|
2017-11-24 17:02:53 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
expect(routes.length).toBe(array.length)
|
2018-09-18 14:26:41 +00:00
|
|
|
routes.forEach((route, index) => {
|
2018-03-18 19:31:32 +00:00
|
|
|
expect(route.route).toBe(array[index])
|
|
|
|
})
|
2017-11-24 17:02:53 +00:00
|
|
|
})
|
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('initRoutes with routes (fn())', async () => {
|
|
|
|
const array = ['/1', '/2', '/3', '/4']
|
|
|
|
const config = {
|
|
|
|
generate: {
|
2019-07-10 10:45:49 +00:00
|
|
|
routes () {
|
2018-03-18 19:31:32 +00:00
|
|
|
return array
|
|
|
|
}
|
2017-11-24 17:02:53 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-18 19:31:32 +00:00
|
|
|
const nuxt = new Nuxt(config)
|
2019-03-08 20:43:23 +00:00
|
|
|
await nuxt.ready()
|
2018-03-18 19:31:32 +00:00
|
|
|
const generator = new Generator(nuxt)
|
2020-05-07 19:08:01 +00:00
|
|
|
generator.getAppRoutes = jest.fn(() => [])
|
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
const routes = await generator.initRoutes()
|
2017-11-24 17:02:53 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
expect(routes.length).toBe(array.length)
|
2018-09-18 14:26:41 +00:00
|
|
|
routes.forEach((route, index) => {
|
2018-03-18 19:31:32 +00:00
|
|
|
expect(route.route).toBe(array[index])
|
|
|
|
})
|
2017-11-24 17:02:53 +00:00
|
|
|
})
|
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('initRoutes with routes (fn(args))', async () => {
|
|
|
|
const config = {
|
|
|
|
generate: {
|
2019-07-10 10:45:49 +00:00
|
|
|
routes (array) {
|
2018-03-18 19:31:32 +00:00
|
|
|
return array
|
|
|
|
}
|
2017-11-24 17:02:53 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-18 19:31:32 +00:00
|
|
|
const nuxt = new Nuxt(config)
|
2019-03-08 20:43:23 +00:00
|
|
|
await nuxt.ready()
|
2018-03-18 19:31:32 +00:00
|
|
|
const generator = new Generator(nuxt)
|
2020-05-07 19:08:01 +00:00
|
|
|
generator.getAppRoutes = jest.fn(() => [])
|
2018-03-18 19:31:32 +00:00
|
|
|
const array = ['/1', '/2', '/3', '/4']
|
|
|
|
const routes = await generator.initRoutes(array)
|
2017-11-24 17:02:53 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
expect(routes.length).toBe(array.length)
|
2018-09-18 14:26:41 +00:00
|
|
|
routes.forEach((route, index) => {
|
2018-03-18 19:31:32 +00:00
|
|
|
expect(route.route).toBe(array[index])
|
|
|
|
})
|
2017-11-24 17:02:53 +00:00
|
|
|
})
|
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('initRoutes with routes (fn(cb, args))', async () => {
|
|
|
|
const config = {
|
|
|
|
generate: {
|
2019-07-10 10:45:49 +00:00
|
|
|
routes (cb, arg1, arg2, arg3, arg4) {
|
2018-03-18 19:31:32 +00:00
|
|
|
cb(null, [arg1, arg2, arg3, arg4])
|
|
|
|
}
|
2017-11-24 17:02:53 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-18 19:31:32 +00:00
|
|
|
const nuxt = new Nuxt(config)
|
2019-03-08 20:43:23 +00:00
|
|
|
await nuxt.ready()
|
2018-03-18 19:31:32 +00:00
|
|
|
const generator = new Generator(nuxt)
|
2020-05-07 19:08:01 +00:00
|
|
|
generator.getAppRoutes = jest.fn(() => [])
|
2018-03-18 19:31:32 +00:00
|
|
|
const array = ['/1', '/2', '/3', '/4']
|
|
|
|
const routes = await generator.initRoutes(...array)
|
2017-11-24 17:02:53 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
expect(routes.length).toBe(array.length)
|
2018-09-18 14:26:41 +00:00
|
|
|
routes.forEach((route, index) => {
|
2018-03-18 19:31:32 +00:00
|
|
|
expect(route.route).toBe(array[index])
|
|
|
|
})
|
2017-11-24 17:02:53 +00:00
|
|
|
})
|
|
|
|
})
|