From fd99795521e92b66a8427fefc00f604f6723808a Mon Sep 17 00:00:00 2001 From: Deep Singhvi Date: Sat, 2 Nov 2024 18:53:18 -0400 Subject: [PATCH] fix(typescript): remove `jest-fetch-mock` dependency (#5077) --- generators/typescript/sdk/CHANGELOG.md | 4 + generators/typescript/sdk/VERSION | 2 +- .../utils/core-utilities/fetcher/package.json | 2 - .../src/fetcher/__test__/Fetcher.test.ts | 36 ++++-- .../fetcher/__test__/getRequestBody.test.ts | 4 - .../fetcher/__test__/getResponseBody.test.ts | 4 - .../src/fetcher/__test__/makeRequest.test.ts | 4 - .../__test__/requestWithRetries.test.ts | 4 - pnpm-lock.yaml | 104 ------------------ .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../alias/tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../bytes/tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../enum/tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../bigint/tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../bundle/tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../jsr/tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 18 ++- .../unit/fetcher/getResponseBody.test.ts | 8 +- .../tests/unit/fetcher/makeRequest.test.ts | 8 +- .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../unions/tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - .../tests/unit/fetcher/Fetcher.test.ts | 36 ++++-- .../tests/unit/fetcher/getRequestBody.test.ts | 4 - .../unit/fetcher/getResponseBody.test.ts | 4 - .../tests/unit/fetcher/makeRequest.test.ts | 4 - .../unit/fetcher/requestWithRetries.test.ts | 4 - 421 files changed, 2203 insertions(+), 2191 deletions(-) diff --git a/generators/typescript/sdk/CHANGELOG.md b/generators/typescript/sdk/CHANGELOG.md index 13d35de9fbd..bd8c4ed46d3 100644 --- a/generators/typescript/sdk/CHANGELOG.md +++ b/generators/typescript/sdk/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.41.1] - 2024-11-02 + +- Fix: Remove dev dependency on `jest-fetch-mock`. + ## [0.41.0] - 2024-10-08 - Improvement: Add a variable jitter to the exponential backoff and retry. diff --git a/generators/typescript/sdk/VERSION b/generators/typescript/sdk/VERSION index 72a8a6313bb..9ed317fb462 100644 --- a/generators/typescript/sdk/VERSION +++ b/generators/typescript/sdk/VERSION @@ -1 +1 @@ -0.41.0 +0.41.1 diff --git a/generators/typescript/utils/core-utilities/fetcher/package.json b/generators/typescript/utils/core-utilities/fetcher/package.json index 3b92c3f4ff3..083a81d5d11 100644 --- a/generators/typescript/utils/core-utilities/fetcher/package.json +++ b/generators/typescript/utils/core-utilities/fetcher/package.json @@ -28,7 +28,6 @@ "dependencies": { "form-data-encoder": "^4.0.2", "formdata-node": "^6.0.3", - "jest-fetch-mock": "^3.0.3", "node-fetch": "2.7.0", "qs": "6.12.1", "readable-stream": "^4.5.2" @@ -44,7 +43,6 @@ "depcheck": "^1.4.6", "eslint": "^8.56.0", "express": "^4.20.0", - "fetch-mock-jest": "^1.5.1", "form-data": "4.0.0", "jest": "^29.7.0", "jest-environment-jsdom": "^29.7.0", diff --git a/generators/typescript/utils/core-utilities/fetcher/src/fetcher/__test__/Fetcher.test.ts b/generators/typescript/utils/core-utilities/fetcher/src/fetcher/__test__/Fetcher.test.ts index 4541567047a..58de46dfe30 100644 --- a/generators/typescript/utils/core-utilities/fetcher/src/fetcher/__test__/Fetcher.test.ts +++ b/generators/typescript/utils/core-utilities/fetcher/src/fetcher/__test__/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json" }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }) + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }) }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }) + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")) }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }) + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }) }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read() - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream) + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/generators/typescript/utils/core-utilities/fetcher/src/fetcher/__test__/getRequestBody.test.ts b/generators/typescript/utils/core-utilities/fetcher/src/fetcher/__test__/getRequestBody.test.ts index 7482383bc61..defd4dc3613 100644 --- a/generators/typescript/utils/core-utilities/fetcher/src/fetcher/__test__/getRequestBody.test.ts +++ b/generators/typescript/utils/core-utilities/fetcher/src/fetcher/__test__/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../runtime"; import { getRequestBody } from "../getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/generators/typescript/utils/core-utilities/fetcher/src/fetcher/__test__/getResponseBody.test.ts b/generators/typescript/utils/core-utilities/fetcher/src/fetcher/__test__/getResponseBody.test.ts index 4345200fc71..143f7928e59 100644 --- a/generators/typescript/utils/core-utilities/fetcher/src/fetcher/__test__/getResponseBody.test.ts +++ b/generators/typescript/utils/core-utilities/fetcher/src/fetcher/__test__/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../runtime"; import { getResponseBody } from "../getResponseBody"; import { chooseStreamWrapper } from "../stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/generators/typescript/utils/core-utilities/fetcher/src/fetcher/__test__/makeRequest.test.ts b/generators/typescript/utils/core-utilities/fetcher/src/fetcher/__test__/makeRequest.test.ts index 6b03d175100..d5a762b3c1e 100644 --- a/generators/typescript/utils/core-utilities/fetcher/src/fetcher/__test__/makeRequest.test.ts +++ b/generators/typescript/utils/core-utilities/fetcher/src/fetcher/__test__/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../runtime"; import { makeRequest } from "../makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/generators/typescript/utils/core-utilities/fetcher/src/fetcher/__test__/requestWithRetries.test.ts b/generators/typescript/utils/core-utilities/fetcher/src/fetcher/__test__/requestWithRetries.test.ts index de62066b58f..e1508ae3245 100644 --- a/generators/typescript/utils/core-utilities/fetcher/src/fetcher/__test__/requestWithRetries.test.ts +++ b/generators/typescript/utils/core-utilities/fetcher/src/fetcher/__test__/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../runtime"; import { requestWithRetries } from "../requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ded1a9edf03..9f613dceb96 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3029,9 +3029,6 @@ importers: formdata-node: specifier: ^6.0.3 version: 6.0.3 - jest-fetch-mock: - specifier: ^3.0.3 - version: 3.0.3 node-fetch: specifier: 2.7.0 version: 2.7.0 @@ -3072,9 +3069,6 @@ importers: express: specifier: ^4.20.0 version: 4.21.1 - fetch-mock-jest: - specifier: ^1.5.1 - version: 1.5.1(node-fetch@2.7.0) form-data: specifier: 4.0.0 version: 4.0.0 @@ -9262,9 +9256,6 @@ packages: core-js-compat@3.38.1: resolution: {integrity: sha512-JRH6gfXxGmrzF3tZ57lFx97YARxCXPaMzPo6jELZhv88pBH5VXpQ+y0znKGlFnzuaihqhLbefxSJxWJMPtfDzw==} - core-js@3.38.0: - resolution: {integrity: sha512-XPpwqEodRljce9KswjZShh95qJ1URisBeKCjUdq27YdenkslVe7OO0ZJhlYXAChW7OhXaRLl8AAba7IBfoIHug==} - core-util-is@1.0.3: resolution: {integrity: sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==} @@ -9293,9 +9284,6 @@ packages: create-require@1.1.1: resolution: {integrity: sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==} - cross-fetch@3.1.8: - resolution: {integrity: sha512-cvA+JwZoU0Xq+h6WkMvAUqPEYy92Obet6UdKLfW60qn99ftItKjB5T+BkyWOFWe2pUyfQ+IJHmpOTznqk1M6Kg==} - cross-spawn@5.1.0: resolution: {integrity: sha512-pTgQJ5KC0d2hcY8eyL1IzlBPYjTkyH72XRZPnLyKus2mBfNjQs3klqbJU2VILqZryAZUt9JOb3h/mWMy23/f5A==} @@ -9939,24 +9927,6 @@ packages: resolution: {integrity: sha512-4ghX8cA/hNycZFPgU+Zgu1xPkVyrvIS2KGWMmH8WX7/U8QLyKa0Drm6FTTngnf+SIYkgPDbh52dN0/o7wCWPRg==} hasBin: true - fetch-mock-jest@1.5.1: - resolution: {integrity: sha512-+utwzP8C+Pax1GSka3nFXILWMY3Er2L+s090FOgqVNrNCPp0fDqgXnAHAJf12PLHi0z4PhcTaZNTz8e7K3fjqQ==} - engines: {node: '>=8.0.0'} - peerDependencies: - node-fetch: '*' - peerDependenciesMeta: - node-fetch: - optional: true - - fetch-mock@9.11.0: - resolution: {integrity: sha512-PG1XUv+x7iag5p/iNHD4/jdpxL9FtVSqRMUQhPab4hVDt80T1MH5ehzVrL2IdXO9Q2iBggArFvPqjUbHFuI58Q==} - engines: {node: '>=4.0.0'} - peerDependencies: - node-fetch: '*' - peerDependenciesMeta: - node-fetch: - optional: true - file-entry-cache@6.0.1: resolution: {integrity: sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==} engines: {node: ^10.12.0 || >=12.0.0} @@ -10575,9 +10545,6 @@ packages: resolution: {integrity: sha512-tE2UXzivje6ofPW7l23cjDOMa09gb7xlAqG6jG5ej6uPV32TlWP3NKPigtaGeHNu9fohccRYvIiZMfOOnOYUtg==} engines: {node: '>= 0.4'} - is-subset@0.1.1: - resolution: {integrity: sha512-6Ybun0IkarhmEqxXCNw/C0bna6Zb/TkfUX9UbwJtK6ObwAVCxmAP308WWTHviM/zAqXk05cdhYsUsZeGQh99iw==} - is-symbol@1.0.4: resolution: {integrity: sha512-C/CPBqKWnvdcxqIARxyOh4v1UUEOCHpgDa0WYgpKDFMszcrPcffg5uhwSgPCLD2WWxmq6isisz87tzT01tuGhg==} engines: {node: '>= 0.4'} @@ -10717,9 +10684,6 @@ packages: resolution: {integrity: sha512-DOSwCRqXirTOyheM+4d5YZOrWcdu0LNZ87ewUoywbcb2XR4wKgqiG8vNeYwhjFMbEkfju7wx2GYH0P2gevGvFw==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} - jest-fetch-mock@3.0.3: - resolution: {integrity: sha512-Ux1nWprtLrdrH4XwE7O7InRY6psIi3GOsqNESJgMJ+M5cv4A8Lh7SN9d2V2kKRZ8ebAfcd1LNyZguAOb6JiDqw==} - jest-get-type@29.6.3: resolution: {integrity: sha512-zrteXnqYxfQh7l5FHyL38jL39di8H8rHoecLH3JNxH3BwOrBsNeabdap5e0I23lD4HHI8W5VFBZqG4Eaq5LNcw==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} @@ -11715,9 +11679,6 @@ packages: path-to-regexp@0.1.10: resolution: {integrity: sha512-7lf7qcQidTku0Gu3YDPc8DJ1q7OOucfa/BSsIwjuh56VU7katFvuM8hULfkwB3Fns/rsVF7PwPKVw1sl5KQS9w==} - path-to-regexp@2.4.0: - resolution: {integrity: sha512-G6zHoVqC6GGTQkZwF4lkuEyMbVOjoBKAEybQUypI1WTkqinCOrq2x6U2+phkJ1XsEMTy4LjtwPI7HW+NVrRR2w==} - path-type@4.0.0: resolution: {integrity: sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==} engines: {node: '>=8'} @@ -11898,9 +11859,6 @@ packages: promise-make-naked@2.1.2: resolution: {integrity: sha512-y7s8ZuHIG56JYspB24be9GFkXA1zXL85Ur9u1DKrW/tvyUoPxWgBjnalK6Nc6l7wHBcAW0c3PO07+XOsWTRuhg==} - promise-polyfill@8.3.0: - resolution: {integrity: sha512-H5oELycFml5yto/atYqmjyigJoAo3+OXwolYiH7OfQuYlAqhxNvTfiNMbV9hsC6Yp83yE5r2KTVmtrG6R9i6Pg==} - prompts@2.4.2: resolution: {integrity: sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q==} engines: {node: '>= 6'} @@ -11950,11 +11908,6 @@ packages: resolution: {integrity: sha512-+38qI9SOr8tfZ4QmJNplMUxqjbe7LKvvZgWdExBOmd+egZTtjLB67Gu0HRX3u/XOq7UU2Nx6nsjvS16Z9uwfpg==} engines: {node: '>=0.6'} - querystring@0.2.1: - resolution: {integrity: sha512-wkvS7mL/JMugcup3/rMitHmd9ecIGd2lhFhK9N3UUQ450h66d1r3Y9nvXzQAW1Lq+wyx61k/1pfKS5KuKiyEbg==} - engines: {node: '>=0.4.x'} - deprecated: The querystring API is considered Legacy. new code should use the URLSearchParams API instead. - querystringify@2.2.0: resolution: {integrity: sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==} @@ -13280,9 +13233,6 @@ packages: whatwg-url@5.0.0: resolution: {integrity: sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==} - whatwg-url@6.5.0: - resolution: {integrity: sha512-rhRZRqx/TLJQWUpQ6bmrt2UV4f0HCQ463yQuONJqC6fO2VoEb1pTYddbe59SkYq87aoM5A3bdhMZiUiVws+fzQ==} - whatwg-url@7.1.0: resolution: {integrity: sha512-WUu7Rg1DroM7oQvGWfOiAK21n74Gg+T4elXEQYkOhtyLeWiJFoOGLXPKI/9gzIie9CtwVLm8wtw6YJdKyxSjeg==} @@ -16652,8 +16602,6 @@ snapshots: dependencies: browserslist: 4.24.0 - core-js@3.38.0: {} - core-util-is@1.0.3: {} cors@2.8.5: @@ -16695,12 +16643,6 @@ snapshots: create-require@1.1.1: {} - cross-fetch@3.1.8: - dependencies: - node-fetch: 2.7.0 - transitivePeerDependencies: - - encoding - cross-spawn@5.1.0: dependencies: lru-cache: 4.1.5 @@ -17559,31 +17501,6 @@ snapshots: fern-api@0.45.0-rc12: {} - fetch-mock-jest@1.5.1(node-fetch@2.7.0): - dependencies: - fetch-mock: 9.11.0(node-fetch@2.7.0) - optionalDependencies: - node-fetch: 2.7.0 - transitivePeerDependencies: - - supports-color - - fetch-mock@9.11.0(node-fetch@2.7.0): - dependencies: - '@babel/core': 7.25.2 - '@babel/runtime': 7.25.0 - core-js: 3.38.0 - debug: 4.3.6 - glob-to-regexp: 0.4.1 - is-subset: 0.1.1 - lodash.isequal: 4.5.0 - path-to-regexp: 2.4.0 - querystring: 0.2.1 - whatwg-url: 6.5.0 - optionalDependencies: - node-fetch: 2.7.0 - transitivePeerDependencies: - - supports-color - file-entry-cache@6.0.1: dependencies: flat-cache: 3.0.4 @@ -18230,8 +18147,6 @@ snapshots: dependencies: has-tostringtag: 1.0.2 - is-subset@0.1.1: {} - is-symbol@1.0.4: dependencies: has-symbols: 1.0.3 @@ -18458,13 +18373,6 @@ snapshots: jest-mock: 29.7.0 jest-util: 29.7.0 - jest-fetch-mock@3.0.3: - dependencies: - cross-fetch: 3.1.8 - promise-polyfill: 8.3.0 - transitivePeerDependencies: - - encoding - jest-get-type@29.6.3: {} jest-haste-map@29.7.0: @@ -19906,8 +19814,6 @@ snapshots: path-to-regexp@0.1.10: {} - path-to-regexp@2.4.0: {} - path-type@4.0.0: {} pathe@1.1.2: {} @@ -20055,8 +19961,6 @@ snapshots: promise-make-naked@2.1.2: {} - promise-polyfill@8.3.0: {} - prompts@2.4.2: dependencies: kleur: 3.0.3 @@ -20103,8 +20007,6 @@ snapshots: dependencies: side-channel: 1.0.6 - querystring@0.2.1: {} - querystringify@2.2.0: {} queue-microtask@1.2.3: {} @@ -21758,12 +21660,6 @@ snapshots: tr46: 0.0.3 webidl-conversions: 3.0.1 - whatwg-url@6.5.0: - dependencies: - lodash.sortby: 4.7.0 - tr46: 1.0.1 - webidl-conversions: 4.0.2 - whatwg-url@7.1.0: dependencies: lodash.sortby: 4.7.0 diff --git a/seed/ts-sdk/alias-extends/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/alias-extends/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/alias-extends/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/alias-extends/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/alias-extends/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/alias-extends/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/alias-extends/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/alias-extends/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/alias-extends/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/alias-extends/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/alias-extends/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/alias-extends/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/alias-extends/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/alias-extends/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/alias-extends/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/alias-extends/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/alias-extends/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/alias-extends/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/alias-extends/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/alias-extends/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/alias/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/alias/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/alias/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/alias/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/alias/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/alias/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/alias/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/alias/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/alias/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/alias/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/alias/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/alias/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/alias/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/alias/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/alias/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/alias/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/alias/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/alias/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/alias/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/alias/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/any-auth/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/any-auth/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/any-auth/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/any-auth/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/any-auth/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/any-auth/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/any-auth/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/any-auth/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/any-auth/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/any-auth/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/any-auth/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/any-auth/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/any-auth/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/any-auth/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/any-auth/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/any-auth/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/any-auth/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/any-auth/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/any-auth/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/any-auth/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/api-wide-base-path/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/api-wide-base-path/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/api-wide-base-path/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/api-wide-base-path/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/api-wide-base-path/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/api-wide-base-path/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/api-wide-base-path/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/api-wide-base-path/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/api-wide-base-path/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/api-wide-base-path/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/api-wide-base-path/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/api-wide-base-path/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/api-wide-base-path/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/api-wide-base-path/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/api-wide-base-path/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/api-wide-base-path/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/api-wide-base-path/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/api-wide-base-path/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/api-wide-base-path/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/api-wide-base-path/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/audiences/no-custom-config/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/audiences/no-custom-config/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/audiences/no-custom-config/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/audiences/no-custom-config/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/audiences/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/audiences/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/audiences/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/audiences/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/audiences/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/audiences/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/audiences/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/audiences/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/audiences/no-custom-config/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/audiences/no-custom-config/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/audiences/no-custom-config/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/audiences/no-custom-config/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/audiences/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/audiences/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/audiences/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/audiences/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/audiences/with-partner-audience/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/audiences/with-partner-audience/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/audiences/with-partner-audience/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/audiences/with-partner-audience/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/audiences/with-partner-audience/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/audiences/with-partner-audience/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/audiences/with-partner-audience/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/audiences/with-partner-audience/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/audiences/with-partner-audience/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/audiences/with-partner-audience/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/audiences/with-partner-audience/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/audiences/with-partner-audience/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/audiences/with-partner-audience/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/audiences/with-partner-audience/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/audiences/with-partner-audience/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/audiences/with-partner-audience/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/audiences/with-partner-audience/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/audiences/with-partner-audience/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/audiences/with-partner-audience/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/audiences/with-partner-audience/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/auth-environment-variables/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/auth-environment-variables/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/auth-environment-variables/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/auth-environment-variables/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/auth-environment-variables/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/auth-environment-variables/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/auth-environment-variables/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/auth-environment-variables/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/auth-environment-variables/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/auth-environment-variables/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/auth-environment-variables/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/auth-environment-variables/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/auth-environment-variables/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/auth-environment-variables/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/auth-environment-variables/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/auth-environment-variables/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/auth-environment-variables/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/auth-environment-variables/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/auth-environment-variables/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/auth-environment-variables/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/basic-auth-environment-variables/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/basic-auth-environment-variables/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/basic-auth-environment-variables/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/basic-auth-environment-variables/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/basic-auth-environment-variables/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/basic-auth-environment-variables/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/basic-auth-environment-variables/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/basic-auth-environment-variables/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/basic-auth-environment-variables/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/basic-auth-environment-variables/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/basic-auth-environment-variables/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/basic-auth-environment-variables/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/basic-auth-environment-variables/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/basic-auth-environment-variables/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/basic-auth-environment-variables/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/basic-auth-environment-variables/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/basic-auth-environment-variables/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/basic-auth-environment-variables/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/basic-auth-environment-variables/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/basic-auth-environment-variables/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/basic-auth/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/basic-auth/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/basic-auth/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/basic-auth/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/basic-auth/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/basic-auth/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/basic-auth/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/basic-auth/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/basic-auth/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/basic-auth/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/basic-auth/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/basic-auth/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/basic-auth/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/basic-auth/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/basic-auth/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/basic-auth/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/basic-auth/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/basic-auth/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/basic-auth/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/basic-auth/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/bearer-token-environment-variable/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/bearer-token-environment-variable/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/bearer-token-environment-variable/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/bearer-token-environment-variable/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/bearer-token-environment-variable/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/bearer-token-environment-variable/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/bearer-token-environment-variable/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/bearer-token-environment-variable/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/bearer-token-environment-variable/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/bearer-token-environment-variable/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/bearer-token-environment-variable/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/bearer-token-environment-variable/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/bearer-token-environment-variable/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/bearer-token-environment-variable/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/bearer-token-environment-variable/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/bearer-token-environment-variable/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/bearer-token-environment-variable/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/bearer-token-environment-variable/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/bearer-token-environment-variable/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/bearer-token-environment-variable/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/bytes/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/bytes/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/bytes/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/bytes/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/bytes/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/bytes/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/bytes/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/bytes/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/bytes/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/bytes/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/bytes/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/bytes/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/bytes/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/bytes/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/bytes/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/bytes/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/bytes/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/bytes/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/bytes/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/bytes/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/code-samples/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/code-samples/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/code-samples/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/code-samples/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/code-samples/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/code-samples/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/code-samples/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/code-samples/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/code-samples/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/code-samples/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/code-samples/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/code-samples/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/code-samples/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/code-samples/tests/unit/fetcher/requestWithRetries.test.ts index b53e04367c5..63ba20686db 100644 --- a/seed/ts-sdk/code-samples/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/code-samples/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test exponential backoff", () => { let mockFetch: jest.Mock; let originalSetTimeout: typeof setTimeout; diff --git a/seed/ts-sdk/cross-package-type-names/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/cross-package-type-names/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/cross-package-type-names/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/cross-package-type-names/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/cross-package-type-names/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/cross-package-type-names/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/cross-package-type-names/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/cross-package-type-names/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/cross-package-type-names/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/cross-package-type-names/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/cross-package-type-names/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/cross-package-type-names/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/cross-package-type-names/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/cross-package-type-names/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/cross-package-type-names/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/cross-package-type-names/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/cross-package-type-names/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/cross-package-type-names/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/cross-package-type-names/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/cross-package-type-names/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/custom-auth/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/custom-auth/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/custom-auth/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/custom-auth/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/custom-auth/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/custom-auth/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/custom-auth/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/custom-auth/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/custom-auth/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/custom-auth/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/custom-auth/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/custom-auth/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/custom-auth/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/custom-auth/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/custom-auth/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/custom-auth/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/custom-auth/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/custom-auth/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/custom-auth/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/custom-auth/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/enum/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/enum/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/enum/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/enum/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/enum/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/enum/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/enum/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/enum/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/enum/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/enum/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/enum/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/enum/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/enum/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/enum/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/enum/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/enum/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/enum/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/enum/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/enum/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/enum/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/error-property/union-utils/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/error-property/union-utils/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/error-property/union-utils/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/error-property/union-utils/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/error-property/union-utils/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/error-property/union-utils/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/error-property/union-utils/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/error-property/union-utils/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/error-property/union-utils/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/error-property/union-utils/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/error-property/union-utils/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/error-property/union-utils/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/error-property/union-utils/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/error-property/union-utils/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/error-property/union-utils/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/error-property/union-utils/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/error-property/union-utils/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/error-property/union-utils/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/error-property/union-utils/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/error-property/union-utils/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/examples/examples-with-api-reference/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/examples/examples-with-api-reference/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/examples/examples-with-api-reference/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/examples/examples-with-api-reference/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/examples/examples-with-api-reference/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/examples/examples-with-api-reference/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/examples/examples-with-api-reference/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/examples/examples-with-api-reference/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/examples/examples-with-api-reference/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/examples/examples-with-api-reference/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/examples/examples-with-api-reference/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/examples/examples-with-api-reference/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/examples/examples-with-api-reference/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/examples/examples-with-api-reference/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/examples/examples-with-api-reference/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/examples/examples-with-api-reference/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/examples/examples-with-api-reference/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/examples/examples-with-api-reference/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/examples/examples-with-api-reference/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/examples/examples-with-api-reference/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/examples/retain-original-casing/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/examples/retain-original-casing/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/examples/retain-original-casing/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/examples/retain-original-casing/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/examples/retain-original-casing/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/examples/retain-original-casing/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/examples/retain-original-casing/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/examples/retain-original-casing/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/examples/retain-original-casing/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/examples/retain-original-casing/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/examples/retain-original-casing/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/examples/retain-original-casing/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/examples/retain-original-casing/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/examples/retain-original-casing/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/examples/retain-original-casing/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/examples/retain-original-casing/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/examples/retain-original-casing/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/examples/retain-original-casing/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/examples/retain-original-casing/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/examples/retain-original-casing/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/exhaustive/allow-extra-fields/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/exhaustive/allow-extra-fields/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/exhaustive/allow-extra-fields/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/exhaustive/allow-extra-fields/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/exhaustive/allow-extra-fields/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/exhaustive/allow-extra-fields/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/exhaustive/allow-extra-fields/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/exhaustive/allow-extra-fields/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/exhaustive/allow-extra-fields/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/exhaustive/allow-extra-fields/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/exhaustive/allow-extra-fields/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/exhaustive/allow-extra-fields/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/exhaustive/allow-extra-fields/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/exhaustive/allow-extra-fields/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/exhaustive/allow-extra-fields/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/exhaustive/allow-extra-fields/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/exhaustive/allow-extra-fields/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/exhaustive/allow-extra-fields/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/exhaustive/allow-extra-fields/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/exhaustive/allow-extra-fields/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/exhaustive/bigint/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/exhaustive/bigint/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/exhaustive/bigint/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/exhaustive/bigint/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/exhaustive/bigint/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/exhaustive/bigint/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/exhaustive/bigint/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/exhaustive/bigint/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/exhaustive/bigint/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/exhaustive/bigint/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/exhaustive/bigint/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/exhaustive/bigint/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/exhaustive/bigint/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/exhaustive/bigint/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/exhaustive/bigint/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/exhaustive/bigint/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/exhaustive/bigint/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/exhaustive/bigint/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/exhaustive/bigint/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/exhaustive/bigint/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/exhaustive/bundle/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/exhaustive/bundle/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/exhaustive/bundle/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/exhaustive/bundle/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/exhaustive/bundle/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/exhaustive/bundle/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/exhaustive/bundle/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/exhaustive/bundle/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/exhaustive/bundle/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/exhaustive/bundle/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/exhaustive/bundle/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/exhaustive/bundle/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/exhaustive/bundle/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/exhaustive/bundle/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/exhaustive/bundle/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/exhaustive/bundle/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/exhaustive/bundle/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/exhaustive/bundle/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/exhaustive/bundle/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/exhaustive/bundle/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/exhaustive/custom-package-json/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/exhaustive/custom-package-json/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/exhaustive/custom-package-json/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/exhaustive/custom-package-json/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/exhaustive/custom-package-json/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/exhaustive/custom-package-json/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/exhaustive/custom-package-json/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/exhaustive/custom-package-json/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/exhaustive/custom-package-json/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/exhaustive/custom-package-json/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/exhaustive/custom-package-json/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/exhaustive/custom-package-json/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/exhaustive/custom-package-json/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/exhaustive/custom-package-json/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/exhaustive/custom-package-json/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/exhaustive/custom-package-json/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/exhaustive/custom-package-json/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/exhaustive/custom-package-json/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/exhaustive/custom-package-json/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/exhaustive/custom-package-json/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/exhaustive/dev-dependencies/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/exhaustive/dev-dependencies/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/exhaustive/dev-dependencies/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/exhaustive/dev-dependencies/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/exhaustive/dev-dependencies/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/exhaustive/dev-dependencies/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/exhaustive/dev-dependencies/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/exhaustive/dev-dependencies/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/exhaustive/dev-dependencies/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/exhaustive/dev-dependencies/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/exhaustive/dev-dependencies/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/exhaustive/dev-dependencies/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/exhaustive/dev-dependencies/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/exhaustive/dev-dependencies/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/exhaustive/dev-dependencies/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/exhaustive/dev-dependencies/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/exhaustive/dev-dependencies/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/exhaustive/dev-dependencies/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/exhaustive/dev-dependencies/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/exhaustive/dev-dependencies/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/exhaustive/jsr/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/exhaustive/jsr/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/exhaustive/jsr/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/exhaustive/jsr/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/exhaustive/jsr/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/exhaustive/jsr/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/exhaustive/jsr/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/exhaustive/jsr/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/exhaustive/jsr/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/exhaustive/jsr/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/exhaustive/jsr/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/exhaustive/jsr/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/exhaustive/jsr/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/exhaustive/jsr/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/exhaustive/jsr/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/exhaustive/jsr/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/exhaustive/jsr/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/exhaustive/jsr/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/exhaustive/jsr/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/exhaustive/jsr/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/exhaustive/no-custom-config/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/exhaustive/no-custom-config/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/exhaustive/no-custom-config/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/exhaustive/no-custom-config/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/exhaustive/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/exhaustive/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/exhaustive/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/exhaustive/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/exhaustive/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/exhaustive/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/exhaustive/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/exhaustive/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/exhaustive/no-custom-config/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/exhaustive/no-custom-config/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/exhaustive/no-custom-config/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/exhaustive/no-custom-config/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/exhaustive/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/exhaustive/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/exhaustive/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/exhaustive/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/exhaustive/retain-original-casing/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/exhaustive/retain-original-casing/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/exhaustive/retain-original-casing/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/exhaustive/retain-original-casing/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/exhaustive/retain-original-casing/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/exhaustive/retain-original-casing/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/exhaustive/retain-original-casing/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/exhaustive/retain-original-casing/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/exhaustive/retain-original-casing/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/exhaustive/retain-original-casing/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/exhaustive/retain-original-casing/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/exhaustive/retain-original-casing/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/exhaustive/retain-original-casing/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/exhaustive/retain-original-casing/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/exhaustive/retain-original-casing/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/exhaustive/retain-original-casing/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/exhaustive/retain-original-casing/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/exhaustive/retain-original-casing/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/exhaustive/retain-original-casing/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/exhaustive/retain-original-casing/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/extends/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/extends/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/extends/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/extends/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/extends/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/extends/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/extends/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/extends/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/extends/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/extends/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/extends/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/extends/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/extends/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/extends/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/extends/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/extends/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/extends/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/extends/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/extends/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/extends/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/extra-properties/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/extra-properties/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/extra-properties/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/extra-properties/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/extra-properties/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/extra-properties/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/extra-properties/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/extra-properties/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/extra-properties/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/extra-properties/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/extra-properties/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/extra-properties/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/extra-properties/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/extra-properties/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/extra-properties/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/extra-properties/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/extra-properties/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/extra-properties/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/extra-properties/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/extra-properties/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/failing-audiences/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/failing-audiences/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/failing-audiences/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/failing-audiences/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/failing-audiences/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/failing-audiences/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/failing-audiences/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/failing-audiences/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/failing-audiences/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/failing-audiences/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/failing-audiences/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/failing-audiences/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/failing-audiences/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/failing-audiences/tests/unit/fetcher/requestWithRetries.test.ts index b53e04367c5..63ba20686db 100644 --- a/seed/ts-sdk/failing-audiences/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/failing-audiences/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test exponential backoff", () => { let mockFetch: jest.Mock; let originalSetTimeout: typeof setTimeout; diff --git a/seed/ts-sdk/file-download/file-download-reponse-headers/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/file-download/file-download-reponse-headers/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/file-download/file-download-reponse-headers/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/file-download/file-download-reponse-headers/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/file-download/file-download-reponse-headers/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/file-download/file-download-reponse-headers/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/file-download/file-download-reponse-headers/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/file-download/file-download-reponse-headers/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/file-download/file-download-reponse-headers/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/file-download/file-download-reponse-headers/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/file-download/file-download-reponse-headers/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/file-download/file-download-reponse-headers/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/file-download/file-download-reponse-headers/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/file-download/file-download-reponse-headers/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/file-download/file-download-reponse-headers/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/file-download/file-download-reponse-headers/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/file-download/file-download-reponse-headers/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/file-download/file-download-reponse-headers/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/file-download/file-download-reponse-headers/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/file-download/file-download-reponse-headers/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/file-download/no-custom-config/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/file-download/no-custom-config/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/file-download/no-custom-config/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/file-download/no-custom-config/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/file-download/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/file-download/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/file-download/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/file-download/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/file-download/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/file-download/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/file-download/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/file-download/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/file-download/no-custom-config/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/file-download/no-custom-config/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/file-download/no-custom-config/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/file-download/no-custom-config/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/file-download/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/file-download/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/file-download/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/file-download/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/file-upload/no-custom-config/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/file-upload/no-custom-config/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/file-upload/no-custom-config/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/file-upload/no-custom-config/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/file-upload/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/file-upload/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/file-upload/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/file-upload/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/file-upload/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/file-upload/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/file-upload/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/file-upload/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/file-upload/no-custom-config/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/file-upload/no-custom-config/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/file-upload/no-custom-config/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/file-upload/no-custom-config/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/file-upload/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/file-upload/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/file-upload/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/file-upload/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/file-upload/wrap-file-properties/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/file-upload/wrap-file-properties/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/file-upload/wrap-file-properties/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/file-upload/wrap-file-properties/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/file-upload/wrap-file-properties/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/file-upload/wrap-file-properties/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/file-upload/wrap-file-properties/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/file-upload/wrap-file-properties/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/file-upload/wrap-file-properties/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/file-upload/wrap-file-properties/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/file-upload/wrap-file-properties/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/file-upload/wrap-file-properties/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/file-upload/wrap-file-properties/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/file-upload/wrap-file-properties/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/file-upload/wrap-file-properties/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/file-upload/wrap-file-properties/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/file-upload/wrap-file-properties/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/file-upload/wrap-file-properties/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/file-upload/wrap-file-properties/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/file-upload/wrap-file-properties/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/folders/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/folders/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/folders/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/folders/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/folders/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/folders/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/folders/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/folders/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/folders/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/folders/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/folders/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/folders/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/folders/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/folders/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/folders/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/folders/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/folders/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/folders/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/folders/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/folders/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/grpc-proto-exhaustive/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/grpc-proto-exhaustive/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/grpc-proto-exhaustive/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/grpc-proto-exhaustive/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/grpc-proto-exhaustive/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/grpc-proto-exhaustive/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/grpc-proto-exhaustive/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/grpc-proto-exhaustive/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/grpc-proto-exhaustive/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/grpc-proto-exhaustive/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/grpc-proto-exhaustive/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/grpc-proto-exhaustive/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/grpc-proto-exhaustive/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/grpc-proto-exhaustive/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/grpc-proto-exhaustive/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/grpc-proto-exhaustive/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/grpc-proto-exhaustive/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/grpc-proto-exhaustive/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/grpc-proto-exhaustive/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/grpc-proto-exhaustive/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/grpc-proto/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/grpc-proto/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/grpc-proto/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/grpc-proto/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/grpc-proto/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/grpc-proto/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/grpc-proto/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/grpc-proto/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/grpc-proto/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/grpc-proto/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/grpc-proto/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/grpc-proto/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/grpc-proto/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/grpc-proto/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/grpc-proto/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/grpc-proto/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/grpc-proto/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/grpc-proto/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/grpc-proto/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/grpc-proto/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/grpc/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/grpc/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/grpc/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/grpc/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/grpc/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/grpc/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/grpc/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/grpc/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/grpc/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/grpc/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/grpc/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/grpc/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/grpc/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/grpc/tests/unit/fetcher/requestWithRetries.test.ts index b53e04367c5..63ba20686db 100644 --- a/seed/ts-sdk/grpc/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/grpc/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test exponential backoff", () => { let mockFetch: jest.Mock; let originalSetTimeout: typeof setTimeout; diff --git a/seed/ts-sdk/idempotency-headers/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/idempotency-headers/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/idempotency-headers/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/idempotency-headers/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/idempotency-headers/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/idempotency-headers/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/idempotency-headers/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/idempotency-headers/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/idempotency-headers/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/idempotency-headers/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/idempotency-headers/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/idempotency-headers/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/idempotency-headers/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/idempotency-headers/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/idempotency-headers/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/idempotency-headers/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/idempotency-headers/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/idempotency-headers/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/idempotency-headers/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/idempotency-headers/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/imdb/no-custom-config/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/imdb/no-custom-config/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/imdb/no-custom-config/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/imdb/no-custom-config/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/imdb/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/imdb/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/imdb/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/imdb/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/imdb/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/imdb/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/imdb/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/imdb/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/imdb/no-custom-config/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/imdb/no-custom-config/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/imdb/no-custom-config/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/imdb/no-custom-config/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/imdb/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/imdb/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/imdb/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/imdb/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/imdb/noScripts/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/imdb/noScripts/tests/unit/fetcher/Fetcher.test.ts index a80d0581fa9..e4b64cca4b3 100644 --- a/seed/ts-sdk/imdb/noScripts/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/imdb/noScripts/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json" }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }) + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }) }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }) + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")) }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }) + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }) }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read() - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream) + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/imdb/noScripts/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/imdb/noScripts/tests/unit/fetcher/getRequestBody.test.ts index b669cbcb71a..919604c2e12 100644 --- a/seed/ts-sdk/imdb/noScripts/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/imdb/noScripts/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { @@ -12,7 +8,7 @@ describe("Test getRequestBody", () => { formData.append("key", "value"); const result = await getRequestBody({ body: formData, - type: "file" + type: "file", }); expect(result).toBe(formData); } @@ -23,7 +19,7 @@ describe("Test getRequestBody", () => { const body = { key: "value" }; const result = await getRequestBody({ body, - type: "json" + type: "json", }); expect(result).toBe('{"key":"value"}'); } @@ -35,7 +31,7 @@ describe("Test getRequestBody", () => { formData.append("key", "value"); const result = await getRequestBody({ body: formData, - type: "file" + type: "file", }); expect(result).toBe(formData); } @@ -46,7 +42,7 @@ describe("Test getRequestBody", () => { const body = { key: "value" }; const result = await getRequestBody({ body, - type: "json" + type: "json", }); expect(result).toBe('{"key":"value"}'); } @@ -56,7 +52,7 @@ describe("Test getRequestBody", () => { const input = new Uint8Array([1, 2, 3]); const result = await getRequestBody({ body: input, - type: "bytes" + type: "bytes", }); expect(result).toBe(input); }); @@ -65,7 +61,7 @@ describe("Test getRequestBody", () => { const input = "key=value&another=param"; const result = await getRequestBody({ body: input, - type: "other" + type: "other", }); expect(result).toBe(input); }); @@ -74,7 +70,7 @@ describe("Test getRequestBody", () => { const input = { key: "value" }; const result = await getRequestBody({ body: input, - type: "json" + type: "json", }); expect(result).toBe('{"key":"value"}'); }); diff --git a/seed/ts-sdk/imdb/noScripts/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/imdb/noScripts/tests/unit/fetcher/getResponseBody.test.ts index 76b9df0f641..1030c517ced 100644 --- a/seed/ts-sdk/imdb/noScripts/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/imdb/noScripts/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); @@ -61,8 +57,8 @@ describe("Test getResponseBody", () => { error: { reason: "non-json", statusCode: 200, - rawBody: "invalid json" - } + rawBody: "invalid json", + }, }); }); }); diff --git a/seed/ts-sdk/imdb/noScripts/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/imdb/noScripts/tests/unit/fetcher/makeRequest.test.ts index af0554e6ef5..be94ab45f10 100644 --- a/seed/ts-sdk/imdb/noScripts/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/imdb/noScripts/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; @@ -30,7 +26,7 @@ describe("Test makeRequest", () => { method: "POST", headers: mockHeaders, body: mockBody, - credentials: undefined + credentials: undefined, }) ); expect(calledOptions.signal).toBeDefined(); @@ -49,7 +45,7 @@ describe("Test makeRequest", () => { method: "GET", headers: mockHeaders, body: undefined, - credentials: undefined + credentials: undefined, }) ); expect(calledOptions.signal).toBeDefined(); diff --git a/seed/ts-sdk/imdb/noScripts/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/imdb/noScripts/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/imdb/noScripts/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/imdb/noScripts/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/imdb/omit-undefined/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/imdb/omit-undefined/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/imdb/omit-undefined/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/imdb/omit-undefined/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/imdb/omit-undefined/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/imdb/omit-undefined/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/imdb/omit-undefined/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/imdb/omit-undefined/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/imdb/omit-undefined/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/imdb/omit-undefined/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/imdb/omit-undefined/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/imdb/omit-undefined/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/imdb/omit-undefined/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/imdb/omit-undefined/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/imdb/omit-undefined/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/imdb/omit-undefined/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/imdb/omit-undefined/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/imdb/omit-undefined/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/imdb/omit-undefined/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/imdb/omit-undefined/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/literal/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/literal/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/literal/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/literal/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/literal/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/literal/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/literal/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/literal/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/literal/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/literal/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/literal/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/literal/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/literal/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/literal/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/literal/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/literal/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/literal/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/literal/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/literal/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/literal/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/mixed-case/no-custom-config/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/mixed-case/no-custom-config/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/mixed-case/no-custom-config/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/mixed-case/no-custom-config/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/mixed-case/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/mixed-case/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/mixed-case/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/mixed-case/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/mixed-case/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/mixed-case/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/mixed-case/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/mixed-case/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/mixed-case/no-custom-config/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/mixed-case/no-custom-config/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/mixed-case/no-custom-config/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/mixed-case/no-custom-config/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/mixed-case/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/mixed-case/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/mixed-case/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/mixed-case/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/mixed-case/retain-original-casing/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/mixed-case/retain-original-casing/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/mixed-case/retain-original-casing/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/mixed-case/retain-original-casing/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/mixed-case/retain-original-casing/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/mixed-case/retain-original-casing/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/mixed-case/retain-original-casing/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/mixed-case/retain-original-casing/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/mixed-case/retain-original-casing/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/mixed-case/retain-original-casing/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/mixed-case/retain-original-casing/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/mixed-case/retain-original-casing/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/mixed-case/retain-original-casing/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/mixed-case/retain-original-casing/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/mixed-case/retain-original-casing/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/mixed-case/retain-original-casing/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/mixed-case/retain-original-casing/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/mixed-case/retain-original-casing/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/mixed-case/retain-original-casing/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/mixed-case/retain-original-casing/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/mixed-file-directory/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/mixed-file-directory/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/mixed-file-directory/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/mixed-file-directory/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/mixed-file-directory/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/mixed-file-directory/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/mixed-file-directory/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/mixed-file-directory/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/mixed-file-directory/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/mixed-file-directory/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/mixed-file-directory/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/mixed-file-directory/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/mixed-file-directory/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/mixed-file-directory/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/mixed-file-directory/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/mixed-file-directory/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/mixed-file-directory/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/mixed-file-directory/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/mixed-file-directory/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/mixed-file-directory/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/multi-line-docs/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/multi-line-docs/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/multi-line-docs/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/multi-line-docs/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/multi-line-docs/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/multi-line-docs/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/multi-line-docs/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/multi-line-docs/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/multi-line-docs/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/multi-line-docs/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/multi-line-docs/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/multi-line-docs/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/multi-line-docs/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/multi-line-docs/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/multi-line-docs/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/multi-line-docs/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/multi-line-docs/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/multi-line-docs/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/multi-line-docs/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/multi-line-docs/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/multi-url-environment-no-default/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/multi-url-environment-no-default/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/multi-url-environment-no-default/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/multi-url-environment-no-default/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/multi-url-environment-no-default/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/multi-url-environment-no-default/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/multi-url-environment-no-default/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/multi-url-environment-no-default/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/multi-url-environment-no-default/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/multi-url-environment-no-default/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/multi-url-environment-no-default/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/multi-url-environment-no-default/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/multi-url-environment-no-default/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/multi-url-environment-no-default/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/multi-url-environment-no-default/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/multi-url-environment-no-default/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/multi-url-environment-no-default/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/multi-url-environment-no-default/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/multi-url-environment-no-default/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/multi-url-environment-no-default/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/multi-url-environment/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/multi-url-environment/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/multi-url-environment/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/multi-url-environment/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/multi-url-environment/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/multi-url-environment/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/multi-url-environment/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/multi-url-environment/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/multi-url-environment/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/multi-url-environment/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/multi-url-environment/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/multi-url-environment/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/multi-url-environment/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/multi-url-environment/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/multi-url-environment/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/multi-url-environment/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/multi-url-environment/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/multi-url-environment/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/multi-url-environment/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/multi-url-environment/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/no-environment/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/no-environment/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/no-environment/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/no-environment/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/no-environment/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/no-environment/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/no-environment/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/no-environment/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/no-environment/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/no-environment/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/no-environment/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/no-environment/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/no-environment/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/no-environment/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/no-environment/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/no-environment/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/no-environment/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/no-environment/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/no-environment/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/no-environment/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/oauth-client-credentials-default/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/oauth-client-credentials-default/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/oauth-client-credentials-default/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/oauth-client-credentials-default/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/oauth-client-credentials-default/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/oauth-client-credentials-default/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/oauth-client-credentials-default/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/oauth-client-credentials-default/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/oauth-client-credentials-default/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/oauth-client-credentials-default/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/oauth-client-credentials-default/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/oauth-client-credentials-default/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/oauth-client-credentials-default/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/oauth-client-credentials-default/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/oauth-client-credentials-default/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/oauth-client-credentials-default/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/oauth-client-credentials-default/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/oauth-client-credentials-default/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/oauth-client-credentials-default/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/oauth-client-credentials-default/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/oauth-client-credentials-environment-variables/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/oauth-client-credentials-environment-variables/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/oauth-client-credentials-environment-variables/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/oauth-client-credentials-environment-variables/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/oauth-client-credentials-environment-variables/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/oauth-client-credentials-environment-variables/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/oauth-client-credentials-environment-variables/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/oauth-client-credentials-environment-variables/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/oauth-client-credentials-environment-variables/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/oauth-client-credentials-environment-variables/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/oauth-client-credentials-environment-variables/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/oauth-client-credentials-environment-variables/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/oauth-client-credentials-environment-variables/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/oauth-client-credentials-environment-variables/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/oauth-client-credentials-environment-variables/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/oauth-client-credentials-environment-variables/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/oauth-client-credentials-environment-variables/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/oauth-client-credentials-environment-variables/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/oauth-client-credentials-environment-variables/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/oauth-client-credentials-environment-variables/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/oauth-client-credentials-nested-root/never-throw-errors/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/oauth-client-credentials-nested-root/never-throw-errors/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/oauth-client-credentials-nested-root/never-throw-errors/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/oauth-client-credentials-nested-root/never-throw-errors/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/oauth-client-credentials-nested-root/never-throw-errors/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/oauth-client-credentials-nested-root/never-throw-errors/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/oauth-client-credentials-nested-root/never-throw-errors/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/oauth-client-credentials-nested-root/never-throw-errors/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/oauth-client-credentials-nested-root/never-throw-errors/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/oauth-client-credentials-nested-root/never-throw-errors/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/oauth-client-credentials-nested-root/never-throw-errors/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/oauth-client-credentials-nested-root/never-throw-errors/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/oauth-client-credentials-nested-root/never-throw-errors/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/oauth-client-credentials-nested-root/never-throw-errors/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/oauth-client-credentials-nested-root/never-throw-errors/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/oauth-client-credentials-nested-root/never-throw-errors/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/oauth-client-credentials-nested-root/never-throw-errors/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/oauth-client-credentials-nested-root/never-throw-errors/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/oauth-client-credentials-nested-root/never-throw-errors/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/oauth-client-credentials-nested-root/never-throw-errors/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/oauth-client-credentials-nested-root/no-custom-config/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/oauth-client-credentials-nested-root/no-custom-config/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/oauth-client-credentials-nested-root/no-custom-config/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/oauth-client-credentials-nested-root/no-custom-config/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/oauth-client-credentials-nested-root/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/oauth-client-credentials-nested-root/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/oauth-client-credentials-nested-root/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/oauth-client-credentials-nested-root/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/oauth-client-credentials-nested-root/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/oauth-client-credentials-nested-root/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/oauth-client-credentials-nested-root/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/oauth-client-credentials-nested-root/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/oauth-client-credentials-nested-root/no-custom-config/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/oauth-client-credentials-nested-root/no-custom-config/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/oauth-client-credentials-nested-root/no-custom-config/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/oauth-client-credentials-nested-root/no-custom-config/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/oauth-client-credentials-nested-root/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/oauth-client-credentials-nested-root/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/oauth-client-credentials-nested-root/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/oauth-client-credentials-nested-root/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/oauth-client-credentials/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/oauth-client-credentials/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/oauth-client-credentials/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/oauth-client-credentials/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/oauth-client-credentials/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/oauth-client-credentials/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/oauth-client-credentials/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/oauth-client-credentials/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/oauth-client-credentials/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/oauth-client-credentials/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/oauth-client-credentials/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/oauth-client-credentials/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/oauth-client-credentials/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/oauth-client-credentials/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/oauth-client-credentials/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/oauth-client-credentials/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/oauth-client-credentials/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/oauth-client-credentials/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/oauth-client-credentials/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/oauth-client-credentials/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/optional/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/optional/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/optional/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/optional/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/optional/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/optional/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/optional/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/optional/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/optional/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/optional/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/optional/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/optional/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/optional/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/optional/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/optional/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/optional/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/optional/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/optional/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/optional/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/optional/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/package-yml/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/package-yml/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/package-yml/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/package-yml/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/package-yml/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/package-yml/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/package-yml/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/package-yml/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/package-yml/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/package-yml/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/package-yml/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/package-yml/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/package-yml/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/package-yml/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/package-yml/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/package-yml/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/package-yml/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/package-yml/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/package-yml/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/package-yml/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/pagination/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/pagination/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/pagination/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/pagination/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/pagination/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/pagination/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/pagination/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/pagination/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/pagination/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/pagination/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/pagination/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/pagination/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/pagination/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/pagination/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/pagination/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/pagination/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/pagination/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/pagination/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/pagination/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/pagination/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/plain-text/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/plain-text/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/plain-text/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/plain-text/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/plain-text/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/plain-text/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/plain-text/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/plain-text/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/plain-text/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/plain-text/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/plain-text/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/plain-text/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/plain-text/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/plain-text/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/plain-text/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/plain-text/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/plain-text/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/plain-text/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/plain-text/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/plain-text/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/query-parameters/no-custom-config/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/query-parameters/no-custom-config/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/query-parameters/no-custom-config/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/query-parameters/no-custom-config/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/query-parameters/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/query-parameters/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/query-parameters/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/query-parameters/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/query-parameters/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/query-parameters/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/query-parameters/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/query-parameters/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/query-parameters/no-custom-config/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/query-parameters/no-custom-config/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/query-parameters/no-custom-config/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/query-parameters/no-custom-config/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/query-parameters/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/query-parameters/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/query-parameters/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/query-parameters/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/query-parameters/no-serde-layer-query/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/query-parameters/no-serde-layer-query/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/query-parameters/no-serde-layer-query/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/query-parameters/no-serde-layer-query/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/query-parameters/no-serde-layer-query/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/query-parameters/no-serde-layer-query/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/query-parameters/no-serde-layer-query/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/query-parameters/no-serde-layer-query/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/query-parameters/no-serde-layer-query/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/query-parameters/no-serde-layer-query/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/query-parameters/no-serde-layer-query/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/query-parameters/no-serde-layer-query/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/query-parameters/no-serde-layer-query/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/query-parameters/no-serde-layer-query/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/query-parameters/no-serde-layer-query/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/query-parameters/no-serde-layer-query/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/query-parameters/no-serde-layer-query/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/query-parameters/no-serde-layer-query/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/query-parameters/no-serde-layer-query/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/query-parameters/no-serde-layer-query/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/reserved-keywords/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/reserved-keywords/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/reserved-keywords/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/reserved-keywords/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/reserved-keywords/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/reserved-keywords/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/reserved-keywords/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/reserved-keywords/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/reserved-keywords/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/reserved-keywords/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/reserved-keywords/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/reserved-keywords/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/reserved-keywords/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/reserved-keywords/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/reserved-keywords/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/reserved-keywords/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/reserved-keywords/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/reserved-keywords/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/reserved-keywords/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/reserved-keywords/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/response-property/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/response-property/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/response-property/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/response-property/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/response-property/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/response-property/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/response-property/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/response-property/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/response-property/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/response-property/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/response-property/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/response-property/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/response-property/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/response-property/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/response-property/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/response-property/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/response-property/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/response-property/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/response-property/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/response-property/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/server-sent-event-examples/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/server-sent-event-examples/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/server-sent-event-examples/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/server-sent-event-examples/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/server-sent-event-examples/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/server-sent-event-examples/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/server-sent-event-examples/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/server-sent-event-examples/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/server-sent-event-examples/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/server-sent-event-examples/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/server-sent-event-examples/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/server-sent-event-examples/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/server-sent-event-examples/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/server-sent-event-examples/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/server-sent-event-examples/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/server-sent-event-examples/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/server-sent-event-examples/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/server-sent-event-examples/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/server-sent-event-examples/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/server-sent-event-examples/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/server-sent-events/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/server-sent-events/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/server-sent-events/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/server-sent-events/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/server-sent-events/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/server-sent-events/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/server-sent-events/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/server-sent-events/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/server-sent-events/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/server-sent-events/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/server-sent-events/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/server-sent-events/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/server-sent-events/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/server-sent-events/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/server-sent-events/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/server-sent-events/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/server-sent-events/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/server-sent-events/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/server-sent-events/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/server-sent-events/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/simple-fhir/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/simple-fhir/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/simple-fhir/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/simple-fhir/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/simple-fhir/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/simple-fhir/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/simple-fhir/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/simple-fhir/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/simple-fhir/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/simple-fhir/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/simple-fhir/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/simple-fhir/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/simple-fhir/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/simple-fhir/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/simple-fhir/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/simple-fhir/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/simple-fhir/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/simple-fhir/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/simple-fhir/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/simple-fhir/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/single-url-environment-default/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/single-url-environment-default/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/single-url-environment-default/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/single-url-environment-default/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/single-url-environment-default/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/single-url-environment-default/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/single-url-environment-default/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/single-url-environment-default/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/single-url-environment-default/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/single-url-environment-default/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/single-url-environment-default/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/single-url-environment-default/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/single-url-environment-default/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/single-url-environment-default/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/single-url-environment-default/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/single-url-environment-default/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/single-url-environment-default/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/single-url-environment-default/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/single-url-environment-default/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/single-url-environment-default/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/single-url-environment-no-default/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/single-url-environment-no-default/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/single-url-environment-no-default/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/single-url-environment-no-default/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/single-url-environment-no-default/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/single-url-environment-no-default/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/single-url-environment-no-default/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/single-url-environment-no-default/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/single-url-environment-no-default/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/single-url-environment-no-default/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/single-url-environment-no-default/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/single-url-environment-no-default/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/single-url-environment-no-default/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/single-url-environment-no-default/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/single-url-environment-no-default/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/single-url-environment-no-default/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/single-url-environment-no-default/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/single-url-environment-no-default/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/single-url-environment-no-default/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/single-url-environment-no-default/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/streaming/allow-custom-fetcher/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/streaming/allow-custom-fetcher/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/streaming/allow-custom-fetcher/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/streaming/allow-custom-fetcher/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/streaming/allow-custom-fetcher/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/streaming/allow-custom-fetcher/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/streaming/allow-custom-fetcher/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/streaming/allow-custom-fetcher/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/streaming/allow-custom-fetcher/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/streaming/allow-custom-fetcher/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/streaming/allow-custom-fetcher/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/streaming/allow-custom-fetcher/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/streaming/allow-custom-fetcher/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/streaming/allow-custom-fetcher/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/streaming/allow-custom-fetcher/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/streaming/allow-custom-fetcher/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/streaming/allow-custom-fetcher/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/streaming/allow-custom-fetcher/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/streaming/allow-custom-fetcher/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/streaming/allow-custom-fetcher/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/streaming/no-custom-config/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/streaming/no-custom-config/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/streaming/no-custom-config/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/streaming/no-custom-config/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/streaming/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/streaming/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/streaming/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/streaming/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/streaming/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/streaming/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/streaming/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/streaming/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/streaming/no-custom-config/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/streaming/no-custom-config/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/streaming/no-custom-config/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/streaming/no-custom-config/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/streaming/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/streaming/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/streaming/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/streaming/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/trace/exhaustive/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/trace/exhaustive/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/trace/exhaustive/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/trace/exhaustive/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/trace/exhaustive/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/trace/exhaustive/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/trace/exhaustive/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/trace/exhaustive/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/trace/exhaustive/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/trace/exhaustive/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/trace/exhaustive/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/trace/exhaustive/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/trace/exhaustive/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/trace/exhaustive/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/trace/exhaustive/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/trace/exhaustive/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/trace/exhaustive/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/trace/exhaustive/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/trace/exhaustive/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/trace/exhaustive/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/trace/no-custom-config/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/trace/no-custom-config/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/trace/no-custom-config/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/trace/no-custom-config/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/trace/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/trace/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/trace/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/trace/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/trace/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/trace/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/trace/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/trace/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/trace/no-custom-config/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/trace/no-custom-config/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/trace/no-custom-config/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/trace/no-custom-config/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/trace/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/trace/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/trace/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/trace/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/trace/no-zurg-no-throwing/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/trace/no-zurg-no-throwing/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/trace/no-zurg-no-throwing/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/trace/no-zurg-no-throwing/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/trace/no-zurg-no-throwing/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/trace/no-zurg-no-throwing/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/trace/no-zurg-no-throwing/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/trace/no-zurg-no-throwing/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/trace/no-zurg-no-throwing/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/trace/no-zurg-no-throwing/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/trace/no-zurg-no-throwing/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/trace/no-zurg-no-throwing/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/trace/no-zurg-no-throwing/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/trace/no-zurg-no-throwing/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/trace/no-zurg-no-throwing/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/trace/no-zurg-no-throwing/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/trace/no-zurg-no-throwing/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/trace/no-zurg-no-throwing/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/trace/no-zurg-no-throwing/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/trace/no-zurg-no-throwing/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/trace/no-zurg-trace/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/trace/no-zurg-trace/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/trace/no-zurg-trace/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/trace/no-zurg-trace/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/trace/no-zurg-trace/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/trace/no-zurg-trace/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/trace/no-zurg-trace/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/trace/no-zurg-trace/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/trace/no-zurg-trace/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/trace/no-zurg-trace/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/trace/no-zurg-trace/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/trace/no-zurg-trace/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/trace/no-zurg-trace/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/trace/no-zurg-trace/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/trace/no-zurg-trace/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/trace/no-zurg-trace/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/trace/no-zurg-trace/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/trace/no-zurg-trace/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/trace/no-zurg-trace/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/trace/no-zurg-trace/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/ts-express-casing/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/ts-express-casing/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/ts-express-casing/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/ts-express-casing/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/ts-express-casing/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/ts-express-casing/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/ts-express-casing/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/ts-express-casing/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/ts-express-casing/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/ts-express-casing/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/ts-express-casing/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/ts-express-casing/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/ts-express-casing/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/ts-express-casing/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/ts-express-casing/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/ts-express-casing/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/ts-express-casing/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/ts-express-casing/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/ts-express-casing/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/ts-express-casing/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/undiscriminated-unions/no-custom-config/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/undiscriminated-unions/no-custom-config/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/undiscriminated-unions/no-custom-config/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/undiscriminated-unions/no-custom-config/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/undiscriminated-unions/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/undiscriminated-unions/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/undiscriminated-unions/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/undiscriminated-unions/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/undiscriminated-unions/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/undiscriminated-unions/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/undiscriminated-unions/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/undiscriminated-unions/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/undiscriminated-unions/no-custom-config/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/undiscriminated-unions/no-custom-config/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/undiscriminated-unions/no-custom-config/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/undiscriminated-unions/no-custom-config/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/undiscriminated-unions/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/undiscriminated-unions/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/undiscriminated-unions/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/undiscriminated-unions/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/undiscriminated-unions/skip-response-validation/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/undiscriminated-unions/skip-response-validation/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/undiscriminated-unions/skip-response-validation/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/undiscriminated-unions/skip-response-validation/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/undiscriminated-unions/skip-response-validation/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/undiscriminated-unions/skip-response-validation/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/undiscriminated-unions/skip-response-validation/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/undiscriminated-unions/skip-response-validation/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/undiscriminated-unions/skip-response-validation/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/undiscriminated-unions/skip-response-validation/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/undiscriminated-unions/skip-response-validation/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/undiscriminated-unions/skip-response-validation/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/undiscriminated-unions/skip-response-validation/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/undiscriminated-unions/skip-response-validation/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/undiscriminated-unions/skip-response-validation/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/undiscriminated-unions/skip-response-validation/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/undiscriminated-unions/skip-response-validation/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/undiscriminated-unions/skip-response-validation/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/undiscriminated-unions/skip-response-validation/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/undiscriminated-unions/skip-response-validation/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/unions/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/unions/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/unions/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/unions/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/unions/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/unions/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/unions/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/unions/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/unions/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/unions/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/unions/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/unions/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/unions/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/unions/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/unions/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/unions/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/unions/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/unions/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/unions/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/unions/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/unknown/no-custom-config/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/unknown/no-custom-config/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/unknown/no-custom-config/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/unknown/no-custom-config/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/unknown/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/unknown/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/unknown/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/unknown/no-custom-config/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/unknown/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/unknown/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/unknown/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/unknown/no-custom-config/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/unknown/no-custom-config/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/unknown/no-custom-config/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/unknown/no-custom-config/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/unknown/no-custom-config/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/unknown/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/unknown/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/unknown/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/unknown/no-custom-config/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/unknown/unknown-as-any/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/unknown/unknown-as-any/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/unknown/unknown-as-any/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/unknown/unknown-as-any/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/unknown/unknown-as-any/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/unknown/unknown-as-any/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/unknown/unknown-as-any/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/unknown/unknown-as-any/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/unknown/unknown-as-any/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/unknown/unknown-as-any/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/unknown/unknown-as-any/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/unknown/unknown-as-any/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/unknown/unknown-as-any/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/unknown/unknown-as-any/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/unknown/unknown-as-any/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/unknown/unknown-as-any/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/unknown/unknown-as-any/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/unknown/unknown-as-any/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/unknown/unknown-as-any/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/unknown/unknown-as-any/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/validation/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/validation/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/validation/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/validation/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/validation/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/validation/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/validation/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/validation/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/validation/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/validation/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/validation/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/validation/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/validation/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/validation/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/validation/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/validation/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/validation/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/validation/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/validation/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/validation/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/variables/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/variables/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/variables/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/variables/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/variables/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/variables/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/variables/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/variables/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/variables/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/variables/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/variables/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/variables/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/variables/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/variables/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/variables/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/variables/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/variables/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/variables/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/variables/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/variables/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/version-no-default/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/version-no-default/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/version-no-default/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/version-no-default/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/version-no-default/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/version-no-default/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/version-no-default/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/version-no-default/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/version-no-default/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/version-no-default/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/version-no-default/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/version-no-default/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/version-no-default/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/version-no-default/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/version-no-default/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/version-no-default/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/version-no-default/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/version-no-default/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/version-no-default/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/version-no-default/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random; diff --git a/seed/ts-sdk/version/tests/unit/fetcher/Fetcher.test.ts b/seed/ts-sdk/version/tests/unit/fetcher/Fetcher.test.ts index 2852994bb99..ff8042175ff 100644 --- a/seed/ts-sdk/version/tests/unit/fetcher/Fetcher.test.ts +++ b/seed/ts-sdk/version/tests/unit/fetcher/Fetcher.test.ts @@ -1,4 +1,3 @@ -import fetchMock from "fetch-mock-jest"; import fs from "fs"; import { Fetcher, fetcherImpl } from "../../../src/core/fetcher/Fetcher"; import { join } from "path"; @@ -14,8 +13,11 @@ describe("Test fetcherImpl", () => { requestType: "json", }; - fetchMock.mock("https://httpbin.org/post", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => ({ data: "test" }), }); const result = await fetcherImpl(mockArgs); @@ -23,6 +25,15 @@ describe("Test fetcherImpl", () => { if (result.ok) { expect(result.body).toEqual({ data: "test" }); } + + expect(global.fetch).toHaveBeenCalledWith( + "https://httpbin.org/post", + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: JSON.stringify({ data: "test" }), + }) + ); }); it("should send octet stream", async () => { @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => { body: fs.createReadStream(join(__dirname, "test-file.txt")), }; - fetchMock.mock("https://httpbin.org/post/file", 200, { - response: JSON.stringify({ data: "test" }), + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + status: 200, + text: () => Promise.resolve(JSON.stringify({ data: "test" })), + json: () => Promise.resolve({ data: "test" }), }); const result = await fetcherImpl(mockArgs); - expect(fetchMock).toHaveFetched(url, { - method: "POST", - body: fs.createReadStream(join(__dirname, "test-file.txt")).read(), - }); + expect(global.fetch).toHaveBeenCalledWith( + url, + expect.objectContaining({ + method: "POST", + headers: expect.objectContaining({ "X-Test": "x-test-header" }), + body: expect.any(fs.ReadStream), + }) + ); expect(result.ok).toBe(true); if (result.ok) { expect(result.body).toEqual({ data: "test" }); diff --git a/seed/ts-sdk/version/tests/unit/fetcher/getRequestBody.test.ts b/seed/ts-sdk/version/tests/unit/fetcher/getRequestBody.test.ts index 1b1462c51bd..919604c2e12 100644 --- a/seed/ts-sdk/version/tests/unit/fetcher/getRequestBody.test.ts +++ b/seed/ts-sdk/version/tests/unit/fetcher/getRequestBody.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getRequestBody } from "../../../src/core/fetcher/getRequestBody"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getRequestBody", () => { it("should return FormData as is in Node environment", async () => { if (RUNTIME.type === "node") { diff --git a/seed/ts-sdk/version/tests/unit/fetcher/getResponseBody.test.ts b/seed/ts-sdk/version/tests/unit/fetcher/getResponseBody.test.ts index 3510779e3f9..1030c517ced 100644 --- a/seed/ts-sdk/version/tests/unit/fetcher/getResponseBody.test.ts +++ b/seed/ts-sdk/version/tests/unit/fetcher/getResponseBody.test.ts @@ -2,10 +2,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test getResponseBody", () => { it("should handle blob response type", async () => { const mockBlob = new Blob(["test"], { type: "text/plain" }); diff --git a/seed/ts-sdk/version/tests/unit/fetcher/makeRequest.test.ts b/seed/ts-sdk/version/tests/unit/fetcher/makeRequest.test.ts index 5969d5155ac..be94ab45f10 100644 --- a/seed/ts-sdk/version/tests/unit/fetcher/makeRequest.test.ts +++ b/seed/ts-sdk/version/tests/unit/fetcher/makeRequest.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { makeRequest } from "../../../src/core/fetcher/makeRequest"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("Test makeRequest", () => { const mockPostUrl = "https://httpbin.org/post"; const mockGetUrl = "https://httpbin.org/get"; diff --git a/seed/ts-sdk/version/tests/unit/fetcher/requestWithRetries.test.ts b/seed/ts-sdk/version/tests/unit/fetcher/requestWithRetries.test.ts index 44811d8a191..6f77f093edf 100644 --- a/seed/ts-sdk/version/tests/unit/fetcher/requestWithRetries.test.ts +++ b/seed/ts-sdk/version/tests/unit/fetcher/requestWithRetries.test.ts @@ -1,10 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { requestWithRetries } from "../../../src/core/fetcher/requestWithRetries"; -if (RUNTIME.type === "browser") { - require("jest-fetch-mock").enableMocks(); -} - describe("requestWithRetries", () => { let mockFetch: jest.Mock; let originalMathRandom: typeof Math.random;