diff --git a/packages/wrangler/src/__tests__/kv.test.ts b/packages/wrangler/src/__tests__/kv.test.ts index 88af107985f8..36e4dc4b24f2 100644 --- a/packages/wrangler/src/__tests__/kv.test.ts +++ b/packages/wrangler/src/__tests__/kv.test.ts @@ -8,6 +8,11 @@ import { import { runWrangler } from "./run-wrangler"; import { runInTempDir } from "./run-in-tmp"; +interface KVNamespaceInfo { + title: string; + id: string; +} + describe("wrangler", () => { runInTempDir(); @@ -196,30 +201,30 @@ describe("wrangler", () => { } it("should list namespaces", async () => { - const KVNamespaces = [ + const kvNamespaces: KVNamespaceInfo[] = [ { title: "title-1", id: "id-1" }, { title: "title-2", id: "id-2" }, ]; - mockListRequest(KVNamespaces); + mockListRequest(kvNamespaces); const { error, stdout, stderr } = await runWrangler( "kv:namespace list" ); expect(error).toMatchInlineSnapshot(`undefined`); expect(stderr).toMatchInlineSnapshot(`""`); const namespaces = JSON.parse(stdout); - expect(namespaces).toEqual(KVNamespaces); + expect(namespaces).toEqual(kvNamespaces); }); it("should make multiple requests for paginated results", async () => { // Create a lot of mock namespaces, so that the fetch requests will be paginated - const KVNamespaces = []; + const kvNamespaces: KVNamespaceInfo[] = []; for (let i = 0; i < 550; i++) { - KVNamespaces.push({ title: "title-" + i, id: "id-" + i }); + kvNamespaces.push({ title: "title-" + i, id: "id-" + i }); } - const requests = mockListRequest(KVNamespaces); + const requests = mockListRequest(kvNamespaces); const { stdout } = await runWrangler("kv:namespace list"); const namespaces = JSON.parse(stdout); - expect(namespaces).toEqual(KVNamespaces); + expect(namespaces).toEqual(kvNamespaces); expect(requests.count).toEqual(6); }); }); @@ -335,8 +340,12 @@ describe("wrangler", () => { expect(namespaceId).toEqual(expectedNamespaceId); expect(key).toEqual(expectedKey); expect(body).toEqual(expectedValue); - expect(query.get("expiration")).toEqual(`${expiration}`); - expect(query.get("expiration_ttl")).toEqual(`${expirationTtl}`); + if (expiration) { + expect(query.get("expiration")).toEqual(`${expiration}`); + } + if (expirationTtl) { + expect(query.get("expiration_ttl")).toEqual(`${expirationTtl}`); + } return null; } ); @@ -681,7 +690,7 @@ describe("wrangler", () => { if (expectedKeys.length <= keysPerRequest) { return createFetchResult(expectedKeys); } else { - const start = parseInt(query.get("cursor")) || 0; + const start = parseInt(query.get("cursor") ?? "0") || 0; const end = start + keysPerRequest; const cursor = end < expectedKeys.length ? end : undefined; return createFetchResult( @@ -778,7 +787,7 @@ describe("wrangler", () => { it("should make multiple requests for paginated results", async () => { // Create a lot of mock keys, so that the fetch requests will be paginated - const keys = []; + const keys: string[] = []; for (let i = 0; i < 550; i++) { keys.push("key-" + i); } diff --git a/packages/wrangler/src/__tests__/mock-cfetch.ts b/packages/wrangler/src/__tests__/mock-cfetch.ts index f0ca6c035743..977308070313 100644 --- a/packages/wrangler/src/__tests__/mock-cfetch.ts +++ b/packages/wrangler/src/__tests__/mock-cfetch.ts @@ -1,5 +1,5 @@ import type { RequestInit } from "node-fetch"; -import type { URLSearchParams } from "node:url"; +import { URLSearchParams } from "node:url"; import { pathToRegexp } from "path-to-regexp"; import { CF_API_BASE_URL } from "../cfetch"; import type { FetchResult } from "../cfetch"; @@ -9,8 +9,8 @@ import type { FetchResult } from "../cfetch"; */ export type MockHandler = ( uri: RegExpExecArray, - init?: RequestInit, - queryParams?: URLSearchParams + init: RequestInit, + queryParams: URLSearchParams ) => ResponseType; type RemoveMockFn = () => void; @@ -32,7 +32,7 @@ const mocks: MockFetch[] = []; export async function mockFetchInternal( resource: string, init: RequestInit = {}, - queryParams?: URLSearchParams + queryParams: URLSearchParams = new URLSearchParams() ) { for (const { regexp, method, handler } of mocks) { const resourcePath = new URL(resource, CF_API_BASE_URL).pathname;