Repository: okonet/lint-staged
Pull request #858 (2020-04-30 14:45:28)

fix: chunkFiles chunks normalized files even when maxArgLength is set
The previous PR https://github.com/okonet/lint-staged/pull/857 only fixed the situation when `maxArgLength` was not set (when used throught the Node.js API).

codecov[bot]: # [Codecov](https://codecov.io/gh/okonet/lint-staged/pull/858?src=pr&el=h1) Report
> Merging [#858](https://codecov.io/gh/okonet/lint-staged/pull/858?src=pr&el=desc) into [master](https://codecov.io/gh/okonet/lint-staged/commit/588329671b749c9a2a232b763f94ea959a212e78&el=desc) will **not change** coverage.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/okonet/lint-staged/pull/858/graphs/tree.svg?width=650&height=150&src=pr&token=LSoEgsjk4O)](https://codecov.io/gh/okonet/lint-staged/pull/858?src=pr&el=tree)

```diff
@@            Coverage Diff            @@
##            master      #858   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           17        17           
  Lines          593       593           
  Branches       142       142           
=========================================
  Hits           593       593           
```


| [Impacted Files](https://codecov.io/gh/okonet/lint-staged/pull/858?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [lib/chunkFiles.js](https://codecov.io/gh/okonet/lint-staged/pull/858/diff?src=pr&el=tree#diff-bGliL2NodW5rRmlsZXMuanM=) | `100.00% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/okonet/lint-staged/pull/858?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/okonet/lint-staged/pull/858?src=pr&el=footer). Last update [5883296...7406e42](https://codecov.io/gh/okonet/lint-staged/pull/858?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

iiroj: @okonet I already "upgraded" the integration tests to use `lib/index.js` instead of lib/runAll.js`, but maybe it should actually really spawn the entire cli using execa.

Patch:
diff --git a/lib/chunkFiles.js b/lib/chunkFiles.js
index ce86e73..6a935ed 100644
--- a/lib/chunkFiles.js
+++ b/lib/chunkFiles.js
@@ -48,5 +48,5 @@ module.exports = function chunkFiles({ files, baseDir, maxArgLength = null, rela
   )
   const chunkCount = Math.min(Math.ceil(fileListLength / maxArgLength), normalizedFiles.length)
   debug(`Creating ${chunkCount} chunks for maxArgLength of ${maxArgLength}`)
-  return chunkArray(files, chunkCount)
+  return chunkArray(normalizedFiles, chunkCount)
 }


Test patch:
diff --git a/test/chunkFiles.spec.js b/test/chunkFiles.spec.js
index 453dd04..f9c60da 100644
--- a/test/chunkFiles.spec.js
+++ b/test/chunkFiles.spec.js
@@ -13,13 +13,13 @@ describe('chunkFiles', () => {
   })
 
   it('should not chunk short argument string', () => {
-    const chunkedFiles = chunkFiles({ baseDir, files, maxArgLength: 1000 })
+    const chunkedFiles = chunkFiles({ baseDir, files, maxArgLength: 1000, relative: true })
     expect(chunkedFiles).toEqual([files])
   })
 
   it('should chunk too long argument string', () => {
-    const chunkedFiles = chunkFiles({ baseDir, files, maxArgLength: 20 })
-    expect(chunkedFiles).toEqual(files.map((file) => [file]))
+    const chunkedFiles = chunkFiles({ baseDir, files, maxArgLength: 20, relative: false })
+    expect(chunkedFiles).toEqual(files.map((file) => [normalize(path.resolve(baseDir, file))]))
   })
 
   it('should take into account relative setting', () => {
@@ -30,8 +30,13 @@ describe('chunkFiles', () => {
     ])
   })
 
-  it('should resolve paths when relative: false', () => {
-    const chunkedFiles = chunkFiles({ baseDir, files, relative: false })
+  it('should resolve absolute paths by default', () => {
+    const chunkedFiles = chunkFiles({ baseDir, files })
+    expect(chunkedFiles).toEqual([files.map((file) => normalize(path.resolve(baseDir, file)))])
+  })
+
+  it('should resolve absolute paths by default even when maxArgLength is set', () => {
+    const chunkedFiles = chunkFiles({ baseDir, files, maxArgLength: 262144 })
     expect(chunkedFiles).toEqual([files.map((file) => normalize(path.resolve(baseDir, file)))])
   })
 })