Skip to content

Commit

Permalink
refactor: makeCmdTasks receives gitDir as argument
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 90e343b commit c87671f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/makeCmdTasks.js
@@ -1,7 +1,6 @@
'use strict'

const resolveTaskFn = require('./resolveTaskFn')
const resolveGitDir = require('./resolveGitDir')

const debug = require('debug')('lint-staged:make-cmd-tasks')

Expand All @@ -16,12 +15,12 @@ const debug = require('debug')('lint-staged:make-cmd-tasks')
*/
module.exports = async function makeCmdTasks(
commands,
gitDir,
pathsToLint,
{ chunkSize = Number.MAX_SAFE_INTEGER, subTaskConcurrency = 1 } = {}
) {
debug('Creating listr tasks for commands %o', commands)

const gitDir = await resolveGitDir()
const lintersArray = Array.isArray(commands) ? commands : [commands]

return lintersArray.map(linter => ({
Expand Down
2 changes: 1 addition & 1 deletion src/runAll.js
Expand Up @@ -43,7 +43,7 @@ module.exports = async function runAll(config) {
title: `Running tasks for ${task.pattern}`,
task: async () =>
new Listr(
await makeCmdTasks(task.commands, task.fileList, {
await makeCmdTasks(task.commands, gitDir, task.fileList, {
chunkSize,
subTaskConcurrency
}),
Expand Down
10 changes: 6 additions & 4 deletions test/makeCmdTasks.spec.js
Expand Up @@ -2,6 +2,8 @@ import execa from 'execa'
import makeCmdTasks from '../src/makeCmdTasks'

describe('makeCmdTasks', () => {
const gitDir = process.cwd()

beforeEach(() => {
execa.mockClear()
})
Expand All @@ -12,7 +14,7 @@ describe('makeCmdTasks', () => {

it('should work with a single command', async () => {
expect.assertions(4)
const res = await makeCmdTasks('test', ['test.js'])
const res = await makeCmdTasks('test', gitDir, ['test.js'])
expect(res.length).toBe(1)
const [linter] = res
expect(linter.title).toBe('test')
Expand All @@ -24,7 +26,7 @@ describe('makeCmdTasks', () => {

it('should work with multiple commands', async () => {
expect.assertions(9)
const res = await makeCmdTasks(['test', 'test2'], ['test.js'])
const res = await makeCmdTasks(['test', 'test2'], gitDir, ['test.js'])
expect(res.length).toBe(2)
const [linter1, linter2] = res
expect(linter1.title).toBe('test')
Expand All @@ -33,12 +35,12 @@ describe('makeCmdTasks', () => {
let taskPromise = linter1.task()
expect(taskPromise).toBeInstanceOf(Promise)
await taskPromise
expect(execa).toHaveBeenCalledTimes(2)
expect(execa).toHaveBeenCalledTimes(1)
expect(execa).lastCalledWith('test', ['test.js'], { reject: false })
taskPromise = linter2.task()
expect(taskPromise).toBeInstanceOf(Promise)
await taskPromise
expect(execa).toHaveBeenCalledTimes(3)
expect(execa).toHaveBeenCalledTimes(2)
expect(execa).lastCalledWith('test2', ['test.js'], { reject: false })
})
})

0 comments on commit c87671f

Please sign in to comment.