From a432e4be2a48bff16fd1da9182f8005cd808d3b5 Mon Sep 17 00:00:00 2001 From: Emilien Muraton Date: Thu, 26 Jul 2018 10:00:47 +0100 Subject: [PATCH] stop search if is undefined --- .../src/crawlers/__tests__/node.test.js | 16 ++++++++++++++++ packages/jest-haste-map/src/crawlers/node.js | 5 ++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/jest-haste-map/src/crawlers/__tests__/node.test.js b/packages/jest-haste-map/src/crawlers/__tests__/node.test.js index 64362a1d0515..3c93a83566bf 100644 --- a/packages/jest-haste-map/src/crawlers/__tests__/node.test.js +++ b/packages/jest-haste-map/src/crawlers/__tests__/node.test.js @@ -217,4 +217,20 @@ describe('node crawler', () => { expect(data.files).toEqual({}); }); }); + + it('completes with undefined names', () => { + process.platform = 'win32'; + + nodeCrawl = require('../node'); + + const files = Object.create(null); + return nodeCrawl({ + data: {files}, + extensions: ['js'], + ignore: pearMatcher, + roots: ['/empty'], + }).then(data => { + expect(data.files).toEqual({}); + }); + }); }); diff --git a/packages/jest-haste-map/src/crawlers/node.js b/packages/jest-haste-map/src/crawlers/node.js index 17ce3452e757..004dd46f23a1 100644 --- a/packages/jest-haste-map/src/crawlers/node.js +++ b/packages/jest-haste-map/src/crawlers/node.js @@ -30,7 +30,10 @@ function find( activeCalls++; fs.readdir(directory, (err, names) => { activeCalls--; - + if (!names) { + callback(result); + return; + } names.forEach(file => { file = path.join(directory, file); if (ignore(file)) {