From c87671f815b824e74a229a8ffcc0f797a875aea1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iiro=20Ja=CC=88ppinen?= Date: Wed, 5 Jun 2019 08:57:24 +0300 Subject: [PATCH] refactor: makeCmdTasks receives gitDir as argument --- src/makeCmdTasks.js | 3 +-- src/runAll.js | 2 +- test/makeCmdTasks.spec.js | 10 ++++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/makeCmdTasks.js b/src/makeCmdTasks.js index cbbd60e18..a3054d571 100644 --- a/src/makeCmdTasks.js +++ b/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') @@ -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 => ({ diff --git a/src/runAll.js b/src/runAll.js index ddc6ea93d..fcf6e99cc 100644 --- a/src/runAll.js +++ b/src/runAll.js @@ -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 }), diff --git a/test/makeCmdTasks.spec.js b/test/makeCmdTasks.spec.js index 1cf6860dc..fa7fa9dc7 100644 --- a/test/makeCmdTasks.spec.js +++ b/test/makeCmdTasks.spec.js @@ -2,6 +2,8 @@ import execa from 'execa' import makeCmdTasks from '../src/makeCmdTasks' describe('makeCmdTasks', () => { + const gitDir = process.cwd() + beforeEach(() => { execa.mockClear() }) @@ -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') @@ -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') @@ -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 }) }) })