Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jest-haste-map: only file IO errors should be silently ignored #3816

Merged
merged 3 commits into from
Jun 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/jest-cli/src/TestWorker.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export type CoverageMap = {|
|};

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