Skip to content

Commit

Permalink
test: add test for failing linter command
Browse files Browse the repository at this point in the history
  • Loading branch information
Iiro Jäppinen committed Jun 20, 2019
1 parent df40ba1 commit 48f6145
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions test/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import makeConsoleMock from 'consolemock'
import cosmiconfig from 'cosmiconfig'
import makeConsoleMock from 'consolemock'
import path from 'path'
import lintStaged from '../src/index'

jest.unmock('execa')

jest.mock('pify', () => () => () => [{ filename: 'foo.js' }])

// silence console from Jest output
console.log = jest.fn(() => {})
console.error = jest.fn(() => {})

// eslint-disable-next-line import/first
import lintStaged from '../src/index'

const replaceSerializer = (from, to) => ({
test: val => typeof val === 'string' && from.test(val),
print: val => val.replace(from, to)
Expand Down Expand Up @@ -86,4 +94,15 @@ describe('lintStaged', () => {
expect(logger.printHistory()).toMatchSnapshot()
expect(process.exitCode).toEqual(1)
})

it('should exit with code 1 on linter errors', async () => {
const config = {
linters: {
'*': 'node -e "process.exit(1)"'
}
}
mockCosmiconfigWith({ config })
await lintStaged(logger, undefined)
expect(console.error).toHaveBeenCalledWith(expect.stringContaining('node -e "process.exit(1)"'))
})
})

0 comments on commit 48f6145

Please sign in to comment.