From 2387aa917431cfed6b6729da9f9e96668f783460 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 20 Dec 2021 19:08:50 +0100 Subject: [PATCH] Fix multiple given files w/o ignore Closes GH-57. --- lib/finder.js | 8 +++++--- test/input.js | 44 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/lib/finder.js b/lib/finder.js index 950267a..9bd6cfe 100644 --- a/lib/finder.js +++ b/lib/finder.js @@ -289,19 +289,21 @@ function statAndIgnore(file, options, callback) { expected++ fs.stat(fp, (error, value) => { stats = value - onStartOrCheck(error) + onStatOrCheck(error) }) } options.ignore.check(fp, (error, value) => { ignored = value - onStartOrCheck(error) + + // `ignore.check` is sometimes sync, we need to force async behavior. + setImmediate(onStatOrCheck, error) }) /** * @param {Error|null} error */ - function onStartOrCheck(error) { + function onStatOrCheck(error) { actual++ if (error) { diff --git a/test/input.js b/test/input.js index af1de71..98f2914 100644 --- a/test/input.js +++ b/test/input.js @@ -13,7 +13,7 @@ const cross = process.platform === 'win32' ? '×' : '✖' const fixtures = path.join('test', 'fixtures') test('input', (t) => { - t.plan(20) + t.plan(21) t.test('should fail without input', (t) => { const stream = new PassThrough() @@ -430,6 +430,48 @@ test('input', (t) => { ) }) + t.test('should not attempt to read files with `value` (3)', (t) => { + const stderr = spy() + const cwd = path.join(fixtures, 'empty') + const file1 = toVFile({ + path: path.join(cwd, 'not-existing-1.txt'), + value: 'foo' + }) + const file2 = toVFile({ + path: path.join(cwd, 'not-existing-2.txt'), + value: 'bar' + }) + + t.plan(1) + + engine( + { + processor: noop().use( + /** @type {import('unified').Plugin<[], import('unist').Node>} */ + function () { + return (_, file) => { + file.message('!') + } + } + ), + cwd, + streamError: stderr.stream, + files: [file1, file2] + }, + (error, code) => { + t.deepEqual( + [error, code, stderr()], + [ + null, + 0, + 'not-existing-1.txt\n 1:1 warning !\n\nnot-existing-2.txt\n 1:1 warning !\n\n⚠ 2 warnings\n' + ], + 'should report' + ) + } + ) + }) + t.test('should not attempt to read files with `value` (3)', (t) => { const stderr = spy() const cwd = path.join(fixtures, 'empty')