2018-10-25 07:43:42 +00:00
|
|
|
import { run } from '../../src'
|
2018-12-20 11:15:48 +00:00
|
|
|
import getCommand from '../../src/commands'
|
2019-02-06 19:23:42 +00:00
|
|
|
import * as utils from '../../src/utils/'
|
2018-10-25 07:43:42 +00:00
|
|
|
|
2018-10-25 15:40:55 +00:00
|
|
|
jest.mock('../../src/commands')
|
2018-10-25 07:43:42 +00:00
|
|
|
|
|
|
|
describe('cli', () => {
|
2019-02-06 19:23:42 +00:00
|
|
|
beforeAll(() => {
|
|
|
|
jest.spyOn(utils, 'forceExit').mockImplementation(() => {})
|
|
|
|
})
|
|
|
|
|
2018-10-29 22:16:16 +00:00
|
|
|
afterEach(() => jest.resetAllMocks())
|
2018-10-25 07:43:42 +00:00
|
|
|
|
|
|
|
test('calls expected method', async () => {
|
2018-12-20 11:15:48 +00:00
|
|
|
const mockedCommand = {
|
2019-01-19 12:00:51 +00:00
|
|
|
run: jest.fn(() => Promise.resolve({}))
|
2018-10-29 22:16:16 +00:00
|
|
|
}
|
2018-12-20 11:15:48 +00:00
|
|
|
getCommand.mockImplementationOnce(() => Promise.resolve(mockedCommand))
|
2018-10-25 07:43:42 +00:00
|
|
|
|
|
|
|
await run()
|
2018-12-20 11:15:48 +00:00
|
|
|
expect(mockedCommand.run).toHaveBeenCalled()
|
2019-02-08 10:06:47 +00:00
|
|
|
expect(utils.forceExit).not.toHaveBeenCalled()
|
2018-10-25 07:43:42 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
test('sets NODE_ENV=development for dev', async () => {
|
|
|
|
const nodeEnv = process.env.NODE_ENV
|
|
|
|
process.env.NODE_ENV = ''
|
|
|
|
|
2020-03-02 18:15:00 +00:00
|
|
|
getCommand.mockImplementationOnce(() => Promise.resolve({ run () { } }))
|
2018-10-25 07:43:42 +00:00
|
|
|
|
2018-12-20 11:15:48 +00:00
|
|
|
await run(['dev'])
|
2018-10-25 07:43:42 +00:00
|
|
|
expect(process.env.NODE_ENV).toBe('development')
|
|
|
|
process.env.NODE_ENV = nodeEnv
|
|
|
|
})
|
|
|
|
|
2018-10-25 15:40:55 +00:00
|
|
|
test('sets NODE_ENV=production for build', async () => {
|
2018-10-25 07:43:42 +00:00
|
|
|
const nodeEnv = process.env.NODE_ENV
|
|
|
|
process.env.NODE_ENV = ''
|
|
|
|
|
2020-03-02 18:15:00 +00:00
|
|
|
getCommand.mockImplementationOnce(() => Promise.resolve({ run () { } }))
|
2018-10-25 07:43:42 +00:00
|
|
|
|
2018-12-20 11:15:48 +00:00
|
|
|
await run(['', '', 'build'])
|
2018-10-25 07:43:42 +00:00
|
|
|
expect(process.env.NODE_ENV).toBe('production')
|
|
|
|
|
2018-12-20 11:15:48 +00:00
|
|
|
process.env.NODE_ENV = nodeEnv
|
2018-10-25 07:43:42 +00:00
|
|
|
})
|
|
|
|
})
|