Skip to content

Commit

Permalink
stop search if is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
emuraton committed Jul 26, 2018
1 parent a10bc90 commit d56dcf3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
18 changes: 18 additions & 0 deletions packages/jest-haste-map/src/crawlers/__tests__/node.test.js
Expand Up @@ -59,6 +59,8 @@ jest.mock('fs', () => {
setTimeout(() => callback(null, ['directory', 'tomato.js']), 0);
} else if (dir === '/fruits/directory') {
setTimeout(() => callback(null, ['strawberry.js']), 0);
} else if (dir == '/empty') {
setTimeout(() => callback(null, null), 0);
}
}),
stat: jest.fn(stat),
Expand Down Expand Up @@ -217,4 +219,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({});
});
});
});
5 changes: 4 additions & 1 deletion packages/jest-haste-map/src/crawlers/node.js
Expand Up @@ -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)) {
Expand Down

0 comments on commit d56dcf3

Please sign in to comment.