Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('init without an existing package.json will fail', () => {
mockFindUp.mock.syncFail = true
mockFindUp.mock.syncReturn = undefined
const result = parse('init')
expect(result).toBe(undefined)
expect(mockReadLine.keyInYN).toHaveBeenCalledTimes(0)
expect(mockGetLogger.mock.error).toHaveBeenCalledWith(
expect.stringMatching(/Unable/),
)
delete mockFindUp.mock.syncFail
delete mockReadLine.mock.keyInYNReturn
delete mockFindUp.mock.syncReturn
})
() => {
mockReadLine.mock.keyInYNReturn = true
mockFindUp.mock.syncReturn = '/some/path/to/things'
const result = parse('init foo.js')
expect(result).toBe(undefined)
expect(mockGetLogger.mock.info).toHaveBeenCalledWith(
expect.stringMatching(/saved/),
)
delete mockReadLine.mock.keyInYNReturn
delete mockFindUp.mock.syncReturn
},
)
() => {
mockReadLine.mock.keyInYNReturn = false
mockFindUp.mock.syncReturn = '/some/path/to/things'
const result = parse('init --config foo.js')
expect(result).toBe(undefined)
expect(mockReadLine.keyInYN).toHaveBeenCalledTimes(1)
expect(mockReadLine.keyInYN).toHaveBeenCalledWith(
expect.stringMatching(/overwrite.*file/),
)
expect(mockGetLogger.mock.info).toHaveBeenCalledTimes(1)
expect(mockGetLogger.mock.info).toHaveBeenCalledWith(
expect.stringMatching(/Exiting.*different/),
)
delete mockReadLine.mock.keyInYNReturn
delete mockFindUp.mock.syncReturn
},