Skip to content

Commit

Permalink
fix: callback early is readdir throw an error
Browse files Browse the repository at this point in the history
  • Loading branch information
emuraton committed Aug 24, 2018
1 parent d56dcf3 commit a1796df
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions packages/jest-haste-map/src/crawlers/__tests__/node.test.js
Expand Up @@ -59,8 +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);
} else if (dir == '/error') {
throw new Error('Error: ENOTDIR: not a directory');
}
}),
stat: jest.fn(stat),
Expand Down Expand Up @@ -220,7 +220,7 @@ describe('node crawler', () => {
});
});

it('completes with undefined names', () => {
it('completes with fs.readdir throwing an error', () => {
process.platform = 'win32';

nodeCrawl = require('../node');
Expand All @@ -230,7 +230,7 @@ describe('node crawler', () => {
data: {files},
extensions: ['js'],
ignore: pearMatcher,
roots: ['/empty'],
roots: ['/error'],
}).then(data => {
expect(data.files).toEqual({});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-haste-map/src/crawlers/node.js
Expand Up @@ -30,7 +30,7 @@ function find(
activeCalls++;
fs.readdir(directory, (err, names) => {
activeCalls--;
if (!names) {
if (err) {
callback(result);
return;
}
Expand Down

0 comments on commit a1796df

Please sign in to comment.