From b8ec791ca17e36b74facde665729164c5323adf1 Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Tue, 30 Nov 2021 15:08:42 -0800 Subject: [PATCH] Don't call afterEach within beforeEach (#46963) Otherwise, a new afterEach handler is added for each test case and the number of handlers run grows quadratically. --- src/testRunner/unittests/createMapShim.ts | 6 +++--- src/testRunner/unittests/createSetShim.ts | 6 +++--- src/testRunner/unittests/debugDeprecation.ts | 10 ++++++---- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/testRunner/unittests/createMapShim.ts b/src/testRunner/unittests/createMapShim.ts index d96524057a4c1..e76718e1f244b 100644 --- a/src/testRunner/unittests/createMapShim.ts +++ b/src/testRunner/unittests/createMapShim.ts @@ -130,9 +130,9 @@ namespace ts { } MapShim = ShimCollections.createMapShim(getIterator); - afterEach(() => { - MapShim = undefined!; - }); + }); + afterEach(() => { + MapShim = undefined!; }); it("iterates values in insertion order and handles changes with string keys", () => { diff --git a/src/testRunner/unittests/createSetShim.ts b/src/testRunner/unittests/createSetShim.ts index 28a6998e0eb07..bef82d78e2b61 100644 --- a/src/testRunner/unittests/createSetShim.ts +++ b/src/testRunner/unittests/createSetShim.ts @@ -128,9 +128,9 @@ namespace ts { } SetShim = ShimCollections.createSetShim(getIterator); - afterEach(() => { - SetShim = undefined!; - }); + }); + afterEach(() => { + SetShim = undefined!; }); it("iterates values in insertion order and handles changes with string keys", () => { diff --git a/src/testRunner/unittests/debugDeprecation.ts b/src/testRunner/unittests/debugDeprecation.ts index 86d4490c4c2c2..1687f24d40644 100644 --- a/src/testRunner/unittests/debugDeprecation.ts +++ b/src/testRunner/unittests/debugDeprecation.ts @@ -1,10 +1,12 @@ namespace ts { describe("unittests:: debugDeprecation", () => { + let loggingHost: LoggingHost | undefined; beforeEach(() => { - const loggingHost = Debug.loggingHost; - afterEach(() => { - Debug.loggingHost = loggingHost; - }); + loggingHost = Debug.loggingHost; + }); + afterEach(() => { + Debug.loggingHost = loggingHost; + loggingHost = undefined; }); describe("deprecateFunction", () => { it("silent deprecation", () => {