From 4d8e68e96fbc2fcacd1ae27e0cccf2dd7cdf8c98 Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Sun, 13 Aug 2023 00:30:43 +0200 Subject: [PATCH] Abort signal immediately to fix race condition of tests --- packages/api/test/unit/client/fetch.test.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/packages/api/test/unit/client/fetch.test.ts b/packages/api/test/unit/client/fetch.test.ts index bf18a6e0ab65..dac702da2291 100644 --- a/packages/api/test/unit/client/fetch.test.ts +++ b/packages/api/test/unit/client/fetch.test.ts @@ -117,14 +117,7 @@ describe("FetchError", function () { ); } - let signal: AbortSignal | undefined; - if (abort) { - const controller = new AbortController(); - setTimeout(() => controller.abort(), 0); - signal = controller.signal; - } else if (timeout) { - signal = AbortSignal.timeout(10); - } + const signal = abort ? AbortSignal.abort() : timeout ? AbortSignal.timeout(1) : null; await expect(fetch(url, {signal})).to.be.rejected.then((error: FetchError) => { expect(error.type).to.be.equal(testCase.errorType); expect(error.code).to.be.equal(testCase.errorCode);