Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EC-423] Fix unit tests #3265

Merged
merged 17 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions apps/browser/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: ["<rootDir>/test.setup.ts"],
...sharedConfig,
preset: "jest-preset-angular",
setupFilesAfterEnv: ["<rootDir>/test.setup.ts"],
moduleNameMapper: pathsToModuleNameMapper(compilerOptions?.paths || {}, {
prefix: "<rootDir>/",
}),
Expand Down
3 changes: 2 additions & 1 deletion apps/browser/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"extends": "./tsconfig.json"
"extends": "./tsconfig.json",
"files": ["./test.setup.ts"]
}
8 changes: 3 additions & 5 deletions apps/cli/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: ["<rootDir>/spec/test.setup.ts"],
eliykat marked this conversation as resolved.
Show resolved Hide resolved
collectCoverage: true,
coverageReporters: ["html", "lcov"],
coverageDirectory: "coverage",
setupFilesAfterEnv: ["<rootDir>/test.setup.ts"],
moduleNameMapper: pathsToModuleNameMapper(compilerOptions?.paths || {}, {
prefix: "<rootDir>/",
}),
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion apps/cli/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"extends": "./tsconfig.json"
"extends": "./tsconfig.json",
"files": ["./test.setup.ts"]
}
8 changes: 4 additions & 4 deletions apps/web/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: ["<rootDir>/test.config.ts"],
setupFilesAfterEnv: ["<rootDir>/test.setup.ts"],
moduleNameMapper: pathsToModuleNameMapper(compilerOptions?.paths || {}, {
prefix: "<rootDir>/",
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -75,6 +76,10 @@ describe("TrialInitiationComponent", () => {
{ provide: LogService, useClass: Substitute.for<LogService>() },
{ provide: I18nService, useClass: Substitute.for<I18nService>() },
{ provide: TitleCasePipe, useClass: Substitute.for<TitleCasePipe>() },
{
provide: PolicyApiServiceAbstraction,
useClass: Substitute.for<PolicyApiServiceAbstraction>(),
},
{
provide: VerticalStepperComponent,
useClass: VerticalStepperStubComponent,
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion apps/web/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
3 changes: 2 additions & 1 deletion apps/web/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"extends": "./tsconfig.json"
"extends": "./tsconfig.json",
"files": ["./test.setup.ts"]
}
6 changes: 6 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ module.exports = {
projects: [
"<rootDir>/apps/browser/jest.config.js",
"<rootDir>/apps/cli/jest.config.js",
"<rootDir>/apps/web/jest.config.js",

"<rootDir>/libs/angular/jest.config.js",
"<rootDir>/libs/common/jest.config.js",
"<rootDir>/libs/components/jest.config.js",
"<rootDir>/libs/electron/jest.config.js",
"<rootDir>/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,
};
9 changes: 4 additions & 5 deletions libs/angular/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: ["<rootDir>/spec/test.setup.ts"],
collectCoverage: true,
coverageReporters: ["html", "lcov"],
coverageDirectory: "coverage",
setupFilesAfterEnv: ["<rootDir>/test.setup.ts"],
moduleNameMapper: pathsToModuleNameMapper(compilerOptions?.paths || {}, {
prefix: "<rootDir>/",
}),
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion libs/angular/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"extends": "./tsconfig.json"
"extends": "./tsconfig.json",
"files": ["./test.setup.ts"]
}
9 changes: 4 additions & 5 deletions libs/common/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: ["<rootDir>/spec/test.setup.ts"],
collectCoverage: true,
coverageReporters: ["html", "lcov"],
coverageDirectory: "coverage",
setupFilesAfterEnv: ["<rootDir>/test.setup.ts"],
eliykat marked this conversation as resolved.
Show resolved Hide resolved
moduleNameMapper: pathsToModuleNameMapper(compilerOptions?.paths || {}, {
prefix: "<rootDir>/",
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
`;
2 changes: 1 addition & 1 deletion libs/common/spec/models/domain/encArrayBuffer.spec.ts
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down
2 changes: 1 addition & 1 deletion libs/common/spec/services/folder.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
3 changes: 2 additions & 1 deletion libs/common/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"extends": "./tsconfig.json"
"extends": "./tsconfig.json",
"files": ["./test.setup.ts"]
}
9 changes: 4 additions & 5 deletions libs/components/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: ["<rootDir>/spec/test.setup.ts"],
collectCoverage: true,
coverageReporters: ["html", "lcov"],
coverageDirectory: "coverage",
setupFilesAfterEnv: ["<rootDir>/test.setup.ts"],
moduleNameMapper: pathsToModuleNameMapper(compilerOptions?.paths || {}, {
prefix: "<rootDir>/",
}),
Expand Down
4 changes: 2 additions & 2 deletions libs/components/src/button/button.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion libs/components/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"extends": "./tsconfig.json"
"extends": "./tsconfig.json",
"files": ["./test.setup.ts"]
}
8 changes: 3 additions & 5 deletions libs/electron/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: ["<rootDir>/spec/test.setup.ts"],
collectCoverage: true,
coverageReporters: ["html", "lcov"],
coverageDirectory: "coverage",
moduleNameMapper: pathsToModuleNameMapper(compilerOptions?.paths || {}, {
prefix: "<rootDir>/",
}),
Expand Down
9 changes: 4 additions & 5 deletions libs/node/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: ["<rootDir>/spec/test.setup.ts"],
eliykat marked this conversation as resolved.
Show resolved Hide resolved
collectCoverage: true,
coverageReporters: ["html", "lcov"],
coverageDirectory: "coverage",
setupFilesAfterEnv: ["<rootDir>/test.setup.ts"],
moduleNameMapper: pathsToModuleNameMapper(compilerOptions?.paths || {}, {
prefix: "<rootDir>/",
}),
Expand Down
Empty file removed libs/node/spec/test.setup.ts
Empty file.
File renamed without changes.
3 changes: 2 additions & 1 deletion libs/node/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"extends": "./tsconfig.json"
"extends": "./tsconfig.json",
"files": ["./test.setup.ts"]
}
19 changes: 19 additions & 0 deletions libs/shared/jest.config.base.js
Original file line number Diff line number Diff line change
@@ -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: "<rootDir>/tsconfig.spec.json",
},
},
};
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,5 @@
"engines": {
"node": "~16",
"npm": "~8"
},
"jest": {
"testEnvironment": "node"
}
}