From 6537620f106bde2b0df637a29e04cd3cda368e0b Mon Sep 17 00:00:00 2001 From: Thomas Rittson Date: Tue, 9 Aug 2022 13:49:47 +1000 Subject: [PATCH 01/16] Fix duplicate jest config --- jest.config.js | 1 + package.json | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/jest.config.js b/jest.config.js index cfec0420880..ada0b21dd5f 100644 --- a/jest.config.js +++ b/jest.config.js @@ -19,4 +19,5 @@ module.exports = { "/libs/electron/jest.config.js", "/libs/node/jest.config.js", ], + testEnvironment: "node", }; diff --git a/package.json b/package.json index 82e67080c1b..7a4f6e34abe 100644 --- a/package.json +++ b/package.json @@ -204,8 +204,5 @@ "engines": { "node": "~16", "npm": "~8" - }, - "jest": { - "testEnvironment": "node" } } From 65c8777968dbe063cd57328aed6cfef75eba40d9 Mon Sep 17 00:00:00 2001 From: Thomas Rittson Date: Tue, 9 Aug 2022 13:50:04 +1000 Subject: [PATCH 02/16] Fix import path --- libs/common/spec/models/domain/encArrayBuffer.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/common/spec/models/domain/encArrayBuffer.spec.ts b/libs/common/spec/models/domain/encArrayBuffer.spec.ts index fb363937072..609b2a16f7a 100644 --- a/libs/common/spec/models/domain/encArrayBuffer.spec.ts +++ b/libs/common/spec/models/domain/encArrayBuffer.spec.ts @@ -1,7 +1,7 @@ import { EncryptionType } from "@bitwarden/common/enums/encryptionType"; import { EncArrayBuffer } from "@bitwarden/common/models/domain/encArrayBuffer"; -import { makeStaticByteArray } from "../utils"; +import { makeStaticByteArray } from "../../utils"; describe("encArrayBuffer", () => { describe("parses the buffer", () => { From 3374d60fd45efce72aeb23f0b25dc5d11bcbb6cb Mon Sep 17 00:00:00 2001 From: Thomas Rittson Date: Tue, 9 Aug 2022 13:50:39 +1000 Subject: [PATCH 03/16] Fix test Firefox data format --- .../importers/testData/firefoxCsv/firefoxAccountsData.csv.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/common/spec/importers/testData/firefoxCsv/firefoxAccountsData.csv.ts b/libs/common/spec/importers/testData/firefoxCsv/firefoxAccountsData.csv.ts index 2f2c1b55e16..81dd3ec5a17 100644 --- a/libs/common/spec/importers/testData/firefoxCsv/firefoxAccountsData.csv.ts +++ b/libs/common/spec/importers/testData/firefoxCsv/firefoxAccountsData.csv.ts @@ -1,4 +1,4 @@ export const data = `"url","username","password","httpRealm","formActionOrigin","guid","timeCreated","timeLastUsed","timePasswordChanged" -"chrome://FirefoxAccounts","bla-bla-foo-bar","{""version"":1,""accountData"":{""kSync"":""xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"",""kXCS"":""xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"",""kExtSync"":""xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"",""kExtKbHash"":""xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"",""scopedKeys"":{""https://identity.mozilla.com/apps/oldsync"":{""kid"":""xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",""k"":""xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"",""kty"":""xxx""},""sync:addon_storage"":{""kid"":""xxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"",""k"":""xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"",""kty"":""xxx""}}}}","Firefox Accounts credentials",,"{d61e37fa-2bc4-469a-bd66-41fd3b0005e0}","1612345678900","1612345678900","1612345678900" +"chrome://FirefoxAccounts","xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","{""version"":1,""accountData"":{""scopedKeys"":{""https://identity.mozilla.com/apps/oldsync"":{""kid"":""xxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxx"",""k"":""xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"",""kty"":""xxx""},""sync:addon_storage"":{""kid"":""xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"",""k"":""xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"",""kty"":""xxx""}},""kSync"":""xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"",""kXCS"":""xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"",""kExtSync"":""xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"",""kExtKbHash"":""xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx""}}","Firefox Accounts credentials",,"{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}","xxxxxxxxxxxxx","xxxxxxxxxxxxx","xxxxxxxxxxxxx" "https://example.com","foo","bar",,"","{d61e37fa-2bc4-469a-bd66-41fd3b0005e0}","1612345678900","1612345678900","1612345678900" `; From 268b28f4d7b86c432d137dc24939698877956cc7 Mon Sep 17 00:00:00 2001 From: Thomas Rittson Date: Tue, 9 Aug 2022 13:51:08 +1000 Subject: [PATCH 04/16] Default to secondary style if buttonType is null --- libs/components/src/button/button.directive.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/components/src/button/button.directive.ts b/libs/components/src/button/button.directive.ts index c4a4d158984..827c49c22db 100644 --- a/libs/components/src/button/button.directive.ts +++ b/libs/components/src/button/button.directive.ts @@ -61,11 +61,11 @@ export class ButtonDirective { "focus:tw-z-10", ] .concat(this.block ? ["tw-w-full", "tw-block"] : ["tw-inline-block"]) - .concat(buttonStyles[this.buttonType] ?? []); + .concat(buttonStyles[this.buttonType ?? "secondary"]); } @Input() - buttonType: ButtonTypes = "secondary"; + buttonType: ButtonTypes = null; @Input() block = false; From 84925958a57ae0bb2b6b320d16a243c43ae9ebe2 Mon Sep 17 00:00:00 2001 From: Thomas Rittson Date: Wed, 10 Aug 2022 10:28:17 +1000 Subject: [PATCH 05/16] Add spec files to web tsconfig --- apps/web/tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web/tsconfig.json b/apps/web/tsconfig.json index fa4895114dd..a27bc65afb9 100644 --- a/apps/web/tsconfig.json +++ b/apps/web/tsconfig.json @@ -16,5 +16,5 @@ "preserveWhitespaces": true }, "files": ["src/polyfills.ts", "src/main.ts", "../../bitwarden_license/bit-web/src/main.ts"], - "include": ["src/connectors/*.ts", "src/**/*.stories.ts"] + "include": ["src/connectors/*.ts", "src/**/*.stories.ts", "src/**/*.spec.ts"] } From 17d79053f1ec0150343487721dfc557e73da8e18 Mon Sep 17 00:00:00 2001 From: Thomas Rittson Date: Wed, 10 Aug 2022 10:28:34 +1000 Subject: [PATCH 06/16] Fix test dependency setup --- .../trial-initiation/trial-initiation.component.spec.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apps/web/src/app/accounts/trial-initiation/trial-initiation.component.spec.ts b/apps/web/src/app/accounts/trial-initiation/trial-initiation.component.spec.ts index aabf32bfea9..9feda5af50e 100644 --- a/apps/web/src/app/accounts/trial-initiation/trial-initiation.component.spec.ts +++ b/apps/web/src/app/accounts/trial-initiation/trial-initiation.component.spec.ts @@ -12,6 +12,7 @@ import { I18nPipe } from "@bitwarden/angular/pipes/i18n.pipe"; import { ApiService } from "@bitwarden/common/abstractions/api.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/abstractions/log.service"; +import { PolicyApiServiceAbstraction } from "@bitwarden/common/abstractions/policy/policy-api.service.abstraction"; import { PolicyService } from "@bitwarden/common/abstractions/policy/policy.service.abstraction"; import { StateService as BaseStateService } from "@bitwarden/common/abstractions/state.service"; import { PlanType } from "@bitwarden/common/enums/planType"; @@ -75,6 +76,10 @@ describe("TrialInitiationComponent", () => { { provide: LogService, useClass: Substitute.for() }, { provide: I18nService, useClass: Substitute.for() }, { provide: TitleCasePipe, useClass: Substitute.for() }, + { + provide: PolicyApiServiceAbstraction, + useClass: Substitute.for(), + }, { provide: VerticalStepperComponent, useClass: VerticalStepperStubComponent, From ddc8c2a06e565bcef1afc292f4ce62a72c8a7cf4 Mon Sep 17 00:00:00 2001 From: Thomas Rittson Date: Wed, 10 Aug 2022 10:44:08 +1000 Subject: [PATCH 07/16] Fix property name in test --- libs/common/spec/services/folder.service.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/common/spec/services/folder.service.spec.ts b/libs/common/spec/services/folder.service.spec.ts index 660d4a953c8..31b1aad7184 100644 --- a/libs/common/spec/services/folder.service.spec.ts +++ b/libs/common/spec/services/folder.service.spec.ts @@ -33,7 +33,7 @@ describe("Folder Service", () => { "1": folderData("1", "test"), }); stateService.activeAccount$.returns(activeAccount); - stateService.activeAccountUnlocked.returns(activeAccountUnlocked); + stateService.activeAccountUnlocked$.returns(activeAccountUnlocked); (window as any).bitwardenContainerService = new ContainerService(cryptoService); folderService = new FolderService(cryptoService, i18nService, cipherService, stateService); From 2c5b8501dc9952f4a24952adcff3ee3a9f87eb01 Mon Sep 17 00:00:00 2001 From: Thomas Rittson Date: Wed, 10 Aug 2022 11:14:54 +1000 Subject: [PATCH 08/16] Create base jest.config file --- apps/browser/jest.config.js | 8 ++++---- apps/browser/tsconfig.json | 3 ++- apps/cli/jest.config.js | 7 ++----- apps/cli/spec/test.setup.ts | 0 apps/web/jest.config.js | 8 ++++---- apps/web/{test.config.ts => test.setup.ts} | 0 apps/web/tsconfig.json | 7 ++++++- jest.config.js | 1 + libs/angular/jest.config.js | 9 ++++----- libs/angular/{spec => }/test.setup.ts | 0 libs/angular/tsconfig.json | 3 ++- libs/common/jest.config.js | 6 +----- libs/common/{spec => }/test.setup.ts | 2 +- libs/common/tsconfig.json | 3 ++- libs/components/jest.config.js | 9 ++++----- libs/components/{spec => }/test.setup.ts | 0 libs/components/tsconfig.json | 3 ++- libs/electron/jest.config.js | 8 +++----- libs/electron/spec/test.setup.ts | 0 libs/node/jest.config.js | 8 +++----- libs/node/spec/test.setup.ts | 0 libs/shared/jest.config.base.js | 6 ++++++ 22 files changed, 47 insertions(+), 44 deletions(-) delete mode 100644 apps/cli/spec/test.setup.ts rename apps/web/{test.config.ts => test.setup.ts} (100%) rename libs/angular/{spec => }/test.setup.ts (100%) rename libs/common/{spec => }/test.setup.ts (89%) rename libs/components/{spec => }/test.setup.ts (100%) delete mode 100644 libs/electron/spec/test.setup.ts delete mode 100644 libs/node/spec/test.setup.ts create mode 100644 libs/shared/jest.config.base.js diff --git a/apps/browser/jest.config.js b/apps/browser/jest.config.js index dca19ba3bc7..4f954afa9e2 100644 --- a/apps/browser/jest.config.js +++ b/apps/browser/jest.config.js @@ -2,12 +2,12 @@ const { pathsToModuleNameMapper } = require("ts-jest"); const { compilerOptions } = require("./tsconfig"); +const sharedConfig = require("../../libs/shared/jest.config.base"); + module.exports = { - collectCoverage: true, - coverageReporters: ["html", "lcov"], - coverageDirectory: "coverage", - setupFilesAfterEnv: ["/test.setup.ts"], + ...sharedConfig, preset: "jest-preset-angular", + setupFilesAfterEnv: ["/test.setup.ts"], moduleNameMapper: pathsToModuleNameMapper(compilerOptions?.paths || {}, { prefix: "/", }), diff --git a/apps/browser/tsconfig.json b/apps/browser/tsconfig.json index 5c35b45fde8..1969e344f57 100644 --- a/apps/browser/tsconfig.json +++ b/apps/browser/tsconfig.json @@ -17,5 +17,6 @@ "angularCompilerOptions": { "preserveWhitespaces": true }, - "include": ["src"] + "include": ["src"], + "files": ["./test.setup.ts"] } diff --git a/apps/cli/jest.config.js b/apps/cli/jest.config.js index 45ee9695ba9..9665a02b058 100644 --- a/apps/cli/jest.config.js +++ b/apps/cli/jest.config.js @@ -2,13 +2,10 @@ const { pathsToModuleNameMapper } = require("ts-jest"); const { compilerOptions } = require("./tsconfig"); +const sharedConfig = require("../../libs/shared/jest.config.base"); + module.exports = { preset: "ts-jest", - testMatch: ["**/+(*.)+(spec).+(ts)"], - setupFilesAfterEnv: ["/spec/test.setup.ts"], - collectCoverage: true, - coverageReporters: ["html", "lcov"], - coverageDirectory: "coverage", moduleNameMapper: pathsToModuleNameMapper(compilerOptions?.paths || {}, { prefix: "/", }), diff --git a/apps/cli/spec/test.setup.ts b/apps/cli/spec/test.setup.ts deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/apps/web/jest.config.js b/apps/web/jest.config.js index 9ed34c3e5a1..707e8960e3e 100644 --- a/apps/web/jest.config.js +++ b/apps/web/jest.config.js @@ -2,12 +2,12 @@ const { pathsToModuleNameMapper } = require("ts-jest"); const { compilerOptions } = require("./tsconfig"); +const sharedConfig = require("../../libs/shared/jest.config.base"); + module.exports = { - collectCoverage: true, - coverageReporters: ["html", "lcov"], - coverageDirectory: "coverage", + ...sharedConfig, preset: "jest-preset-angular", - setupFilesAfterEnv: ["/test.config.ts"], + setupFilesAfterEnv: ["/test.setup.ts"], moduleNameMapper: pathsToModuleNameMapper(compilerOptions?.paths || {}, { prefix: "/", }), diff --git a/apps/web/test.config.ts b/apps/web/test.setup.ts similarity index 100% rename from apps/web/test.config.ts rename to apps/web/test.setup.ts diff --git a/apps/web/tsconfig.json b/apps/web/tsconfig.json index a27bc65afb9..1e9f114f2c0 100644 --- a/apps/web/tsconfig.json +++ b/apps/web/tsconfig.json @@ -15,6 +15,11 @@ "angularCompilerOptions": { "preserveWhitespaces": true }, - "files": ["src/polyfills.ts", "src/main.ts", "../../bitwarden_license/bit-web/src/main.ts"], + "files": [ + "src/polyfills.ts", + "src/main.ts", + "../../bitwarden_license/bit-web/src/main.ts", + "./test.setup.ts" + ], "include": ["src/connectors/*.ts", "src/**/*.stories.ts", "src/**/*.spec.ts"] } diff --git a/jest.config.js b/jest.config.js index ada0b21dd5f..ae7e8800b4e 100644 --- a/jest.config.js +++ b/jest.config.js @@ -12,6 +12,7 @@ module.exports = { projects: [ "/apps/browser/jest.config.js", "/apps/cli/jest.config.js", + "/apps/web/jest.config.js", "/libs/angular/jest.config.js", "/libs/common/jest.config.js", diff --git a/libs/angular/jest.config.js b/libs/angular/jest.config.js index 067610c0812..3be0f66db55 100644 --- a/libs/angular/jest.config.js +++ b/libs/angular/jest.config.js @@ -2,14 +2,13 @@ const { pathsToModuleNameMapper } = require("ts-jest"); const { compilerOptions } = require("../shared/tsconfig.libs"); +const sharedConfig = require("../../libs/shared/jest.config.base"); + module.exports = { + ...sharedConfig, displayName: "libs/angular tests", preset: "jest-preset-angular", - testMatch: ["**/+(*.)+(spec).+(ts)"], - setupFilesAfterEnv: ["/spec/test.setup.ts"], - collectCoverage: true, - coverageReporters: ["html", "lcov"], - coverageDirectory: "coverage", + setupFilesAfterEnv: ["/test.setup.ts"], moduleNameMapper: pathsToModuleNameMapper(compilerOptions?.paths || {}, { prefix: "/", }), diff --git a/libs/angular/spec/test.setup.ts b/libs/angular/test.setup.ts similarity index 100% rename from libs/angular/spec/test.setup.ts rename to libs/angular/test.setup.ts diff --git a/libs/angular/tsconfig.json b/libs/angular/tsconfig.json index 6004a56fb55..d4625efa3de 100644 --- a/libs/angular/tsconfig.json +++ b/libs/angular/tsconfig.json @@ -1,5 +1,6 @@ { "extends": "../shared/tsconfig.libs", "include": ["src", "spec"], - "exclude": ["node_modules", "dist"] + "exclude": ["node_modules", "dist"], + "files": ["./test.setup.ts"] } diff --git a/libs/common/jest.config.js b/libs/common/jest.config.js index ac811b2edfc..efc229af244 100644 --- a/libs/common/jest.config.js +++ b/libs/common/jest.config.js @@ -6,11 +6,7 @@ module.exports = { displayName: "libs/common tests", preset: "ts-jest", testEnvironment: "jsdom", - testMatch: ["**/+(*.)+(spec).+(ts)"], - setupFilesAfterEnv: ["/spec/test.setup.ts"], - collectCoverage: true, - coverageReporters: ["html", "lcov"], - coverageDirectory: "coverage", + setupFilesAfterEnv: ["/test.setup.ts"], moduleNameMapper: pathsToModuleNameMapper(compilerOptions?.paths || {}, { prefix: "/", }), diff --git a/libs/common/spec/test.setup.ts b/libs/common/test.setup.ts similarity index 89% rename from libs/common/spec/test.setup.ts rename to libs/common/test.setup.ts index b21b45290df..17254ea34c6 100644 --- a/libs/common/spec/test.setup.ts +++ b/libs/common/test.setup.ts @@ -1,6 +1,6 @@ import { webcrypto } from "crypto"; -import { toEqualBuffer } from "./matchers/toEqualBuffer"; +import { toEqualBuffer } from "./spec/matchers/toEqualBuffer"; Object.defineProperty(window, "crypto", { value: webcrypto, diff --git a/libs/common/tsconfig.json b/libs/common/tsconfig.json index 6004a56fb55..d4625efa3de 100644 --- a/libs/common/tsconfig.json +++ b/libs/common/tsconfig.json @@ -1,5 +1,6 @@ { "extends": "../shared/tsconfig.libs", "include": ["src", "spec"], - "exclude": ["node_modules", "dist"] + "exclude": ["node_modules", "dist"], + "files": ["./test.setup.ts"] } diff --git a/libs/components/jest.config.js b/libs/components/jest.config.js index 194f92fafa2..e90c663ce90 100644 --- a/libs/components/jest.config.js +++ b/libs/components/jest.config.js @@ -2,14 +2,13 @@ const { pathsToModuleNameMapper } = require("ts-jest"); const { compilerOptions } = require("./tsconfig"); +const sharedConfig = require("../../libs/shared/jest.config.base"); + module.exports = { + ...sharedConfig, displayName: "libs/components tests", preset: "jest-preset-angular", - testMatch: ["**/+(*.)+(spec).+(ts)"], - setupFilesAfterEnv: ["/spec/test.setup.ts"], - collectCoverage: true, - coverageReporters: ["html", "lcov"], - coverageDirectory: "coverage", + setupFilesAfterEnv: ["/test.setup.ts"], moduleNameMapper: pathsToModuleNameMapper(compilerOptions?.paths || {}, { prefix: "/", }), diff --git a/libs/components/spec/test.setup.ts b/libs/components/test.setup.ts similarity index 100% rename from libs/components/spec/test.setup.ts rename to libs/components/test.setup.ts diff --git a/libs/components/tsconfig.json b/libs/components/tsconfig.json index 69cc9a3edeb..88d289ec143 100644 --- a/libs/components/tsconfig.json +++ b/libs/components/tsconfig.json @@ -28,5 +28,6 @@ "strictInjectionParameters": true, "strictInputAccessModifiers": true, "strictTemplates": true - } + }, + "files": ["./test.setup.ts"] } diff --git a/libs/electron/jest.config.js b/libs/electron/jest.config.js index 06f2234ec6f..104e723a844 100644 --- a/libs/electron/jest.config.js +++ b/libs/electron/jest.config.js @@ -2,14 +2,12 @@ const { pathsToModuleNameMapper } = require("ts-jest"); const { compilerOptions } = require("../shared/tsconfig.libs"); +const sharedConfig = require("../../libs/shared/jest.config.base"); + module.exports = { + ...sharedConfig, preset: "ts-jest", testEnvironment: "jsdom", - testMatch: ["**/+(*.)+(spec).+(ts)"], - setupFilesAfterEnv: ["/spec/test.setup.ts"], - collectCoverage: true, - coverageReporters: ["html", "lcov"], - coverageDirectory: "coverage", moduleNameMapper: pathsToModuleNameMapper(compilerOptions?.paths || {}, { prefix: "/", }), diff --git a/libs/electron/spec/test.setup.ts b/libs/electron/spec/test.setup.ts deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/libs/node/jest.config.js b/libs/node/jest.config.js index 056444b8307..eff19c23916 100644 --- a/libs/node/jest.config.js +++ b/libs/node/jest.config.js @@ -2,13 +2,11 @@ const { pathsToModuleNameMapper } = require("ts-jest"); const { compilerOptions } = require("../shared/tsconfig.libs"); +const sharedConfig = require("../shared/jest.config.base"); + module.exports = { + ...sharedConfig, preset: "ts-jest", - testMatch: ["**/+(*.)+(spec).+(ts)"], - setupFilesAfterEnv: ["/spec/test.setup.ts"], - collectCoverage: true, - coverageReporters: ["html", "lcov"], - coverageDirectory: "coverage", moduleNameMapper: pathsToModuleNameMapper(compilerOptions?.paths || {}, { prefix: "/", }), diff --git a/libs/node/spec/test.setup.ts b/libs/node/spec/test.setup.ts deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/libs/shared/jest.config.base.js b/libs/shared/jest.config.base.js new file mode 100644 index 00000000000..d5d8f24227d --- /dev/null +++ b/libs/shared/jest.config.base.js @@ -0,0 +1,6 @@ +module.exports = { + testMatch: ["**/+(*.)+(spec).+(ts)"], + collectCoverage: true, + coverageReporters: ["html", "lcov"], + coverageDirectory: "coverage", +}; From 341d10bc15a295e8351fb002674d74abc44cdf73 Mon Sep 17 00:00:00 2001 From: Thomas Rittson Date: Wed, 10 Aug 2022 11:16:33 +1000 Subject: [PATCH 09/16] Add maxWorkers to jest config --- libs/shared/jest.config.base.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libs/shared/jest.config.base.js b/libs/shared/jest.config.base.js index d5d8f24227d..d52a158b1ec 100644 --- a/libs/shared/jest.config.base.js +++ b/libs/shared/jest.config.base.js @@ -3,4 +3,9 @@ module.exports = { collectCoverage: true, coverageReporters: ["html", "lcov"], coverageDirectory: "coverage", + + // Workaround for a memory leak that crashes tests in CI: + // https://github.com/facebook/jest/issues/9430#issuecomment-1149882002 + // Also anecdotally improves performance when run locally + maxWorkers: 3, }; From a5ab6d001d1ccc26e99e31374f9c8352405131d3 Mon Sep 17 00:00:00 2001 From: Thomas Rittson Date: Wed, 10 Aug 2022 11:22:17 +1000 Subject: [PATCH 10/16] Undo change to testEnvironment --- jest.config.js | 1 - 1 file changed, 1 deletion(-) diff --git a/jest.config.js b/jest.config.js index ae7e8800b4e..b82f6e14242 100644 --- a/jest.config.js +++ b/jest.config.js @@ -20,5 +20,4 @@ module.exports = { "/libs/electron/jest.config.js", "/libs/node/jest.config.js", ], - testEnvironment: "node", }; From a130cb639a9cb5fedcb3fa705ec4ad7ec4710de5 Mon Sep 17 00:00:00 2001 From: Thomas Rittson Date: Wed, 10 Aug 2022 13:48:01 +1000 Subject: [PATCH 11/16] Add eslint env setting to jest.config.base --- libs/shared/jest.config.base.js | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/shared/jest.config.base.js b/libs/shared/jest.config.base.js index d52a158b1ec..6d45dd71baa 100644 --- a/libs/shared/jest.config.base.js +++ b/libs/shared/jest.config.base.js @@ -1,3 +1,4 @@ +/* eslint-env node */ module.exports = { testMatch: ["**/+(*.)+(spec).+(ts)"], collectCoverage: true, From a449257ec425516b9e7e51cbc99519790fac9f3f Mon Sep 17 00:00:00 2001 From: Thomas Rittson Date: Wed, 10 Aug 2022 13:55:10 +1000 Subject: [PATCH 12/16] Add maxWorkers to root jest config --- jest.config.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/jest.config.js b/jest.config.js index b82f6e14242..3ca7b5d6e9b 100644 --- a/jest.config.js +++ b/jest.config.js @@ -20,4 +20,9 @@ module.exports = { "/libs/electron/jest.config.js", "/libs/node/jest.config.js", ], + + // Workaround for a memory leak that crashes tests in CI: + // https://github.com/facebook/jest/issues/9430#issuecomment-1149882002 + // Also anecdotally improves performance when run locally + maxWorkers: 3, }; From f6024ef2775a1f8362423495df57ed247f6b568e Mon Sep 17 00:00:00 2001 From: Thomas Rittson Date: Thu, 11 Aug 2022 06:14:11 +1000 Subject: [PATCH 13/16] Add shared config to libs/common --- libs/common/jest.config.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/common/jest.config.js b/libs/common/jest.config.js index efc229af244..29309a78306 100644 --- a/libs/common/jest.config.js +++ b/libs/common/jest.config.js @@ -2,7 +2,10 @@ const { pathsToModuleNameMapper } = require("ts-jest"); const { compilerOptions } = require("../shared/tsconfig.libs"); +const sharedConfig = require("../shared/jest.config.base"); + module.exports = { + ...sharedConfig, displayName: "libs/common tests", preset: "ts-jest", testEnvironment: "jsdom", From 0e52b7dbf167dca68a0617f087c35914e6b2731c Mon Sep 17 00:00:00 2001 From: Thomas Rittson Date: Thu, 11 Aug 2022 06:16:11 +1000 Subject: [PATCH 14/16] Add back test.setup to cli --- apps/cli/jest.config.js | 1 + apps/cli/test.setup.ts | 0 apps/cli/tsconfig.json | 3 ++- 3 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 apps/cli/test.setup.ts diff --git a/apps/cli/jest.config.js b/apps/cli/jest.config.js index 9665a02b058..4f0dab845ec 100644 --- a/apps/cli/jest.config.js +++ b/apps/cli/jest.config.js @@ -6,6 +6,7 @@ const sharedConfig = require("../../libs/shared/jest.config.base"); module.exports = { preset: "ts-jest", + setupFilesAfterEnv: ["/test.setup.ts"], moduleNameMapper: pathsToModuleNameMapper(compilerOptions?.paths || {}, { prefix: "/", }), diff --git a/apps/cli/test.setup.ts b/apps/cli/test.setup.ts new file mode 100644 index 00000000000..e69de29bb2d diff --git a/apps/cli/tsconfig.json b/apps/cli/tsconfig.json index da47ac52d8b..b2f34ead5bb 100644 --- a/apps/cli/tsconfig.json +++ b/apps/cli/tsconfig.json @@ -16,5 +16,6 @@ "@bitwarden/node/*": ["../../libs/node/src/*"] } }, - "include": ["src"] + "include": ["src"], + "files": ["./test.setup.ts"] } From c38d10f8f21d41a4f6153d9f1704be45434cd06d Mon Sep 17 00:00:00 2001 From: Thomas Rittson Date: Thu, 11 Aug 2022 06:19:12 +1000 Subject: [PATCH 15/16] Add back test setup to libs/node --- libs/node/jest.config.js | 1 + libs/node/test.setup.ts | 0 libs/node/tsconfig.json | 3 ++- 3 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 libs/node/test.setup.ts diff --git a/libs/node/jest.config.js b/libs/node/jest.config.js index eff19c23916..833d03cfa5d 100644 --- a/libs/node/jest.config.js +++ b/libs/node/jest.config.js @@ -7,6 +7,7 @@ const sharedConfig = require("../shared/jest.config.base"); module.exports = { ...sharedConfig, preset: "ts-jest", + setupFilesAfterEnv: ["/test.setup.ts"], moduleNameMapper: pathsToModuleNameMapper(compilerOptions?.paths || {}, { prefix: "/", }), diff --git a/libs/node/test.setup.ts b/libs/node/test.setup.ts new file mode 100644 index 00000000000..e69de29bb2d diff --git a/libs/node/tsconfig.json b/libs/node/tsconfig.json index 6004a56fb55..d4625efa3de 100644 --- a/libs/node/tsconfig.json +++ b/libs/node/tsconfig.json @@ -1,5 +1,6 @@ { "extends": "../shared/tsconfig.libs", "include": ["src", "spec"], - "exclude": ["node_modules", "dist"] + "exclude": ["node_modules", "dist"], + "files": ["./test.setup.ts"] } From 1167d5b431784cce191821d4e25493b2c1f4a90a Mon Sep 17 00:00:00 2001 From: Thomas Rittson Date: Thu, 11 Aug 2022 10:21:56 +1000 Subject: [PATCH 16/16] Enable tsconfig.spec.json --- apps/browser/tsconfig.json | 3 +-- apps/browser/tsconfig.spec.json | 3 ++- apps/cli/tsconfig.json | 3 +-- apps/cli/tsconfig.spec.json | 3 ++- apps/web/tsconfig.json | 7 +------ apps/web/tsconfig.spec.json | 3 ++- libs/angular/tsconfig.json | 3 +-- libs/angular/tsconfig.spec.json | 3 ++- libs/common/tsconfig.json | 3 +-- libs/common/tsconfig.spec.json | 3 ++- libs/components/tsconfig.json | 3 +-- libs/components/tsconfig.spec.json | 3 ++- libs/node/tsconfig.json | 3 +-- libs/node/tsconfig.spec.json | 3 ++- libs/shared/jest.config.base.js | 7 +++++++ 15 files changed, 28 insertions(+), 25 deletions(-) diff --git a/apps/browser/tsconfig.json b/apps/browser/tsconfig.json index 1969e344f57..5c35b45fde8 100644 --- a/apps/browser/tsconfig.json +++ b/apps/browser/tsconfig.json @@ -17,6 +17,5 @@ "angularCompilerOptions": { "preserveWhitespaces": true }, - "include": ["src"], - "files": ["./test.setup.ts"] + "include": ["src"] } diff --git a/apps/browser/tsconfig.spec.json b/apps/browser/tsconfig.spec.json index fc8520e7376..de184bd7608 100644 --- a/apps/browser/tsconfig.spec.json +++ b/apps/browser/tsconfig.spec.json @@ -1,3 +1,4 @@ { - "extends": "./tsconfig.json" + "extends": "./tsconfig.json", + "files": ["./test.setup.ts"] } diff --git a/apps/cli/tsconfig.json b/apps/cli/tsconfig.json index b2f34ead5bb..da47ac52d8b 100644 --- a/apps/cli/tsconfig.json +++ b/apps/cli/tsconfig.json @@ -16,6 +16,5 @@ "@bitwarden/node/*": ["../../libs/node/src/*"] } }, - "include": ["src"], - "files": ["./test.setup.ts"] + "include": ["src"] } diff --git a/apps/cli/tsconfig.spec.json b/apps/cli/tsconfig.spec.json index fc8520e7376..de184bd7608 100644 --- a/apps/cli/tsconfig.spec.json +++ b/apps/cli/tsconfig.spec.json @@ -1,3 +1,4 @@ { - "extends": "./tsconfig.json" + "extends": "./tsconfig.json", + "files": ["./test.setup.ts"] } diff --git a/apps/web/tsconfig.json b/apps/web/tsconfig.json index 1e9f114f2c0..a27bc65afb9 100644 --- a/apps/web/tsconfig.json +++ b/apps/web/tsconfig.json @@ -15,11 +15,6 @@ "angularCompilerOptions": { "preserveWhitespaces": true }, - "files": [ - "src/polyfills.ts", - "src/main.ts", - "../../bitwarden_license/bit-web/src/main.ts", - "./test.setup.ts" - ], + "files": ["src/polyfills.ts", "src/main.ts", "../../bitwarden_license/bit-web/src/main.ts"], "include": ["src/connectors/*.ts", "src/**/*.stories.ts", "src/**/*.spec.ts"] } diff --git a/apps/web/tsconfig.spec.json b/apps/web/tsconfig.spec.json index fc8520e7376..de184bd7608 100644 --- a/apps/web/tsconfig.spec.json +++ b/apps/web/tsconfig.spec.json @@ -1,3 +1,4 @@ { - "extends": "./tsconfig.json" + "extends": "./tsconfig.json", + "files": ["./test.setup.ts"] } diff --git a/libs/angular/tsconfig.json b/libs/angular/tsconfig.json index d4625efa3de..6004a56fb55 100644 --- a/libs/angular/tsconfig.json +++ b/libs/angular/tsconfig.json @@ -1,6 +1,5 @@ { "extends": "../shared/tsconfig.libs", "include": ["src", "spec"], - "exclude": ["node_modules", "dist"], - "files": ["./test.setup.ts"] + "exclude": ["node_modules", "dist"] } diff --git a/libs/angular/tsconfig.spec.json b/libs/angular/tsconfig.spec.json index fc8520e7376..de184bd7608 100644 --- a/libs/angular/tsconfig.spec.json +++ b/libs/angular/tsconfig.spec.json @@ -1,3 +1,4 @@ { - "extends": "./tsconfig.json" + "extends": "./tsconfig.json", + "files": ["./test.setup.ts"] } diff --git a/libs/common/tsconfig.json b/libs/common/tsconfig.json index d4625efa3de..6004a56fb55 100644 --- a/libs/common/tsconfig.json +++ b/libs/common/tsconfig.json @@ -1,6 +1,5 @@ { "extends": "../shared/tsconfig.libs", "include": ["src", "spec"], - "exclude": ["node_modules", "dist"], - "files": ["./test.setup.ts"] + "exclude": ["node_modules", "dist"] } diff --git a/libs/common/tsconfig.spec.json b/libs/common/tsconfig.spec.json index fc8520e7376..de184bd7608 100644 --- a/libs/common/tsconfig.spec.json +++ b/libs/common/tsconfig.spec.json @@ -1,3 +1,4 @@ { - "extends": "./tsconfig.json" + "extends": "./tsconfig.json", + "files": ["./test.setup.ts"] } diff --git a/libs/components/tsconfig.json b/libs/components/tsconfig.json index 88d289ec143..69cc9a3edeb 100644 --- a/libs/components/tsconfig.json +++ b/libs/components/tsconfig.json @@ -28,6 +28,5 @@ "strictInjectionParameters": true, "strictInputAccessModifiers": true, "strictTemplates": true - }, - "files": ["./test.setup.ts"] + } } diff --git a/libs/components/tsconfig.spec.json b/libs/components/tsconfig.spec.json index fc8520e7376..de184bd7608 100644 --- a/libs/components/tsconfig.spec.json +++ b/libs/components/tsconfig.spec.json @@ -1,3 +1,4 @@ { - "extends": "./tsconfig.json" + "extends": "./tsconfig.json", + "files": ["./test.setup.ts"] } diff --git a/libs/node/tsconfig.json b/libs/node/tsconfig.json index d4625efa3de..6004a56fb55 100644 --- a/libs/node/tsconfig.json +++ b/libs/node/tsconfig.json @@ -1,6 +1,5 @@ { "extends": "../shared/tsconfig.libs", "include": ["src", "spec"], - "exclude": ["node_modules", "dist"], - "files": ["./test.setup.ts"] + "exclude": ["node_modules", "dist"] } diff --git a/libs/node/tsconfig.spec.json b/libs/node/tsconfig.spec.json index fc8520e7376..de184bd7608 100644 --- a/libs/node/tsconfig.spec.json +++ b/libs/node/tsconfig.spec.json @@ -1,3 +1,4 @@ { - "extends": "./tsconfig.json" + "extends": "./tsconfig.json", + "files": ["./test.setup.ts"] } diff --git a/libs/shared/jest.config.base.js b/libs/shared/jest.config.base.js index 6d45dd71baa..7538064c284 100644 --- a/libs/shared/jest.config.base.js +++ b/libs/shared/jest.config.base.js @@ -9,4 +9,11 @@ module.exports = { // https://github.com/facebook/jest/issues/9430#issuecomment-1149882002 // Also anecdotally improves performance when run locally maxWorkers: 3, + + // Jest does not use tsconfig.spec.json by default + globals: { + "ts-jest": { + tsconfig: "/tsconfig.spec.json", + }, + }, };