From 7aa2dbc4049164a242d52e386e0294c8847d2206 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Tue, 5 Oct 2021 04:50:45 +0000 Subject: [PATCH] fix: patch Jest memory leak by calling GC afterEach Refs: https://github.com/facebook/jest/issues/7311#issuecomment-578889493 --- jest.config.js | 1 + package.json | 2 +- scripts/jest/forceGlobalGc.js | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 scripts/jest/forceGlobalGc.js diff --git a/jest.config.js b/jest.config.js index a94b37b7c9fdb..043a5c2f14aa9 100644 --- a/jest.config.js +++ b/jest.config.js @@ -10,4 +10,5 @@ module.exports = { ], testPathIgnorePatterns: ["/node_modules/", "/clients/client-.*"], coveragePathIgnorePatterns: ["/node_modules/", "/clients/client-.*", "/__fixtures__/"], + setupFilesAfterEnv: ["/scripts/jest/forceGlobalGc.js"], }; diff --git a/package.json b/package.json index d5f1a9bf3da3a..56aeb047d48b1 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "build:all": "yarn build:crypto-dependencies && lerna run build", "build-documentation": "yarn remove-documentation && typedoc", "pretest:all": "yarn build:all", - "test:all": "jest --coverage --passWithNoTests && lerna run test --scope '@aws-sdk/{fetch-http-handler,hash-blob-browser}'", + "test:all": "node --expose-gc ./node_modules/.bin/jest --coverage --passWithNoTests && lerna run test --scope '@aws-sdk/{fetch-http-handler,hash-blob-browser}'", "test:functional": "jest --config tests/functional/jest.config.js --passWithNoTests", "test:integration-legacy": "cucumber-js --fail-fast", "test:integration": "jest --config jest.config.integ.js --passWithNoTests", diff --git a/scripts/jest/forceGlobalGc.js b/scripts/jest/forceGlobalGc.js new file mode 100644 index 0000000000000..3467479df0dc8 --- /dev/null +++ b/scripts/jest/forceGlobalGc.js @@ -0,0 +1,3 @@ +afterEach(() => { + if (global.gc) global.gc(); +});