Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should skip stashing changes if no lint-staged files are changed', async () => {
expect.assertions(4)
hasPartiallyStagedFiles.mockImplementationOnce(() => Promise.resolve(true))
getStagedFiles.mockImplementationOnce(async () => ['sample.java'])
execa.mockImplementationOnce(() =>
Promise.resolve({
stdout: '',
stderr: 'Linter finished with error',
code: 1,
failed: true,
cmd: 'mock cmd'
})
)
try {
await runAll({ config: { '*.js': ['echo "sample"'] } })
} catch (err) {
console.log(err)
}
expect(console.printHistory()).toMatchSnapshot()
expect(gitStashSave).toHaveBeenCalledTimes(0)
it('should throw error for failed linters', async () => {
expect.assertions(1)
mockFn.mockImplementationOnce(() =>
Promise.resolve({
stdout: 'Mock error',
stderr: '',
code: 0,
failed: true,
cmd: 'mock cmd'
})
)
const [linter] = runScript('mock-fail-linter', ['test.js'])
try {
await linter.task()
} catch (err) {
expect(err.privateMsg).toMatch(dedent`
${
logSymbols.error