Nuxt/packages/cli/test/unit/cli.test.js
Xin Du (Clark) a616c09b22 feat(test): unit tests for core/config module (#4760)
* feat(test): enable tests in packages

* fix: wait error hook

* test: entry and hookable in core

* fix(test): options snapshot in windows

* refactor(test): simpilify jest.fn

* test: module in core

* test: complete module test

* test: add test for resolver in core

* test: update config snapshot

* test: nuxt in core module
2019-01-19 13:00:51 +01:00

42 lines
1.1 KiB
JavaScript

import { run } from '../../src'
import getCommand from '../../src/commands'
jest.mock('../../src/commands')
describe('cli', () => {
afterEach(() => jest.resetAllMocks())
test('calls expected method', async () => {
const mockedCommand = {
run: jest.fn(() => Promise.resolve({}))
}
getCommand.mockImplementationOnce(() => Promise.resolve(mockedCommand))
await run()
expect(mockedCommand.run).toHaveBeenCalled()
})
test('sets NODE_ENV=development for dev', async () => {
const nodeEnv = process.env.NODE_ENV
process.env.NODE_ENV = ''
getCommand.mockImplementationOnce(() => Promise.resolve({}))
await run(['dev'])
expect(process.env.NODE_ENV).toBe('development')
process.env.NODE_ENV = nodeEnv
})
test('sets NODE_ENV=production for build', async () => {
const nodeEnv = process.env.NODE_ENV
process.env.NODE_ENV = ''
getCommand.mockImplementationOnce(() => Promise.resolve({}))
await run(['', '', 'build'])
expect(process.env.NODE_ENV).toBe('production')
process.env.NODE_ENV = nodeEnv
})
})