From 9739796919e67e5f70dc4cbc26348d4c692e6d0f Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Wed, 22 Mar 2023 17:36:56 +0100 Subject: [PATCH 1/2] test(fluentui/react): fix initial global leaks that were causing OOM issues --- .../DetailsList/DetailsList.test.tsx | 7 ++--- .../DetailsList/DetailsListV2.test.tsx | 3 +- .../Dialog/Dialog.deprecated.test.tsx | 21 ++++++------- .../src/components/Dialog/Dialog.test.tsx | 30 ++++++++++++------- .../style-utilities/src/styles/theme.test.ts | 19 +++++++++--- scripts/jest/src/jest.preset.v8.js | 2 ++ scripts/jest/src/jest.preset.v8.spec.ts | 2 ++ 7 files changed, 55 insertions(+), 29 deletions(-) diff --git a/packages/react/src/components/DetailsList/DetailsList.test.tsx b/packages/react/src/components/DetailsList/DetailsList.test.tsx index d2e40b859ee35..9f82b65c97542 100644 --- a/packages/react/src/components/DetailsList/DetailsList.test.tsx +++ b/packages/react/src/components/DetailsList/DetailsList.test.tsx @@ -68,18 +68,17 @@ function customColumnDivider( describe('DetailsList', () => { let spy: jest.SpyInstance; - beforeAll(() => { + beforeEach(() => { /* eslint-disable-next-line @typescript-eslint/no-empty-function */ spy = jest.spyOn(window, 'scrollTo').mockImplementation(() => {}); + resetIds(); }); afterAll(() => { spy.mockRestore(); }); - beforeEach(() => { - resetIds(); - }); + // beforeEach(() => {}); afterEach(() => { if ((setTimeout as unknown as jest.Mock).mock) { diff --git a/packages/react/src/components/DetailsList/DetailsListV2.test.tsx b/packages/react/src/components/DetailsList/DetailsListV2.test.tsx index da42473541867..9766f957b55d8 100644 --- a/packages/react/src/components/DetailsList/DetailsListV2.test.tsx +++ b/packages/react/src/components/DetailsList/DetailsListV2.test.tsx @@ -77,7 +77,8 @@ const groupProps: IDetailsGroupRenderProps = { */ describe('DetailsListV2', () => { let spy: jest.SpyInstance; - beforeAll(() => { + + beforeEach(() => { /* eslint-disable-next-line @typescript-eslint/no-empty-function */ spy = jest.spyOn(window, 'scrollTo').mockImplementation(() => {}); }); diff --git a/packages/react/src/components/Dialog/Dialog.deprecated.test.tsx b/packages/react/src/components/Dialog/Dialog.deprecated.test.tsx index 57c18ad1942db..07c6f06799406 100644 --- a/packages/react/src/components/Dialog/Dialog.deprecated.test.tsx +++ b/packages/react/src/components/Dialog/Dialog.deprecated.test.tsx @@ -6,24 +6,25 @@ import { resetIds, setWarningCallback } from '../../Utilities'; import { DialogBase } from './Dialog.base'; describe('Dialog deprecated props', () => { - beforeEach(() => { - resetIds(); + beforeAll(() => { + // eslint-disable-next-line @typescript-eslint/no-empty-function + const noop = () => {}; + // Prevent warn deprecations from failing test + setWarningCallback(noop); }); - afterAll(() => { + beforeEach(() => { resetIds(); - }); - - beforeAll(() => { - // Prevent warn deprecations from failing test - setWarningCallback(() => { - /* no-op */ - }); (ReactDOM.createPortal as any) = jest.fn((element, node) => { return element; }); }); + afterAll(() => { + setWarningCallback(); + // resetIds(); + }); + afterEach(() => { (ReactDOM.createPortal as any).mockClear(); jest.useRealTimers(); diff --git a/packages/react/src/components/Dialog/Dialog.test.tsx b/packages/react/src/components/Dialog/Dialog.test.tsx index 1d5b969ac78d7..83186263f8f3a 100644 --- a/packages/react/src/components/Dialog/Dialog.test.tsx +++ b/packages/react/src/components/Dialog/Dialog.test.tsx @@ -14,11 +14,6 @@ describe('Dialog', () => { resetIds(); }); - afterEach(() => { - setWarningCallback(); - jest.useRealTimers(); - }); - afterAll(() => { resetIds(); }); @@ -86,11 +81,14 @@ describe('Dialog', () => { expect(queryByRole('dialog')).toBeFalsy(); expect(onDismissed).toHaveBeenCalledTimes(1); + + jest.useRealTimers(); }); it('deprecated isOpen controls open state of the dialog', () => { // suppress deprecation warning as error - setWarningCallback(() => undefined); + // eslint-disable-next-line @typescript-eslint/no-empty-function + setWarningCallback(() => {}); jest.useFakeTimers(); const onDismissed = jest.fn(); @@ -106,6 +104,9 @@ describe('Dialog', () => { expect(queryByRole('dialog')).toBeFalsy(); expect(onDismissed).toHaveBeenCalledTimes(1); + + jest.useRealTimers(); + setWarningCallback(); }); it('Properly attaches auto-generated aria attributes IDs', () => { @@ -154,7 +155,7 @@ describe('Dialog', () => {