Skip to content

Commit

Permalink
test: improve runAll tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Iiro Jäppinen authored and okonet committed Jun 6, 2019
1 parent cb5fcbd commit e770d8f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 34 deletions.
2 changes: 0 additions & 2 deletions src/resolveGitDir.js
Expand Up @@ -2,14 +2,12 @@

const execGit = require('./execGit')
const path = require('path')
const printErrors = require('./printErrors')

module.exports = async function resolveGitDir(options) {
try {
const gitDir = await execGit(['rev-parse', '--show-toplevel'], options)
return path.normalize(gitDir)
} catch (error) {
printErrors(error)
return null
}
}
3 changes: 3 additions & 0 deletions test/__snapshots__/runAll.2.spec.js.snap
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`runAll should throw when not in a git directory 1`] = `"Current directory is not a git directory!"`;
29 changes: 0 additions & 29 deletions test/__snapshots__/runAll.spec.js.snap
Expand Up @@ -81,35 +81,6 @@ exports[`runAll should skip stashing changes if no lint-staged files are changed
LOG No staged files match any of provided globs."
`;

exports[`runAll should skip updating stash if there are errors during linting 1`] = `
"
LOG Stashing changes... [started]
LOG Stashing changes... [completed]
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 Updating stash... [started]
LOG Updating stash... [skipped]
LOG → Skipping stash update since some tasks exited with errors
LOG Restoring local changes... [started]
LOG Restoring local changes... [completed]
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: {hasStash: true, hasErrors: true}
}
],
context: {hasStash: true, hasErrors: true}
}"
`;

exports[`runAll should skip updating stash if there are errors during linting 1`] = `
"
LOG Stashing changes... [started]
Expand Down
11 changes: 11 additions & 0 deletions test/runAll.2.spec.js
@@ -0,0 +1,11 @@
import { getConfig } from '../src/getConfig'
import runAll from '../src/runAll'

jest.unmock('execa')

describe('runAll', () => {
it('should throw when not in a git directory', async () => {
const config = getConfig({ concurrent: true, cwd: '/' })
await expect(runAll(config)).rejects.toThrowErrorMatchingSnapshot()
})
})
6 changes: 3 additions & 3 deletions test/runAll.spec.js
Expand Up @@ -29,9 +29,9 @@ describe('runAll', () => {
global.console = globalConsoleTemp
})

it('should throw when invalid config is provided', () => {
expect(runAll({})).rejects.toThrowErrorMatchingSnapshot()
expect(runAll()).rejects.toThrowErrorMatchingSnapshot()
it('should throw when invalid config is provided', async () => {
await expect(runAll({})).rejects.toThrowErrorMatchingSnapshot()
await expect(runAll()).rejects.toThrowErrorMatchingSnapshot()
})

it('should not throw when a valid config is provided', () => {
Expand Down

0 comments on commit e770d8f

Please sign in to comment.