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.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/jest.config.js b/apps/cli/jest.config.js index 45ee9695ba9..4f0dab845ec 100644 --- a/apps/cli/jest.config.js +++ b/apps/cli/jest.config.js @@ -2,13 +2,11 @@ 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", + setupFilesAfterEnv: ["/test.setup.ts"], moduleNameMapper: pathsToModuleNameMapper(compilerOptions?.paths || {}, { prefix: "/", }), diff --git a/apps/cli/spec/test.setup.ts b/apps/cli/test.setup.ts similarity index 100% rename from apps/cli/spec/test.setup.ts rename to apps/cli/test.setup.ts 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/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/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, 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 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"] } 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/jest.config.js b/jest.config.js index cfec0420880..3ca7b5d6e9b 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", @@ -19,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, }; 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.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/jest.config.js b/libs/common/jest.config.js index ac811b2edfc..29309a78306 100644 --- a/libs/common/jest.config.js +++ b/libs/common/jest.config.js @@ -2,15 +2,14 @@ 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", - 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/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" `; 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", () => { 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); 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.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/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/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; 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.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/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/node/jest.config.js b/libs/node/jest.config.js index 056444b8307..833d03cfa5d 100644 --- a/libs/node/jest.config.js +++ b/libs/node/jest.config.js @@ -2,13 +2,12 @@ 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", + setupFilesAfterEnv: ["/test.setup.ts"], 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/electron/spec/test.setup.ts b/libs/node/test.setup.ts similarity index 100% rename from libs/electron/spec/test.setup.ts rename to libs/node/test.setup.ts 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 new file mode 100644 index 00000000000..7538064c284 --- /dev/null +++ b/libs/shared/jest.config.base.js @@ -0,0 +1,19 @@ +/* eslint-env node */ +module.exports = { + testMatch: ["**/+(*.)+(spec).+(ts)"], + 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, + + // Jest does not use tsconfig.spec.json by default + globals: { + "ts-jest": { + tsconfig: "/tsconfig.spec.json", + }, + }, +}; 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" } }