Skip to content

Commit

Permalink
jest-haste-map: only file IO errors should be silently ignored (#3816)
Browse files Browse the repository at this point in the history
* jest-haste-map: only file IO errors should be silently ignored

* fix tests

* remove extra line
  • Loading branch information
jeanlauliac authored and cpojer committed Jun 14, 2017
1 parent 89c5065 commit 79eed25
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/jest-cli/src/TestWorker.js
Expand Up @@ -44,6 +44,7 @@ const formatError = (error: string | Error): SerializableError => {
}

return {
code: error.code || undefined,
message: error.message,
stack: error.stack,
type: 'Error',
Expand Down
1 change: 1 addition & 0 deletions packages/jest-cli/src/reporters/CoverageWorker.js
Expand Up @@ -30,6 +30,7 @@ function formatCoverageError(error, filename: Path): SerializableError {
`;

return {
code: error.code || undefined,
message,
stack: error.stack,
type: 'ERROR',
Expand Down
4 changes: 3 additions & 1 deletion packages/jest-haste-map/src/__tests__/index-test.js
Expand Up @@ -136,7 +136,9 @@ describe('HasteMap', () => {
return mockFs[path];
}

throw new Error(`Cannot read path '${path}'.`);
const error = new Error(`Cannot read path '${path}'.`);
error.code = 'ENOENT';
throw error;
});
fs.writeFileSync = jest.fn((path, data, options) => {
expect(options).toBe('utf8');
Expand Down
3 changes: 3 additions & 0 deletions packages/jest-haste-map/src/index.js
Expand Up @@ -407,6 +407,9 @@ class HasteMap extends EventEmitter {
fileMetadata[H.DEPENDENCIES] = metadata.dependencies || [];
},
error => {
if (['ENOENT', 'EACCES'].indexOf(error.code) < 0) {
throw error;
}
// If a file cannot be read we remove it from the file list and
// ignore the failure silently.
delete hasteMap.files[filePath];
Expand Down
1 change: 1 addition & 0 deletions packages/jest-haste-map/src/worker.js
Expand Up @@ -33,6 +33,7 @@ const formatError = (error: string | Error): SerializableError => {
}

return {
code: error.code || undefined,
message: error.message,
stack: error.stack,
type: 'Error',
Expand Down
1 change: 1 addition & 0 deletions types/TestResult.js
Expand Up @@ -62,6 +62,7 @@ export type CoverageMap = {|
|};

export type SerializableError = {|
code?: mixed,
message: string,
stack: ?string,
type?: string,
Expand Down

0 comments on commit 79eed25

Please sign in to comment.