2019-02-06 19:23:42 +00:00
|
|
|
import * as utils from '../../src/utils/'
|
2018-12-20 11:15:48 +00:00
|
|
|
import { mockGetNuxt, mockGetGenerator, NuxtCommand } from '../utils'
|
2018-10-25 07:43:42 +00:00
|
|
|
|
|
|
|
describe('generate', () => {
|
|
|
|
let generate
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
2018-10-29 22:16:16 +00:00
|
|
|
generate = await import('../../src/commands/generate').then(m => m.default)
|
2018-10-25 07:43:42 +00:00
|
|
|
jest.spyOn(process, 'exit').mockImplementation(code => code)
|
2019-02-06 19:23:42 +00:00
|
|
|
jest.spyOn(utils, 'forceExit').mockImplementation(() => {})
|
2018-10-25 07:43:42 +00:00
|
|
|
})
|
|
|
|
|
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 generate.run).toBe('function')
|
2018-10-25 07:43:42 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
test('builds by default', async () => {
|
|
|
|
mockGetNuxt()
|
|
|
|
const generator = mockGetGenerator(Promise.resolve())
|
|
|
|
|
2018-10-29 22:16:16 +00:00
|
|
|
await NuxtCommand.from(generate).run()
|
2018-10-25 07:43:42 +00:00
|
|
|
|
|
|
|
expect(generator).toHaveBeenCalled()
|
|
|
|
expect(generator.mock.calls[0][0].build).toBe(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('doesnt build with no-build', async () => {
|
|
|
|
mockGetNuxt()
|
|
|
|
const generator = mockGetGenerator(Promise.resolve())
|
|
|
|
|
2018-12-20 11:15:48 +00:00
|
|
|
await NuxtCommand.run(generate, ['generate', '.', '--no-build'])
|
2018-10-25 07:43:42 +00:00
|
|
|
|
|
|
|
expect(generator).toHaveBeenCalled()
|
|
|
|
expect(generator.mock.calls[0][0].build).toBe(false)
|
|
|
|
})
|
|
|
|
|
2018-11-17 23:05:51 +00:00
|
|
|
test('build with devtools', async () => {
|
|
|
|
mockGetNuxt()
|
|
|
|
const generator = mockGetGenerator(Promise.resolve())
|
|
|
|
|
2018-12-20 11:15:48 +00:00
|
|
|
const cmd = NuxtCommand.from(generate, ['generate', '.', '--devtools'])
|
2018-11-17 23:05:51 +00:00
|
|
|
|
2018-12-20 11:15:48 +00:00
|
|
|
const options = await cmd.getNuxtConfig()
|
2018-11-17 23:05:51 +00:00
|
|
|
|
|
|
|
await cmd.run()
|
|
|
|
|
|
|
|
expect(options.vue.config.devtools).toBe(true)
|
|
|
|
expect(generator).toHaveBeenCalled()
|
|
|
|
expect(generator.mock.calls[0][0].build).toBe(true)
|
|
|
|
})
|
|
|
|
|
2018-11-22 15:48:26 +00:00
|
|
|
test('generate with modern mode', async () => {
|
|
|
|
mockGetNuxt()
|
|
|
|
mockGetGenerator(Promise.resolve())
|
|
|
|
|
2018-12-20 11:15:48 +00:00
|
|
|
const cmd = NuxtCommand.from(generate, ['generate', '.', '--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('client')
|
|
|
|
})
|
2019-02-08 10:06:47 +00:00
|
|
|
|
|
|
|
test('generate with modern mode', async () => {
|
|
|
|
mockGetNuxt()
|
|
|
|
mockGetGenerator(Promise.resolve())
|
|
|
|
|
|
|
|
const cmd = NuxtCommand.from(generate, ['generate', '.', '--m'])
|
|
|
|
|
|
|
|
const options = await cmd.getNuxtConfig()
|
|
|
|
|
|
|
|
await cmd.run()
|
|
|
|
|
|
|
|
expect(options.modern).toBe('client')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('generate force-exits by default', async () => {
|
|
|
|
mockGetNuxt()
|
|
|
|
mockGetGenerator(Promise.resolve())
|
|
|
|
|
|
|
|
const cmd = NuxtCommand.from(generate, ['generate', '.'])
|
|
|
|
await cmd.run()
|
|
|
|
|
|
|
|
expect(utils.forceExit).toHaveBeenCalledTimes(1)
|
|
|
|
expect(utils.forceExit).toHaveBeenCalledWith('generate', 5)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('generate can set force exit explicitly', async () => {
|
|
|
|
mockGetNuxt()
|
|
|
|
mockGetGenerator(Promise.resolve())
|
|
|
|
|
|
|
|
const cmd = NuxtCommand.from(generate, ['generate', '.', '--force-exit'])
|
|
|
|
await cmd.run()
|
|
|
|
|
|
|
|
expect(utils.forceExit).toHaveBeenCalledTimes(1)
|
|
|
|
expect(utils.forceExit).toHaveBeenCalledWith('generate', false)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('generate can disable force exit explicitly', async () => {
|
|
|
|
mockGetNuxt()
|
|
|
|
mockGetGenerator(Promise.resolve())
|
|
|
|
|
|
|
|
const cmd = NuxtCommand.from(generate, ['generate', '.', '--no-force-exit'])
|
|
|
|
await cmd.run()
|
|
|
|
|
|
|
|
expect(utils.forceExit).not.toHaveBeenCalled()
|
|
|
|
})
|
2018-10-25 07:43:42 +00:00
|
|
|
})
|