From c74195c62494cbbdecc921abaaca2e1003f3caf7 Mon Sep 17 00:00:00 2001 From: Carmen Popoviciu Date: Wed, 18 Dec 2024 16:16:03 +0100 Subject: [PATCH] chore(wrangler): Fix failing e2e tests (#7585) This commit fixed some e2e tests that started failing after https://github.com/cloudflare/workers-sdk/pull/7476 --- packages/wrangler/e2e/dev.test.ts | 91 ++++++++++++++++++++++--------- 1 file changed, 66 insertions(+), 25 deletions(-) diff --git a/packages/wrangler/e2e/dev.test.ts b/packages/wrangler/e2e/dev.test.ts index 9c5e58456a26..423ae226a8af 100644 --- a/packages/wrangler/e2e/dev.test.ts +++ b/packages/wrangler/e2e/dev.test.ts @@ -1158,7 +1158,7 @@ describe("watch mode", () => { describe.each([{ cmd: "wrangler dev" }])( "Workers + Assets watch mode: $cmd", ({ cmd }) => { - it(`supports modifying existing assets during dev session and errors when invalid routes are added`, async () => { + it(`supports modifying existing assets during dev session`, async () => { const helper = new WranglerE2ETestHelper(); await helper.seed({ "wrangler.toml": dedent` @@ -1199,19 +1199,6 @@ 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(/Invalid Routes:/); }); it(`supports adding new assets during dev session`, async () => { @@ -1662,13 +1649,48 @@ describe("watch mode", () => { // now check assets are still fetchable await expect(fetchText(url)).resolves.toBe("Hello from Assets"); }); + + it(`warns on mounted paths when routes are configured in the configuration file`, async () => { + const helper = new WranglerE2ETestHelper(); + await helper.seed({ + "wrangler.toml": dedent` + name = "${workerName}" + compatibility_date = "2023-01-01" + + [assets] + directory = "./public" + `, + "public/index.html": dedent` +

Hello Workers + Assets

`, + }); + + const worker = helper.runLongLived(cmd); + const { url } = await worker.waitForReady(); + + const { response } = await fetchWithETag(`${url}/index.html`, {}); + expect(await response.text()).toBe("

Hello Workers + Assets

"); + + await helper.seed({ + "wrangler.toml": dedent` + name = "${workerName}" + compatibility_date = "2023-01-01" + route = "example.com/path/*" + + [assets] + directory = "./public" + `, + }); + await worker.readUntil( + /Warning: The following routes will attempt to serve Assets on a configured path:/ + ); + }); } ); describe.each([{ cmd: "wrangler dev --assets=dist" }])( "Workers + Assets watch mode: $cmd", ({ cmd }) => { - it(`supports modifying assets during dev session and errors when invalid routes are added`, async () => { + it(`supports modifying assets during dev session`, async () => { const helper = new WranglerE2ETestHelper(); await helper.seed({ "wrangler.toml": dedent` @@ -1749,16 +1771,6 @@ 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(/Invalid Routes:/); }); it(`supports switching from assets-only Workers to Workers with assets during the current dev session`, async () => { @@ -1859,6 +1871,35 @@ describe("watch mode", () => { response = await fetch(`${url}/hey`); expect(response.status).toBe(404); }); + + it(`warns on mounted paths when routes are configured in the configuration file`, async () => { + const helper = new WranglerE2ETestHelper(); + await helper.seed({ + "wrangler.toml": dedent` + name = "${workerName}" + compatibility_date = "2023-01-01" + `, + "dist/index.html": dedent` +

Hello Workers + Assets

`, + }); + + const worker = helper.runLongLived(cmd); + const { url } = await worker.waitForReady(); + + const { response } = await fetchWithETag(`${url}/index.html`, {}); + expect(await response.text()).toBe("

Hello Workers + Assets

"); + + await helper.seed({ + "wrangler.toml": dedent` + name = "${workerName}" + compatibility_date = "2023-01-01" + route = "example.com/path/*" + `, + }); + await worker.readUntil( + /Warning: The following routes will attempt to serve Assets on a configured path:/ + ); + }); } ); });