From cdd5dfea815bd043703c991dcca2051458d7ee75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Jim=C3=A9nez=20Es=C3=BAn?= Date: Thu, 22 Feb 2018 23:16:28 +0000 Subject: [PATCH] Force haste map regeneration on deserialization error (#5642) --- packages/jest-haste-map/src/index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/jest-haste-map/src/index.js b/packages/jest-haste-map/src/index.js index 4af29b1c25ef..86c79cc6bd01 100644 --- a/packages/jest-haste-map/src/index.js +++ b/packages/jest-haste-map/src/index.js @@ -289,8 +289,13 @@ class HasteMap extends EventEmitter { * 1. read data from the cache or create an empty structure. */ read(): InternalHasteMap { - // This may throw. `_buildFileMap` will catch it and create a new map. - const hasteMap: InternalHasteMap = serializer.readFileSync(this._cachePath); + let hasteMap: InternalHasteMap; + + try { + hasteMap = serializer.readFileSync(this._cachePath); + } catch (err) { + hasteMap = this._createEmptyMap(); + } for (const key in hasteMap) { Object.setPrototypeOf(hasteMap[key], null);