2019-03-18 21:21:48 +00:00
|
|
|
const { Nuxt, Builder } = require('nuxt-edge')
|
|
|
|
|
|
|
|
const defaultConfig = require('./fixture/nuxt.config')
|
|
|
|
|
|
|
|
jest.setTimeout(60000)
|
|
|
|
|
2019-04-09 10:29:39 +00:00
|
|
|
async function setupMockNuxt(config) {
|
2019-03-18 21:21:48 +00:00
|
|
|
const nuxt = new Nuxt({
|
|
|
|
...defaultConfig,
|
2019-04-09 10:29:39 +00:00
|
|
|
...config,
|
|
|
|
_ready: false
|
2019-03-18 21:21:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
nuxt.moduleContainer.addTemplate = jest.fn(nuxt.moduleContainer.addTemplate)
|
|
|
|
|
2019-04-09 10:29:39 +00:00
|
|
|
await nuxt.ready()
|
|
|
|
|
2019-03-24 11:59:15 +00:00
|
|
|
const builder = new Builder(nuxt)
|
2019-03-18 21:21:48 +00:00
|
|
|
|
2019-03-24 11:59:15 +00:00
|
|
|
await builder.validatePages()
|
|
|
|
await builder.generateRoutesAndFiles()
|
|
|
|
nuxt.builder = builder
|
2019-03-18 21:21:48 +00:00
|
|
|
|
2019-04-09 10:29:39 +00:00
|
|
|
return nuxt
|
|
|
|
}
|
|
|
|
|
|
|
|
async function setupNuxt(config) {
|
|
|
|
const nuxt = new Nuxt({
|
|
|
|
...defaultConfig,
|
|
|
|
...config,
|
|
|
|
_ready: false
|
|
|
|
})
|
|
|
|
|
|
|
|
jest.spyOn(nuxt.moduleContainer, 'addTemplate')
|
|
|
|
|
2019-03-24 12:39:48 +00:00
|
|
|
await nuxt.ready()
|
2019-03-18 21:21:48 +00:00
|
|
|
|
2019-04-09 10:29:39 +00:00
|
|
|
const builder = new Builder(nuxt)
|
|
|
|
nuxt.builder = builder
|
|
|
|
|
2019-03-18 21:21:48 +00:00
|
|
|
return nuxt
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2019-04-09 10:29:39 +00:00
|
|
|
setupMockNuxt,
|
2019-03-18 21:21:48 +00:00
|
|
|
setupNuxt
|
|
|
|
}
|