From 9ad0f4bc6b8bdd94989804226c28c9960d9da7d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bazyli=20Brz=C3=B3ska?= Date: Fri, 16 Aug 2019 07:44:27 +0200 Subject: [PATCH] Workaround a node >=12.5.0 bug that causes the process not to exit after tests have completed and cancerous memory growth (#8787) --- CHANGELOG.md | 1 + packages/jest-haste-map/src/index.ts | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e707b90b69d..470c7ddb9862 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ - `[jest-snapshots]` Fix test retries that contain snapshots ([#8629](https://github.com/facebook/jest/pull/8629)) - `[jest-mock]` Fix incorrect assignments when restoring mocks in instances where they originally didn't exist ([#8631](https://github.com/facebook/jest/pull/8631)) - `[expect]` Fix stack overflow when matching objects with circular references ([#8687](https://github.com/facebook/jest/pull/8687)) +- `[jest-haste-map]` Workaround a node >=12.5.0 bug that causes the process not to exit after tests have completed and cancerous memory growth ([#8787](https://github.com/facebook/jest/pull/8787)) ### Chore & Maintenance diff --git a/packages/jest-haste-map/src/index.ts b/packages/jest-haste-map/src/index.ts index 70965909d79d..4a14bebc2eee 100644 --- a/packages/jest-haste-map/src/index.ts +++ b/packages/jest-haste-map/src/index.ts @@ -642,7 +642,7 @@ class HasteMap extends EventEmitter { .then(workerReply, workerError); } - private async _buildHasteMap(data: { + private _buildHasteMap(data: { removedFiles: FileData; changedFiles?: FileData; hasteMap: InternalHasteMap; @@ -687,16 +687,18 @@ class HasteMap extends EventEmitter { } } - try { - await Promise.all(promises); - this._cleanup(); - hasteMap.map = map; - hasteMap.mocks = mocks; - return hasteMap; - } catch (error) { - this._cleanup(); - throw error; - } + return Promise.all(promises).then( + () => { + this._cleanup(); + hasteMap.map = map; + hasteMap.mocks = mocks; + return hasteMap; + }, + error => { + this._cleanup(); + throw error; + }, + ); } private _cleanup() {