Skip to content

Commit

Permalink
issue #4734 Use separate mock api for each test (#4928)
Browse files Browse the repository at this point in the history
* remove unnecessary eslint-disable

* choose random port for tests

* improve test port setting

* add default mock api

* separate port for each test

* get extension id once

* make tests independent

* fix extensionDir path

* update setMaxListeners

* add debug info

* more logs

* update WKD_API_HOST

* update consts

* debug

* test ContactStore

* run all unit tests

* run only unit tests

* fix unit mock port

* run all wkd tests

* separate gmail tests

* disable gmail

* disable gmail

* remove acct param

* add logging

* more logging

* new logs

* log oauth url

* log errors

* log current consts

* log extension dir

* log extension files

* update config script

* update config script

* update config script

* check test

* run all tests

* fix unit tests

* use port for send message strategy

* fix flaky tests

* split standard tests

* use browser pool

* fix settings tests

* fix compose and settings tests

* fix for settings tests

* fix email parsing

* fix setup tests

* use custom port for send strategies

* fix typo

* fix fes mock endpoints

* fix mock email parsing

* code cleanup

* fix mock errors handling

* code cleanup

* code cleanup

* increase concurrency

* close mock api on test end

* fix mock api close

* code cleanup

* remove closeMockApi from AvaContext

* move closeMockApi to try/finally
  • Loading branch information
