2018-12-20 11:15:48 +00:00
|
|
|
import { mockGetNuxt, mockGetBuilder, mockGetGenerator, NuxtCommand } from '../utils'
|
2018-10-25 07:43:42 +00:00
|
|
|
|
|
|
|
describe('build', () => {
|
|
|
|
let build
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
2018-10-29 22:16:16 +00:00
|
|
|
build = await import('../../src/commands/build').then(m => m.default)
|
2018-10-25 07:43:42 +00:00
|
|
|
jest.spyOn(process, 'exit').mockImplementation(code => code)
|
|
|
|
})
|
|
|
|
|
2018-10-29 22:16:16 +00:00
|
|
|
afterEach(() => jest.resetAllMocks())
|
2018-10-25 07:43:42 +00:00
|
|
|
|
2018-10-29 22:16:16 +00:00
|
|
|
test('has run function', () => {
|
|
|
|
expect(typeof build.run).toBe('function')
|
2018-10-25 07:43:42 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
test('builds on universal mode', async () => {
|
|
|
|
mockGetNuxt({
|
|
|
|
mode: 'universal',
|
|
|
|
build: {
|
|
|
|
analyze: true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
const builder = mockGetBuilder(Promise.resolve())
|
|
|
|
|
2018-10-29 22:16:16 +00:00
|
|
|
await NuxtCommand.from(build).run()
|
2018-10-25 07:43:42 +00:00
|
|
|
|
|
|
|
expect(builder).toHaveBeenCalled()
|
|
|
|
})
|
|
|
|
|
|
|
|
test('generates on spa mode', async () => {
|
|
|
|
mockGetNuxt({
|
|
|
|
mode: 'spa',
|
|
|
|
build: {
|
|
|
|
analyze: false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
const generate = mockGetGenerator(Promise.resolve())
|
|
|
|
|
2018-10-29 22:16:16 +00:00
|
|
|
await NuxtCommand.from(build).run()
|
2018-10-25 07:43:42 +00:00
|
|
|
|
|
|
|
expect(generate).toHaveBeenCalled()
|
|
|
|
})
|
|
|
|
|
2018-11-17 23:05:51 +00:00
|
|
|
test('build with devtools', async () => {
|
|
|
|
mockGetNuxt({
|
|
|
|
mode: 'universal'
|
|
|
|
})
|
|
|
|
const builder = mockGetBuilder(Promise.resolve())
|
|
|
|
|
2018-12-20 11:15:48 +00:00
|
|
|
const cmd = NuxtCommand.from(build, ['build', '.', '--devtools'])
|
2018-11-17 23:05:51 +00:00
|
|
|
|
2018-12-20 11:15:48 +00:00
|
|
|
const options = await cmd.getNuxtConfig(cmd.argv)
|
2018-11-17 23:05:51 +00:00
|
|
|
|
|
|
|
await cmd.run()
|
|
|
|
|
|
|
|
expect(options.vue.config.devtools).toBe(true)
|
|
|
|
expect(builder).toHaveBeenCalled()
|
|
|
|
})
|
|
|
|
|
2018-11-22 15:48:26 +00:00
|
|
|
test('build with modern mode', async () => {
|
|
|
|
mockGetNuxt({
|
|
|
|
mode: 'universal'
|
|
|
|
})
|
|
|
|
mockGetBuilder(Promise.resolve())
|
|
|
|
|
2018-12-20 11:15:48 +00:00
|
|
|
const cmd = NuxtCommand.from(build, ['build', '.', '--m'])
|
2018-11-22 15:48:26 +00:00
|
|
|
|
2018-12-20 11:15:48 +00:00
|
|
|
const options = await cmd.getNuxtConfig()
|
2018-11-22 15:48:26 +00:00
|
|
|
|
|
|
|
await cmd.run()
|
|
|
|
|
|
|
|
expect(options.modern).toBe(true)
|
|
|
|
})
|
2018-10-25 07:43:42 +00:00
|
|
|
})
|