Skip to content

Commit

Permalink
test: improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronhunter authored and okonet committed Jul 6, 2019
1 parent 76264eb commit 107402f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/__snapshots__/runAll.spec.js.snap
Expand Up @@ -116,3 +116,31 @@ exports[`runAll should use an injected logger 1`] = `
"
LOG No staged files match any of provided globs."
`;

exports[`runAll should warn if the argument length is longer than what the platform can handle 1`] = `
"
WARN ‼ lint-staged generated an argument string of 999999 characters, and commands might not run correctly on your platform.
It is recommended to use functions as linters and split your command based on the number of staged files. For more info, please visit:
https://github.com/okonet/lint-staged#using-js-functions-to-customize-linter-commands
LOG Stashing changes... [started]
LOG Stashing changes... [skipped]
LOG → No partially staged files found...
LOG Running linters... [started]
LOG Running tasks for *.js [started]
LOG echo \\"sample\\" [started]
LOG echo \\"sample\\" [failed]
LOG →
LOG Running tasks for *.js [failed]
LOG →
LOG Running linters... [failed]
LOG {
name: 'ListrError',
errors: [
{
privateMsg: '\\\\n\\\\n\\\\n× echo \\"sample\\" found some errors. Please fix them and try committing again.\\\\n\\\\nLinter finished with error',
context: {hasErrors: true}
}
],
context: {hasErrors: true}
}"
`;
12 changes: 12 additions & 0 deletions test/runAll.spec.js
Expand Up @@ -110,6 +110,18 @@ describe('runAll', () => {
expect(gitStashPop).toHaveBeenCalledTimes(1)
})

it('should warn if the argument length is longer than what the platform can handle', async () => {
hasPartiallyStagedFiles.mockImplementationOnce(() => Promise.resolve(false))
getStagedFiles.mockImplementationOnce(async () => new Array(100000).fill('sample.js'))

try {
await runAll({ '*.js': () => 'echo "sample"' })
} catch (err) {
console.log(err)
}
expect(console.printHistory()).toMatchSnapshot()
})

it('should skip linters and stash update but perform working copy restore if terminated', async () => {
expect.assertions(4)
hasPartiallyStagedFiles.mockImplementationOnce(() => Promise.resolve(true))
Expand Down

0 comments on commit 107402f

Please sign in to comment.