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/four-banks-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

`wrangler preview` no longer warns on inheritable binding types being missing from `previews` config.
86 changes: 86 additions & 0 deletions packages/wrangler/src/__tests__/preview.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,92 @@ describe("wrangler preview", () => {
expect(std.warn).not.toContain("IMPORTANT_BINDING");
});

test("should not warn about inheritable top-level bindings missing from previews", async ({
expect,
}) => {
mkdirSync("public", { recursive: true });
writeFileSync("public/index.html", "<h1>Hello</h1>");
writeFileSync(
"wrangler.json",
JSON.stringify({
name: "test-worker",
main: "src/index.ts",
compatibility_date: "2025-01-01",
assets: {
binding: "ASSETS",
directory: "public",
},
})
);

msw.use(
http.get(
`*/accounts/:accountId/workers/workers/:workerId/previews/:previewId`,
() =>
HttpResponse.json(
{
success: false,
result: null,
errors: [{ code: 10025, message: "Preview not found" }],
},
{ status: 404 }
)
),
http.post(
`*/accounts/:accountId/workers/workers/:workerId/previews`,
() =>
HttpResponse.json({
success: true,
result: {
id: "preview-id-assets",
name: "test-preview",
slug: "test-preview",
urls: ["https://test-preview.test-worker.cloudflare.app"],
worker_name: "test-worker",
created_on: new Date().toISOString(),
},
})
),
http.post(
`*/accounts/:accountId/workers/scripts/:workerId/assets-upload-session`,
() =>
HttpResponse.json({
success: true,
result: { buckets: [], jwt: "assets-jwt-from-session" },
})
),
http.post(
`*/accounts/:accountId/workers/workers/:workerId/previews/:previewId/deployments`,
() =>
HttpResponse.json({
success: true,
result: {
id: "deployment-id-assets",
preview_id: "preview-id-assets",
preview_name: "test-preview",
urls: ["https://assets123.test-worker.cloudflare.app"],
compatibility_date: "2025-01-01",
env: {},
created_on: new Date().toISOString(),
},
})
),
http.get(`*/accounts/:accountId/workers/workers/:workerId`, () =>
HttpResponse.json({
success: true,
result: {
preview_defaults: {},
},
})
)
);

await runWrangler("preview --name test-preview");

expect(std.warn).not.toContain("Your configuration has diverged.");
expect(std.warn).not.toContain("ASSETS");
});

test("should output preview and deployment JSON with --json", async ({
expect,
}) => {
Expand Down
9 changes: 8 additions & 1 deletion packages/wrangler/src/preview/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,12 @@ function formatDeploymentResource(
return drawConnectedChildBox(lines, { footerLines, indent: " " });
}

function isInheritableBinding(
binding: Exclude<StartDevWorkerInput["bindings"], undefined>[string]
) {
return binding.type === "assets";
}

function logMissingPreviewsBindingsWarning(
topLevelBindings: StartDevWorkerInput["bindings"],
remotePreviewDefaultBindings: Record<string, Binding> | undefined,
Expand All @@ -732,7 +738,8 @@ function logMissingPreviewsBindingsWarning(
]);
const missingBindings = Object.fromEntries(
Object.entries(topLevelBindings ?? {}).filter(
([name]) => !availableBindingNames.has(name)
([name, binding]) =>
!availableBindingNames.has(name) && !isInheritableBinding(binding)
)
);

Expand Down
Loading