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'
|
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', () => {
|
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()
|
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 = ''
|
|
|
|
|
2018-12-20 11:15:48 +00:00
|
|
|
getCommand.mockImplementationOnce(() => Promise.resolve({}))
|
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 = ''
|
|
|
|
|
2018-12-20 11:15:48 +00:00
|
|
|
getCommand.mockImplementationOnce(() => Promise.resolve({}))
|
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
|
|
|
})
|
|
|
|
})
|