Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fair-buses-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

feat: add support for include and exclude when publishing site assets
16 changes: 16 additions & 0 deletions .changeset/four-tips-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
"wrangler": patch
---

fix: ensure `kv:key list` matches the output from Wrangler 1

The previous output was passing an array of objects to console.log, which ended up showing something like

```
[Object object]
[Object object]
...
```

Now the result is JSON stringified before being sent to the console.
The tests have been fixed to check this too.
8 changes: 8 additions & 0 deletions .changeset/silly-students-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"wrangler": patch
---

fix: check actual asset file size, not base64 encoded size

Previously we were checking whether the base64 encoded size of an asset was too large (>25MiB).
But base64 takes up more space than a normal file, so this was too aggressive.
2 changes: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/wrangler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"finalhandler": "^1.1.2",
"find-up": "^6.2.0",
"formdata-node": "^4.3.1",
"ignore": "^5.2.0",
"ink": "^3.2.0",
"ink-select-input": "^4.2.1",
"ink-table": "^3.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/wrangler/src/__tests__/dev.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function renderDev({
jsxFragment,
bindings = {},
public: publicDir,
site,
assetPaths,
compatibilityDate,
compatibilityFlags,
usageModel,
Expand All @@ -56,7 +56,7 @@ function renderDev({
jsxFactory={jsxFactory}
jsxFragment={jsxFragment}
accountId={accountId}
site={site}
assetPaths={assetPaths}
public={publicDir}
compatibilityDate={compatibilityDate}
compatibilityFlags={compatibilityFlags}
Expand Down
177 changes: 125 additions & 52 deletions packages/wrangler/src/__tests__/kv.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { writeFileSync } from "fs";
import type { KVNamespaceInfo } from "../kv";
import {
setMockResponse,
setMockRawResponse,
Expand All @@ -8,11 +9,6 @@ import {
import { runWrangler } from "./run-wrangler";
import { runInTempDir } from "./run-in-tmp";

interface KVNamespaceInfo {
title: string;
id: string;
}

describe("wrangler", () => {
runInTempDir();

Expand Down Expand Up @@ -685,37 +681,6 @@ describe("wrangler", () => {
});

describe("list", () => {
function mockKeyListRequest(
expectedNamespaceId: string,
expectedKeys: string[],
keysPerRequest = 1000
) {
const requests = { count: 0 };
setMockRawResponse(
"/accounts/:accountId/storage/kv/namespaces/:namespaceId/keys",
([_url, accountId, namespaceId], _init, query) => {
requests.count++;
expect(accountId).toEqual("some-account-id");
expect(namespaceId).toEqual(expectedNamespaceId);
if (expectedKeys.length <= keysPerRequest) {
return createFetchResult(expectedKeys);
} else {
const start = parseInt(query.get("cursor") ?? "0") || 0;
const end = start + keysPerRequest;
const cursor = end < expectedKeys.length ? end : undefined;
return createFetchResult(
expectedKeys.slice(start, end),
true,
[],
[],
{ cursor }
);
}
}
);
return requests;
}

it("should list the keys of a namespace specified by namespace-id", async () => {
const keys = ["key-1", "key-2", "key-3"];
mockKeyListRequest("some-namespace-id", keys);
Expand All @@ -725,9 +690,23 @@ describe("wrangler", () => {
expect(error).toMatchInlineSnapshot(`undefined`);
expect(stderr).toMatchInlineSnapshot(`""`);
expect(stdout).toMatchInlineSnapshot(`
"key-1
key-2
key-3"
"[
{
\\"name\\": \\"key-1\\",
\\"expiration\\": 123456789,
\\"metadata\\": {}
},
{
\\"name\\": \\"key-2\\",
\\"expiration\\": 123456789,
\\"metadata\\": {}
},
{
\\"name\\": \\"key-3\\",
\\"expiration\\": 123456789,
\\"metadata\\": {}
}
]"
`);
});

Expand All @@ -741,9 +720,23 @@ describe("wrangler", () => {
expect(error).toMatchInlineSnapshot(`undefined`);
expect(stderr).toMatchInlineSnapshot(`""`);
expect(stdout).toMatchInlineSnapshot(`
"key-1
key-2
key-3"
"[
{
\\"name\\": \\"key-1\\",
\\"expiration\\": 123456789,
\\"metadata\\": {}
},
{
\\"name\\": \\"key-2\\",
\\"expiration\\": 123456789,
\\"metadata\\": {}
},
{
\\"name\\": \\"key-3\\",
\\"expiration\\": 123456789,
\\"metadata\\": {}
}
]"
`);
});

Expand All @@ -757,9 +750,23 @@ describe("wrangler", () => {
expect(error).toMatchInlineSnapshot(`undefined`);
expect(stderr).toMatchInlineSnapshot(`""`);
expect(stdout).toMatchInlineSnapshot(`
"key-1
key-2
key-3"
"[
{
\\"name\\": \\"key-1\\",
\\"expiration\\": 123456789,
\\"metadata\\": {}
},
{
\\"name\\": \\"key-2\\",
\\"expiration\\": 123456789,
\\"metadata\\": {}
},
{
\\"name\\": \\"key-3\\",
\\"expiration\\": 123456789,
\\"metadata\\": {}
}
]"
`);
});

Expand All @@ -773,9 +780,23 @@ describe("wrangler", () => {
expect(error).toMatchInlineSnapshot(`undefined`);
expect(stderr).toMatchInlineSnapshot(`""`);
expect(stdout).toMatchInlineSnapshot(`
"key-1
key-2
key-3"
"[
{
\\"name\\": \\"key-1\\",
\\"expiration\\": 123456789,
\\"metadata\\": {}
},
{
\\"name\\": \\"key-2\\",
\\"expiration\\": 123456789,
\\"metadata\\": {}
},
{
\\"name\\": \\"key-3\\",
\\"expiration\\": 123456789,
\\"metadata\\": {}
}
]"
`);
});

Expand All @@ -789,9 +810,23 @@ describe("wrangler", () => {
expect(error).toMatchInlineSnapshot(`undefined`);
expect(stderr).toMatchInlineSnapshot(`""`);
expect(stdout).toMatchInlineSnapshot(`
"key-1
key-2
key-3"
"[
{
\\"name\\": \\"key-1\\",
\\"expiration\\": 123456789,
\\"metadata\\": {}
},
{
\\"name\\": \\"key-2\\",
\\"expiration\\": 123456789,
\\"metadata\\": {}
},
{
\\"name\\": \\"key-3\\",
\\"expiration\\": 123456789,
\\"metadata\\": {}
}
]"
`);
});

Expand All @@ -808,7 +843,7 @@ describe("wrangler", () => {
);
expect(error).toMatchInlineSnapshot(`undefined`);
expect(stderr).toMatchInlineSnapshot(`""`);
expect(stdout).toEqual(keys.join("\n"));
expect(JSON.parse(stdout).map((k) => k.name)).toEqual(keys);
expect(requests.count).toEqual(6);
});

Expand Down Expand Up @@ -1124,3 +1159,41 @@ function writeWranglerConfig() {
"utf-8"
);
}

export function mockKeyListRequest(
expectedNamespaceId: string,
expectedKeys: string[],
keysPerRequest = 1000
) {
const requests = { count: 0 };
// See https://api.cloudflare.com/#workers-kv-namespace-list-a-namespace-s-keys
const expectedKeyObjects = expectedKeys.map((name) => ({
name,
expiration: 123456789,
metadata: {},
}));
setMockRawResponse(
"/accounts/:accountId/storage/kv/namespaces/:namespaceId/keys",
"GET",
([_url, accountId, namespaceId], _init, query) => {
requests.count++;
expect(accountId).toEqual("some-account-id");
expect(namespaceId).toEqual(expectedNamespaceId);
if (expectedKeyObjects.length <= keysPerRequest) {
return createFetchResult(expectedKeyObjects);
} else {
const start = parseInt(query.get("cursor") ?? "0") || 0;
const end = start + keysPerRequest;
const cursor = end < expectedKeyObjects.length ? end : undefined;
return createFetchResult(
expectedKeyObjects.slice(start, end),
true,
[],
[],
{ cursor }
);
}
}
);
return requests;
}
6 changes: 4 additions & 2 deletions packages/wrangler/src/__tests__/mock-cfetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ export async function mockFetchInternal(
const resourcePath = new URL(resource, CF_API_BASE_URL).pathname;
const uri = regexp.exec(resourcePath);
// Do the resource path and (if specified) the HTTP method match?
if (uri !== null && (!method || method === init.method)) {
if (uri !== null && (!method || method === (init.method ?? "GET"))) {
// The `resource` regular expression will extract the labelled groups from the URL.
// These are passed through to the `handler` call, to allow it to do additional checks or behaviour.
return handler(uri, init, queryParams); // TODO: should we have some kind of fallthrough system? we'll see.
}
}
throw new Error(`no mocks found for ${init.method}: ${resource}`);
throw new Error(
`no mocks found for ${init.method ?? "any HTTP"} request to ${resource}`
);
}

/**
Expand Down
Loading