From 05ebca2c4c9ca0e43789c0348d6eab8bb40fa151 Mon Sep 17 00:00:00 2001 From: Thomas Rittson <31796059+eliykat@users.noreply.github.com> Date: Thu, 8 Sep 2022 08:05:30 +1000 Subject: [PATCH] [EC-497] Fix memory leaks in tests (#3421) * Add isolatedModules:true * Add manual typechecking in CI for libs/ tests --- .github/workflows/test.yml | 11 ++++++++++- jest.config.js | 9 +++++++++ libs/shared/jest.config.base.js | 7 ++++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 36e4157f05b..bb0b4453dfa 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -42,7 +42,16 @@ jobs: - name: Install Node dependencies run: npm ci + # We use isolatedModules: true which disables typechecking in tests + # Tests in apps/ are typechecked when their app is built, so we just do it here for libs/ + # See https://bitwarden.atlassian.net/browse/EC-497 + - name: Run typechecking + run: | + for p in libs/**/tsconfig.spec.json; do + echo "Typechecking $p" + npx tsc --noEmit --project $p + done + - name: Run tests run: | - export NODE_OPTIONS=--max_old_space_size=6144 npm run test diff --git a/jest.config.js b/jest.config.js index e8f4ce151d4..7a747974f53 100644 --- a/jest.config.js +++ b/jest.config.js @@ -26,4 +26,13 @@ module.exports = { // https://github.com/facebook/jest/issues/9430#issuecomment-1149882002 // Also anecdotally improves performance when run locally maxWorkers: 3, + globals: { + "ts-jest": { + // Further workaround for memory leak, recommended here: + // https://github.com/kulshekhar/ts-jest/issues/1967#issuecomment-697494014 + // Makes tests run faster and reduces size/rate of leak, but loses typechecking on test code + // See https://bitwarden.atlassian.net/browse/EC-497 for more info + isolatedModules: true, + }, + }, }; diff --git a/libs/shared/jest.config.base.js b/libs/shared/jest.config.base.js index 7538064c284..056e54e9a7e 100644 --- a/libs/shared/jest.config.base.js +++ b/libs/shared/jest.config.base.js @@ -10,10 +10,15 @@ module.exports = { // Also anecdotally improves performance when run locally maxWorkers: 3, - // Jest does not use tsconfig.spec.json by default globals: { "ts-jest": { + // Jest does not use tsconfig.spec.json by default tsconfig: "/tsconfig.spec.json", + // Further workaround for memory leak, recommended here: + // https://github.com/kulshekhar/ts-jest/issues/1967#issuecomment-697494014 + // Makes tests run faster and reduces size/rate of leak, but loses typechecking on test code + // See https://bitwarden.atlassian.net/browse/EC-497 for more info + isolatedModules: true, }, }, };