Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
({snapshotLog = false, throws = false, signal = false, args = []}) => {
// beforeEach
const {sync: crossSpawnSyncMock} = require('cross-spawn')
const originalExit = process.exit
const originalArgv = process.argv
const originalLog = console.log
process.exit = jest.fn()
console.log = jest.fn()
try {
// tests
process.argv = ['node', '../', ...args]
crossSpawnSyncMock.mockClear()
if (signal) {
crossSpawnSyncMock.mockReturnValueOnce({result: 1, signal})
}
require('../')
if (snapshotLog) {
expect(console.log.mock.calls).toMatchSnapshot()
} else if (signal) {
expect(process.exit).toHaveBeenCalledTimes(1)
expect(process.exit).toHaveBeenCalledWith(1)
expect(console.log.mock.calls).toMatchSnapshot()
} else {
expect(crossSpawnSyncMock).toHaveBeenCalledTimes(1)
const [firstCall] = crossSpawnSyncMock.mock.calls
const [script, calledArgs] = firstCall
expect([script, ...calledArgs].join(' ')).toMatchSnapshot()
}