From 129e43a37e3d2b5eb51c1e628225a6d265a6f6bb Mon Sep 17 00:00:00 2001 From: Alessia Bellisario Date: Thu, 3 Oct 2024 14:23:23 -0400 Subject: [PATCH 1/5] chore: fix Jest polyfills --- .storybook/public/mockServiceWorker.js | 2 +- jest.polyfills.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.storybook/public/mockServiceWorker.js b/.storybook/public/mockServiceWorker.js index 15751fa..a8262f0 100644 --- a/.storybook/public/mockServiceWorker.js +++ b/.storybook/public/mockServiceWorker.js @@ -8,7 +8,7 @@ * - Please do NOT serve this file on production. */ -const PACKAGE_VERSION = '2.3.5' +const PACKAGE_VERSION = '2.4.9' const INTEGRITY_CHECKSUM = '26357c79639bfa20d64c0efca2a87423' const IS_MOCKED_RESPONSE = Symbol('isMockedResponse') const activeClientIds = new Set() diff --git a/jest.polyfills.js b/jest.polyfills.js index e20e28b..52fa70b 100644 --- a/jest.polyfills.js +++ b/jest.polyfills.js @@ -27,8 +27,8 @@ Object.defineProperties(globalThis, { File: { value: File }, Headers: { value: Headers }, FormData: { value: FormData }, - Request: { value: Request }, - Response: { value: Response }, + Request: { value: Request, configurable: true }, + Response: { value: Response, configurable: true }, }); // Symbol.dispose is not defined From b239e04cb7e74c2fe3960f3973b884487a958279 Mon Sep 17 00:00:00 2001 From: Alessia Bellisario Date: Thu, 3 Oct 2024 14:27:38 -0400 Subject: [PATCH 2/5] chore: test higher delay in node processes --- src/handlers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/handlers.ts b/src/handlers.ts index 4b857f3..701647f 100644 --- a/src/handlers.ts +++ b/src/handlers.ts @@ -105,7 +105,7 @@ function createHandlerFromSchema( // This sometimes caused multipart responses to be batched into a single // render by React, so we'll use a longer delay of 20ms. if (_delay === "real" && isNodeProcess()) { - _delay = 20; + _delay = 50; } let testSchema: GraphQLSchema = schema; From d4da51ad1976852dc696262edd826a0bad334f96 Mon Sep 17 00:00:00 2001 From: Alessia Bellisario Date: Thu, 3 Oct 2024 14:29:52 -0400 Subject: [PATCH 3/5] fix: test that validates rollback via disposable --- src/__tests__/handlers.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/__tests__/handlers.test.tsx b/src/__tests__/handlers.test.tsx index 345122c..2177f02 100644 --- a/src/__tests__/handlers.test.tsx +++ b/src/__tests__/handlers.test.tsx @@ -342,6 +342,6 @@ describe("unit tests", () => { // @ts-expect-error intentionally accessing a property that has been // excluded from the type - expect(ecommerceHandler.replaceDelay["currentDelay"]).toBe(20); + expect(ecommerceHandler.replaceDelay["currentDelay"]).toBe(50); }); }); From e10aa611e5bcbe6562f9b4b6d319b5ed6f5cb501 Mon Sep 17 00:00:00 2001 From: Alessia Bellisario Date: Thu, 3 Oct 2024 14:31:32 -0400 Subject: [PATCH 4/5] chore: add changeset for new delay value --- .changeset/tough-starfishes-tickle.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/tough-starfishes-tickle.md diff --git a/.changeset/tough-starfishes-tickle.md b/.changeset/tough-starfishes-tickle.md new file mode 100644 index 0000000..5983fa8 --- /dev/null +++ b/.changeset/tough-starfishes-tickle.md @@ -0,0 +1,5 @@ +--- +"@apollo/graphql-testing-library": patch +--- + +Use 50ms as the delay value in Node processes, since 20ms was still resulting in occasional batched renders. From 3f983b21db2c7f715b4bd1a9b6f77f5ecc245196 Mon Sep 17 00:00:00 2001 From: Alessia Bellisario Date: Wed, 11 Dec 2024 06:12:45 -0500 Subject: [PATCH 5/5] wip --- src/utilities.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/utilities.ts b/src/utilities.ts index 9a3aa23..af2356e 100644 --- a/src/utilities.ts +++ b/src/utilities.ts @@ -72,7 +72,11 @@ function createDefaultResolvers(typesMap: Map>) { for (const key of typesMap.keys()) { defaultResolvers[key] = { __resolveType(data) { - return data.__typename || typesMap.get(key)?.values().next().value; + return ( + // fallback to an empty string here to satisfy TS, since + // all keys in typesMap should have ' + data.__typename || typesMap.get(key)?.values().next().value || "" + ); }, }; }