2018-10-25 07:43:42 +00:00
|
|
|
import fs from 'fs'
|
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)
|
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()
|
|
|
|
jest.spyOn(fs, 'existsSync').mockImplementationOnce(() => true)
|
|
|
|
|
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('fatal error if dist dir doesnt exist', async () => {
|
|
|
|
mockGetNuxtStart()
|
|
|
|
jest.spyOn(fs, 'existsSync').mockImplementationOnce(() => false)
|
|
|
|
|
2018-10-29 22:16:16 +00:00
|
|
|
await NuxtCommand.from(start).run()
|
2018-10-25 07:43:42 +00:00
|
|
|
|
|
|
|
expect(consola.fatal).toHaveBeenCalledWith('No build files found, please run `nuxt build` before launching `nuxt start`')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('no error on ssr and server bundle exists', async () => {
|
|
|
|
mockGetNuxtStart(true)
|
|
|
|
mockGetNuxtConfig()
|
|
|
|
jest.spyOn(fs, 'existsSync').mockImplementation(() => true)
|
|
|
|
|
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()
|
|
|
|
})
|
|
|
|
|
2018-11-08 09:15:56 +00:00
|
|
|
test.skip('fatal error on ssr and server bundle doesnt exist', async () => {
|
2018-10-25 07:43:42 +00:00
|
|
|
mockGetNuxtStart(true)
|
2018-11-08 09:15:56 +00:00
|
|
|
let i = 0
|
|
|
|
jest.spyOn(fs, 'existsSync').mockImplementation(() => {
|
|
|
|
return ++i === 1
|
|
|
|
})
|
2018-10-25 07:43:42 +00:00
|
|
|
|
2018-10-29 22:16:16 +00:00
|
|
|
await NuxtCommand.from(start).run()
|
2018-10-25 07:43:42 +00:00
|
|
|
|
2018-11-08 09:15:56 +00:00
|
|
|
expect(consola.fatal).toHaveBeenCalledWith('No SSR build found.\nPlease start with `nuxt start --spa` or build using `nuxt build --universal`')
|
2018-10-25 07:43:42 +00:00
|
|
|
})
|
|
|
|
})
|