Skip to content

Commit

Permalink
fix(wrangler): Validate routes on config file changes (#6819)
Browse files Browse the repository at this point in the history
* fix(wrangler): Validate routes on config file changes

* add tests

* update tests to reflect new html_handling behaviour

---------

Co-authored-by: emily-shen <[email protected]>
  • Loading branch information
CarmenPopoviciu and emily-shen committed Sep 26, 2024
1 parent f70f750 commit 7ede181
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/friendly-papayas-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

fix: Validate `[routes]` on configuration file changes
39 changes: 27 additions & 12 deletions packages/wrangler/e2e/dev.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ describe("watch mode", () => {
describe.each([{ cmd: "wrangler dev" }, { cmd: "wrangler dev --x-dev-env" }])(
"Workers + Assets watch mode: $cmd",
({ cmd }) => {
it(`supports modifying existing assets during dev session`, async () => {
it(`supports modifying existing assets during dev session and errors when invalid routes are added`, async () => {
const helper = new WranglerE2ETestHelper();
await helper.seed({
"wrangler.toml": dedent`
Expand Down Expand Up @@ -977,6 +977,19 @@ describe("watch mode", () => {
);
// expect a new eTag back because the content for this path has changed
expect(response.headers.get("etag")).not.toBe(originalETag);

// changes to routes should error while in watch mode
await helper.seed({
"wrangler.toml": dedent`
name = "${workerName}"
compatibility_date = "2023-01-01"
route = "example.com/path/*"
[assets]
directory = "./public"
`,
});
await worker.readUntil(/UserError: Invalid Routes:/);
});

it(`supports adding new assets during dev session`, async () => {
Expand Down Expand Up @@ -1158,11 +1171,7 @@ describe("watch mode", () => {
const worker = helper.runLongLived(cmd);
const { url } = await worker.waitForReady();

let response = await fetch(url);
expect(response.status).toBe(200);
expect(await response.text()).toBe("Hello from user Worker!");

response = await fetch(`${url}/hey`);
let response = await fetch(`${url}/hey`);
expect(response.status).toBe(200);
expect(await response.text()).toBe("Hello from user Worker!");

Expand Down Expand Up @@ -1226,11 +1235,7 @@ describe("watch mode", () => {
const worker = helper.runLongLived(cmd);
const { url } = await worker.waitForReady();

let response = await fetch(url);
expect(response.status).toBe(200);
expect(await response.text()).toBe("Hello from user Worker!");

response = await fetch(`${url}/hey`);
let response = await fetch(`${url}/hey`);
expect(response.status).toBe(200);
expect(await response.text()).toBe("Hello from user Worker!");

Expand Down Expand Up @@ -1395,7 +1400,7 @@ describe("watch mode", () => {
{ cmd: "wrangler dev --assets=dist" },
{ cmd: "wrangler dev --x-dev-env --assets=dist" },
])("Workers + Assets watch mode: $cmd", ({ cmd }) => {
it(`supports modifying assets during dev session`, async () => {
it(`supports modifying assets during dev session and errors when invalid routes are added`, async () => {
const helper = new WranglerE2ETestHelper();
await helper.seed({
"wrangler.toml": dedent`
Expand Down Expand Up @@ -1476,6 +1481,16 @@ describe("watch mode", () => {
}
));
expect(response.status).toBe(404);

// changes to routes should error while in watch mode
await helper.seed({
"wrangler.toml": dedent`
name = "${workerName}"
compatibility_date = "2023-01-01"
route = "example.com/path/*"
`,
});
await worker.readUntil(/UserError: Invalid Routes:/);
});

it(`supports switching from assets-only Workers to Workers with assets during the current dev session`, async () => {
Expand Down
3 changes: 3 additions & 0 deletions packages/wrangler/src/dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,9 @@ export async function startDev(args: StartDevOptions) {
"dev"
);

// ensure we re-validate routes
await getHostAndRoutes(args, config);

assetsOptions = processAssetsArg(args, config);

/*
Expand Down

0 comments on commit 7ede181

Please sign in to comment.