Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
})
const originalLog = console.log
const originalExit = process.exit
process.exit = jest.fn()
console.log = jest.fn()
// tests
if (version) {
utils.pkg.version = version
}
utils.hasFile = () => hasCoverageDir
process.env.SKIP_CODECOV = isOptedOutOfCoverage
require('../travis-after-success')
expect(console.log.mock.calls).toMatchSnapshot()
const commands = crossSpawnSyncMock.mock.calls.map(
call => `${call[0]} ${call[1].join(' ')}`,
)
expect(commands).toMatchSnapshot()
// afterEach
process.exit = originalExit
console.log = originalLog
Object.keys(originalEnvs).forEach(envKey => {
process.env[envKey] = env[envKey]
})
jest.resetModules()
},
{
// 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()
}
} catch (error) {
if (throws) {
expect(error.message).toMatchSnapshot()
} else {
throw error
}
} finally {
// afterEach
process.exit = originalExit
process.argv = originalArgv
console.log = originalLog
jest.resetModules()
}
const originalExit = process.exit
Object.assign(utils, {
hasPkgProp,
hasFile,
resolveBin: (modName, {executable = modName} = {}) => executable,
})
process.exit = jest.fn()
const teardown = setup()
process.argv = ['node', '../lint', ...args]
try {
// tests
require('../lint')
expect(crossSpawnSyncMock).toHaveBeenCalledTimes(1)
const [firstCall] = crossSpawnSyncMock.mock.calls
const [script, calledArgs] = firstCall
expect([script, ...calledArgs].join(' ')).toMatchSnapshot()
} catch (error) {
throw error
} finally {
teardown()
// afterEach
process.exit = originalExit
process.argv = originalArgv
jest.resetModules()
}
},
{
const originalExit = process.exit
Object.assign(utils, {
hasPkgProp,
hasFile,
resolveBin: (modName, {executable = modName} = {}) => executable,
})
process.exit = jest.fn()
process.argv = ['node', '../pre-commit', ...args]
utils.isOptedIn = optIn => optIn === 'pre-commit'
try {
// tests
require('../pre-commit')
expect(crossSpawnSyncMock).toHaveBeenCalledTimes(2)
const [firstCall, secondCall] = crossSpawnSyncMock.mock.calls
const [scriptOne, calledArgsOne] = firstCall
expect([scriptOne, ...calledArgsOne].join(' ')).toMatchSnapshot()
const [scriptTwo, calledArgsTwo] = secondCall
expect([scriptTwo, ...calledArgsTwo].join(' ')).toMatchSnapshot()
} catch (error) {
throw error
} finally {
// afterEach
process.exit = originalExit
process.argv = originalArgv
jest.resetModules()
}
},
{
({setup = () => () => {}}) => {
// beforeEach
const {sync: crossSpawnSyncMock} = require('cross-spawn')
const originalExit = process.exit
process.exit = jest.fn()
process.env['SCRIPTS_PRE-COMMIT'] = 'false'
const teardown = setup()
try {
// tests
require('../validate')
expect(crossSpawnSyncMock).toHaveBeenCalledTimes(1)
const [firstCall] = crossSpawnSyncMock.mock.calls
const [script, calledArgs] = firstCall
expect([script, ...calledArgs].join(' ')).toMatchSnapshot()
} catch (error) {
throw error
} finally {
teardown()
}
// afterEach
process.exit = originalExit
jest.resetModules()
},
{
({args}) => {
// beforeEach
const {sync: crossSpawnSyncMock} = require('cross-spawn')
const originalExit = process.exit
const originalArgv = process.argv
const utils = require('../../utils')
utils.resolveBin = (modName, {executable = modName} = {}) => executable
process.exit = jest.fn()
// tests
process.argv = ['node', '../format', ...args]
require('../format')
expect(crossSpawnSyncMock).toHaveBeenCalledTimes(1)
const [firstCall] = crossSpawnSyncMock.mock.calls
const [script, calledArgs] = firstCall
expect([script, ...calledArgs].join(' ')).toMatchSnapshot()
// afterEach
process.exit = originalExit
process.argv = originalArgv
jest.resetModules()
},
{