sosnovsky committed Feb 1, 2023
1 parent d5ee302 commit c8485e4
Show file tree
Hide file tree
Showing 64 changed files with 1,269 additions and 1,387 deletions.
5 changes: 1 addition & 4 deletions .eslintrc.js
Expand Up @@ -70,7 +70,6 @@ module.exports = {
leadingUnderscore: 'allow',
},
],
'@typescript-eslint/no-empty-function': 'error',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-explicit-any': ['warn'],
'@typescript-eslint/no-floating-promises': 'error',
Expand Down Expand Up @@ -111,14 +110,13 @@ module.exports = {
'no-control-regex': 0,
'no-debugger': 'error',
'no-empty': 'error',
'no-empty-function': 'error',
'no-empty-pattern': 0,
'no-eval': 'error',
'no-fallthrough': 0,
'no-invalid-this': 'off',
'no-new-wrappers': 'error',
'no-null/no-null': 'error',
'no-only-tests/no-only-tests': ['error', { block: ['ava.default'] }],
'no-only-tests/no-only-tests': ['error'],
'no-prototype-builtins': 0,
'no-shadow': 'off',
'no-throw-literal': 'error',
Expand All @@ -128,7 +126,6 @@ module.exports = {
'no-unsafe-finally': 'error',
'no-unused-expressions': 'off',
'no-unused-labels': 'error',
'no-unused-vars': 0,
'no-use-before-define': 'off',
'no-useless-escape': 0,
'no-var': 'error',
Expand Down
3 changes: 1 addition & 2 deletions conf/tsconfig.test.json
Expand Up @@ -17,7 +17,6 @@
"../test/source/test.ts",
"../test/source/patterns.ts",
"../test/source/async-stack.ts",
"../test/source/buf.ts",
"../test/source/mock.ts"
"../test/source/buf.ts"
]
}
6 changes: 2 additions & 4 deletions extension/chrome/elements/attachment.ts
Expand Up @@ -103,8 +103,7 @@ export class AttachmentDownloadView extends View {
$('img#file-format').attr('src', this.getFileIconSrc());
if (!this.size && this.url) {
// download url of a file that has an unknown size
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.getUrlFileSize(this.url!)
this.getUrlFileSize(this.url)
.then(fileSize => {
if (typeof fileSize !== 'undefined') {
this.size = fileSize;
Expand Down Expand Up @@ -213,8 +212,7 @@ export class AttachmentDownloadView extends View {
console.info('trying to figure out figetUrlFileSizee size');
if (url.indexOf('docs.googleusercontent.getUrlFileSizeom/docs/securesc') !== -1) {
try {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const googleDriveFileId = url.split('/').pop()!.split('?').shift(); // try and catch any errors below if structure is not as expected
const googleDriveFileId = url.split('/').pop()?.split('?').shift(); // try and catch any errors below if structure is not as expected
url = googleDriveFileId ? `https://drive.google.com/uc?export=download&id=${googleDriveFileId}` : url; // attempt to get length headers from Google Drive file if available
} catch (e) {
// leave url as is
Expand Down
3 changes: 1 addition & 2 deletions extension/chrome/elements/backup.ts
Expand Up @@ -72,8 +72,7 @@ View.run(
};

private sendResizeMsg = () => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const desiredHeight = $('#backup_block').height()!;
const desiredHeight = $('#backup_block').height();
BrowserMsg.send.setCss(this.parentTabId, {
selector: `iframe#${this.frameId}`,
css: { height: `${desiredHeight}px` },
Expand Down
Expand Up @@ -17,7 +17,7 @@ declare const filesize: { filesize: Function }; // eslint-disable-line @typescri
export class PgpBlockViewAttachmentsModule {
public includedAttachments: Attachment[] = [];

public constructor(private view: PgpBlockView) {} // eslint-disable-line no-empty-function
public constructor(private view: PgpBlockView) {}

public renderInnerAttachments = (attachments: Attachment[], isEncrypted: boolean) => {
Xss.sanitizeAppend('#pgp_block', '<div id="attachments"></div>');
Expand Down
Expand Up @@ -18,7 +18,6 @@ export class PgpBlockViewDecryptModule {
private msgFetchedFromApi: false | GmailResponseFormat = false;
private isPwdMsgBasedOnMsgSnippet: boolean | undefined;

// eslint-disable-next-line no-empty-function
public constructor(private view: PgpBlockView) {}

public initialize = async (verificationPubs: string[], forcePullMsgFromApi: boolean) => {
Expand Down
Expand Up @@ -16,7 +16,6 @@ import { Str } from '../../../js/common/core/common.js';
export class PgpBlockViewErrorModule {
private debugId = Str.sloppyRandom();

// eslint-disable-next-line no-empty-function
public constructor(private view: PgpBlockView) {}

public renderErr = async (errBoxContent: string, renderRawMsg: string | undefined, errMsg?: string) => {
Expand Down
Expand Up @@ -7,7 +7,7 @@ import { Str } from '../../../js/common/core/common.js';
import { Xss } from '../../../js/common/platform/xss.js';

export class PgpBlockViewQuoteModule {
public constructor(private view: PgpBlockView) {} // eslint-disable-line no-empty-function
public constructor(private view: PgpBlockView) {}

public separateQuotedContentAndRenderText = async (decryptedContent: string, isHtml: boolean) => {
if (isHtml) {
Expand Down
Expand Up @@ -23,7 +23,6 @@ export class PgpBlockViewRenderModule {
private heightHist: number[] = [];
private printMailInfoHtml!: string;

// eslint-disable-next-line no-empty-function
public constructor(private view: PgpBlockView) {}

public initPrintView = async () => {
Expand Down Expand Up @@ -133,14 +132,12 @@ export class PgpBlockViewRenderModule {
</body>
</html>
`;
/* eslint-disable @typescript-eslint/no-non-null-assertion */
w!.document.write(html);
w?.document.write(html);
// Give some time for above dom to load in print dialog
// https://stackoverflow.com/questions/31725373/google-chrome-not-showing-image-in-print-preview
await Ui.time.sleep(250);
w!.window.print();
w!.document.close();
/* eslint-enable @typescript-eslint/no-non-null-assertion */
w?.window.print();
w?.document.close();
};

public renderText = (text: string) => {
Expand Down
Expand Up @@ -11,7 +11,6 @@ import { Value } from '../../../js/common/core/common.js';
import { BrowserMsg } from '../../../js/common/browser/browser-msg.js';

export class PgpBlockViewSignatureModule {
// eslint-disable-next-line no-empty-function
public constructor(private view: PgpBlockView) {}

public renderPgpSignatureCheckResult = async (
Expand Down
1 change: 0 additions & 1 deletion extension/chrome/settings/setup/setup-create-key.ts
Expand Up @@ -13,7 +13,6 @@ import { OpenPGPKey } from '../../../js/common/core/crypto/pgp/openpgp-key.js';
import { saveKeysAndPassPhrase } from '../../../js/common/helpers.js';

export class SetupCreateKeyModule {
// eslint-disable-next-line no-empty-function
public constructor(private view: SetupView) {}

public actionCreateKeyHandler = async () => {
Expand Down
1 change: 0 additions & 1 deletion extension/chrome/settings/setup/setup-import-key.ts
Expand Up @@ -14,7 +14,6 @@ import { Lang } from '../../../js/common/lang.js';
import { saveKeysAndPassPhrase } from '../../../js/common/helpers.js';

export class SetupImportKeyModule {
// eslint-disable-next-line no-empty-function
public constructor(private view: SetupView) {}

public actionImportPrivateKeyHandle = async (button: HTMLElement) => {
Expand Down
Expand Up @@ -16,7 +16,6 @@ import { processAndStoreKeysFromEkmLocally, saveKeysAndPassPhrase } from '../../
import { Xss } from '../../../js/common/platform/xss.js';

export class SetupWithEmailKeyManagerModule {
// eslint-disable-next-line no-empty-function
public constructor(private view: SetupView) {}

public continueEkmSetupHandler = async () => {
Expand Down
1 change: 0 additions & 1 deletion extension/chrome/settings/setup/setup-recover-key.ts
Expand Up @@ -15,7 +15,6 @@ import { KeyStore } from '../../../js/common/platform/store/key-store.js';
import { saveKeysAndPassPhrase } from '../../../js/common/helpers.js';

export class SetupRecoverKeyModule {
// eslint-disable-next-line no-empty-function
public constructor(private view: SetupView) {}

public actionRecoverAccountHandler = async () => {
Expand Down
1 change: 0 additions & 1 deletion extension/chrome/settings/setup/setup-render.ts
Expand Up @@ -16,7 +16,6 @@ import { KeyImportUi } from '../../../js/common/ui/key-import-ui.js';
export class SetupRenderModule {
public readonly emailDomainsToSkip = ['yahoo', 'live', 'outlook'];

// eslint-disable-next-line no-empty-function
public constructor(private view: SetupView) {}

public renderInitial = async (): Promise<void> => {
Expand Down
1 change: 0 additions & 1 deletion extension/js/common/client-configuration.ts
Expand Up @@ -49,7 +49,6 @@ export class ClientConfigurationError extends UnreportableError {
* These either enforce, alter or forbid various behavior to fit customer needs
*/
export class ClientConfiguration {
// eslint-disable-next-line no-empty-function
protected constructor(private clientConfigurationJson: ClientConfigurationJson, public domainName: string) {}

public static newInstance = async (acctEmail: string): Promise<ClientConfiguration> => {
Expand Down
4 changes: 2 additions & 2 deletions extension/js/common/core/common.ts
Expand Up @@ -23,11 +23,11 @@ export class Str {
let name: string | undefined;
if (full.includes('<') && full.includes('>')) {
email = full
.substr(full.indexOf('<') + 1, full.indexOf('>') - full.indexOf('<') - 1)
.substring(full.indexOf('<') + 1, full.indexOf('>'))
.replace(/["']/g, '')
.trim()
.toLowerCase();
name = full.substr(0, full.indexOf('<')).replace(/["']/g, '').trim();
name = full.substring(0, full.indexOf('<')).replace(/["']/g, '').trim();
} else {
email = full.replace(/["']/g, '').trim().toLowerCase();
}
Expand Down
2 changes: 1 addition & 1 deletion extension/js/common/core/crypto/pgp/pgp-password.ts
Expand Up @@ -111,7 +111,7 @@ export class PgpPwd {
.toUpperCase()
.replace(/[^A-Z0-9]|0|O|1/g, '')
.replace(/(.{4})/g, '$1-')
.substr(0, 19);
.substring(0, 19);
};

private static readableCrackTime = (totalSeconds: number) => {
Expand Down
2 changes: 1 addition & 1 deletion extension/js/common/core/expiration-cache.ts
Expand Up @@ -6,7 +6,7 @@
export class ExpirationCache {
private cache: { [key: string]: { value: string; expiration: number } } = {};

// eslint-disable-next-line @typescript-eslint/naming-convention, no-empty-function
// eslint-disable-next-line @typescript-eslint/naming-convention
public constructor(public EXPIRATION_TICKS: number) {}

public set = (key: string, value?: string, expiration?: number) => {
Expand Down
2 changes: 1 addition & 1 deletion extension/js/common/core/msg-block.ts
Expand Up @@ -32,7 +32,7 @@ export class MsgBlock {
public attachmentMeta?: AttachmentMeta, // only in plainAttachment, encryptedAttachment, decryptedAttachment, encryptedAttachmentLink (not sure if always)
public decryptErr?: DecryptError, // only in decryptErr block, always
public verifyRes?: VerifyRes
) {} // eslint-disable-line no-empty-function
) {}

public static fromContent = (type: MsgBlockType, content: string | Buf, missingEnd = false): MsgBlock => {
return new MsgBlock(type, content, !missingEnd);
Expand Down

0 comments on commit c8485e4

Please sign in to comment.