From dc918aea1d1b6377f98251459dfdbdc38880cad7 Mon Sep 17 00:00:00 2001 From: Evan Hahn <69474926+EvanHahn-Signal@users.noreply.github.com> Date: Mon, 11 Jan 2021 14:17:09 -0600 Subject: [PATCH] Check leaks in Mocha --- .mocharc.json | 3 +++ .../quill/emoji/completion_test.tsx | 17 --------------- .../quill/mentions/completion_test.tsx | 21 ------------------- 3 files changed, 3 insertions(+), 38 deletions(-) create mode 100644 .mocharc.json rename ts/{test-node => test-electron}/quill/emoji/completion_test.tsx (96%) rename ts/{test-node => test-electron}/quill/mentions/completion_test.tsx (94%) diff --git a/.mocharc.json b/.mocharc.json new file mode 100644 index 000000000..34c571cd4 --- /dev/null +++ b/.mocharc.json @@ -0,0 +1,3 @@ +{ + "checkLeaks": true +} diff --git a/ts/test-node/quill/emoji/completion_test.tsx b/ts/test-electron/quill/emoji/completion_test.tsx similarity index 96% rename from ts/test-node/quill/emoji/completion_test.tsx rename to ts/test-electron/quill/emoji/completion_test.tsx index 291abc026..2da378827 100644 --- a/ts/test-node/quill/emoji/completion_test.tsx +++ b/ts/test-electron/quill/emoji/completion_test.tsx @@ -7,9 +7,6 @@ import sinon from 'sinon'; import { EmojiCompletion } from '../../../quill/emoji/completion'; import { EmojiData } from '../../../components/emoji/lib'; -// eslint-disable-next-line @typescript-eslint/no-explicit-any -const globalAsAny = global as any; - describe('emojiCompletion', () => { let emojiCompletion: EmojiCompletion; const mockOnPickEmoji = sinon.spy(); @@ -18,14 +15,6 @@ describe('emojiCompletion', () => { let mockQuill: any; beforeEach(function beforeEach() { - this.oldDocument = globalAsAny.document; - globalAsAny.document = { - body: { - appendChild: () => null, - }, - createElement: () => null, - }; - mockQuill = { getLeaf: sinon.stub(), getSelection: sinon.stub(), @@ -55,12 +44,6 @@ describe('emojiCompletion', () => { mockOnPickEmoji.resetHistory(); mockSetEmojiPickerElement.resetHistory(); (emojiCompletion.render as sinon.SinonStub).resetHistory(); - - if (this.oldDocument === undefined) { - delete globalAsAny.document; - } else { - globalAsAny.document = this.oldDocument; - } }); describe('getCurrentLeafTextPartitions', () => { diff --git a/ts/test-node/quill/mentions/completion_test.tsx b/ts/test-electron/quill/mentions/completion_test.tsx similarity index 94% rename from ts/test-node/quill/mentions/completion_test.tsx rename to ts/test-electron/quill/mentions/completion_test.tsx index 46652e2c4..9cc25e0c5 100644 --- a/ts/test-node/quill/mentions/completion_test.tsx +++ b/ts/test-electron/quill/mentions/completion_test.tsx @@ -52,20 +52,6 @@ const members: Array = [ me, ]; -declare global { - // eslint-disable-next-line @typescript-eslint/no-namespace - namespace NodeJS { - interface Global { - document: { - body: { - appendChild: unknown; - }; - createElement: unknown; - }; - } - } -} - describe('MentionCompletion', () => { const mockSetMentionPickerElement = sinon.spy(); @@ -78,13 +64,6 @@ describe('MentionCompletion', () => { let mentionCompletion: MentionCompletion; beforeEach(function beforeEach() { - global.document = { - body: { - appendChild: sinon.spy(), - }, - createElement: sinon.spy(), - }; - const memberRepositoryRef: MutableRefObject = { current: new MemberRepository(members), };