Skip to content

Commit

Permalink
fix: stop search if files names are undefined (#6761)
Browse files Browse the repository at this point in the history
  • Loading branch information
emuraton authored and SimenB committed Aug 30, 2018
1 parent c1d9c2e commit d235839
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- `[jest-each]` Prevent done callback being supplied to describe ([#6843](https://github.com/facebook/jest/pull/6843))
- `[jest-config]` Better error message for a case when a preset module was found, but no `jest-preset.js` or `jest-preset.json` at the root ([#6863](https://github.com/facebook/jest/pull/6863))
- `[jest-mock]` Fix inheritance of static properties and methods in mocks ([#6921](https://github.com/facebook/jest/pull/6921))
- `[jest-haste-map]` Catch crawler error when unsuccessfully reading directories ([#6761](https://github.com/facebook/jest/pull/6761))

### Chore & Maintenance

Expand Down
18 changes: 18 additions & 0 deletions packages/jest-haste-map/src/crawlers/__tests__/node.test.js
Original file line number Diff line number Diff line change
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 == '/error') {
setTimeout(() => callback({code: 'ENOTDIR'}, undefined), 0);
}
}),
stat: jest.fn(stat),
Expand Down Expand Up @@ -217,4 +219,20 @@ describe('node crawler', () => {
expect(data.files).toEqual({});
});
});

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

nodeCrawl = require('../node');

const files = Object.create(null);
return nodeCrawl({
data: {files},
extensions: ['js'],
ignore: pearMatcher,
roots: ['/error'],
}).then(data => {
expect(data.files).toEqual({});
});
});
});
5 changes: 4 additions & 1 deletion packages/jest-haste-map/src/crawlers/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ function find(
activeCalls++;
fs.readdir(directory, (err, names) => {
activeCalls--;

if (err) {
callback(result);
return;
}
names.forEach(file => {
file = path.join(directory, file);
if (ignore(file)) {
Expand Down

0 comments on commit d235839

Please sign in to comment.