Skip to content

Commit 4182e9f

Browse files
authored
test: fix "too many files" config import test on some file systems (#788)
Our "too many files" config import test fails on case-insensitive file systems, such as macOS by default. Our fixture folder had a bunch of files that would get removed on these file systems. For example, one of `0a` and `0A` would get removed. That meant that there were fewer than 10,001 files (as expected), and the test would fail. We could fix this by renaming the files, but I chose to fix this by re-creating the fixture each time we run the test. That avoids creating a folder with 10,001 files inside, and prevents you from having to run `npm run test:buildConfigs`.
1 parent 0e5c718 commit 4182e9f

File tree

10,004 files changed

+49
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

10,004 files changed

+49
-4
lines changed

package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
"@types/throttle-debounce": "^5.0.0",
123123
"@types/varint": "^6.0.1",
124124
"@types/yauzl-promise": "^4.0.0",
125+
"@types/yazl": "^2.4.5",
125126
"bitfield": "^4.1.0",
126127
"cpy": "^10.1.0",
127128
"cpy-cli": "^5.0.0",

tests/config-import.js

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import test from 'node:test'
22
import assert from 'node:assert/strict'
3+
import * as fs from 'node:fs'
4+
import { temporaryFileTask } from 'tempy'
35
import { arrayFrom, size } from 'iterpal'
6+
import { ZipFile } from 'yazl'
47
import { defaultConfigPath } from './helpers/default-config.js'
58
import { readConfig } from '../src/config-import.js'
69

@@ -17,10 +20,16 @@ test('config import - loading', async () => {
1720
'not a zip file'
1821
)
1922

20-
await assert.rejects(
21-
async () => await readConfig('./tests/fixtures/config/tooBigOfAZip.zip'),
22-
/Error: Zip file contains too many entries. Max is 10000/,
23-
'number of files in zip is above MAX_ENTRIES'
23+
await temporaryFileTask(
24+
async (zipPath) => {
25+
await writeZipWithLotsOfEmptyFiles(zipPath, 10_001)
26+
await assert.rejects(
27+
readConfig(zipPath),
28+
/Error: Zip file contains too many entries. Max is 10000/,
29+
'number of files in zip is above MAX_ENTRIES'
30+
)
31+
},
32+
{ extension: 'zip' }
2433
)
2534

2635
await assert.rejects(
@@ -280,3 +289,28 @@ test('config import - load default config', async () => {
280289

281290
assert.equal(config.warnings.length, 0, 'no warnings on config file')
282291
})
292+
293+
/**
294+
* @param {string} zipPath
295+
* @param {number} count
296+
* @returns {Promise<void>}
297+
*/
298+
function writeZipWithLotsOfEmptyFiles(zipPath, count) {
299+
return new Promise((resolve) => {
300+
const zipFile = new ZipFile()
301+
302+
const emptyBuffer = Buffer.alloc(0)
303+
// Runs faster with compression disabled.
304+
const options = { compress: false }
305+
306+
for (let i = 0; i < count; i++) {
307+
zipFile.addBuffer(emptyBuffer, i.toString(), options)
308+
}
309+
310+
zipFile.outputStream
311+
.pipe(fs.createWriteStream(zipPath))
312+
.on('close', resolve)
313+
314+
zipFile.end()
315+
})
316+
}

tests/fixtures/config/tooBigOfAZip/-

Whitespace-only changes.

tests/fixtures/config/tooBigOfAZip/--

Whitespace-only changes.

tests/fixtures/config/tooBigOfAZip/-0

Whitespace-only changes.

tests/fixtures/config/tooBigOfAZip/-1

Whitespace-only changes.

tests/fixtures/config/tooBigOfAZip/-2

Whitespace-only changes.

tests/fixtures/config/tooBigOfAZip/-3

Whitespace-only changes.

tests/fixtures/config/tooBigOfAZip/-4

Whitespace-only changes.

0 commit comments

Comments
 (0)