2018-12-01 10:13:28 +00:00
|
|
|
import fs from 'fs-extra'
|
2019-02-06 19:23:42 +00:00
|
|
|
import * as utils from '../../src/utils/'
|
2018-10-29 22:16:16 +00:00
|
|
|
import { consola, mockGetNuxtStart, mockGetNuxtConfig, NuxtCommand } from '../utils'
|
2018-10-25 07:43:42 +00:00
|
|
|
|
|
|
|
describe('start', () => {
|
|
|
|
let start
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
2018-10-29 22:16:16 +00:00
|
|
|
start = await import('../../src/commands/start').then(m => m.default)
|
2019-02-06 19:23:42 +00:00
|
|
|
jest.spyOn(utils, 'forceExit').mockImplementation(() => {})
|
2018-10-25 07:43:42 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
if (fs.existsSync.mockRestore) {
|
|
|
|
fs.existsSync.mockRestore()
|
|
|
|
}
|
|
|
|
jest.resetAllMocks()
|
|
|
|
})
|
|
|
|
|
2018-10-29 22:16:16 +00:00
|
|
|
test('has run function', () => {
|
|
|
|
expect(typeof start.run).toBe('function')
|
2018-10-25 07:43:42 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
test('no error if dist dir exists', async () => {
|
|
|
|
mockGetNuxtStart()
|
|
|
|
mockGetNuxtConfig()
|
2018-10-29 22:16:16 +00:00
|
|
|
await NuxtCommand.from(start).run()
|
2018-10-25 07:43:42 +00:00
|
|
|
expect(consola.fatal).not.toHaveBeenCalled()
|
|
|
|
})
|
|
|
|
|
|
|
|
test('no error on ssr and server bundle exists', async () => {
|
|
|
|
mockGetNuxtStart(true)
|
|
|
|
mockGetNuxtConfig()
|
2018-10-29 22:16:16 +00:00
|
|
|
await NuxtCommand.from(start).run()
|
2018-10-25 07:43:42 +00:00
|
|
|
expect(consola.fatal).not.toHaveBeenCalled()
|
|
|
|
})
|
2019-02-08 10:06:47 +00:00
|
|
|
|
|
|
|
test('start doesnt force-exit by default', async () => {
|
|
|
|
mockGetNuxtStart()
|
|
|
|
|
|
|
|
const cmd = NuxtCommand.from(start, ['start', '.'])
|
|
|
|
await cmd.run()
|
|
|
|
|
|
|
|
expect(utils.forceExit).not.toHaveBeenCalled()
|
|
|
|
})
|
|
|
|
|
|
|
|
test('start can set force exit explicitly', async () => {
|
|
|
|
mockGetNuxtStart()
|
|
|
|
|
|
|
|
const cmd = NuxtCommand.from(start, ['start', '.', '--force-exit'])
|
|
|
|
await cmd.run()
|
|
|
|
|
|
|
|
expect(utils.forceExit).toHaveBeenCalledTimes(1)
|
|
|
|
expect(utils.forceExit).toHaveBeenCalledWith('start', false)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('start can disable force exit explicitly', async () => {
|
|
|
|
mockGetNuxtStart()
|
|
|
|
|
|
|
|
const cmd = NuxtCommand.from(start, ['start', '.', '--no-force-exit'])
|
|
|
|
await cmd.run()
|
|
|
|
|
|
|
|
expect(utils.forceExit).not.toHaveBeenCalled()
|
|
|
|
})
|
2018-10-25 07:43:42 +00:00
|
|
|
})
|