Skip to content

Commit

Permalink
Turn on --x-registry for Pages by default (#7381)
Browse files Browse the repository at this point in the history
  • Loading branch information
penalosa authored Nov 28, 2024
1 parent a3f56d1 commit 22a4055
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/seven-eels-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Turn on `--x-registry` for Pages by default
120 changes: 119 additions & 1 deletion packages/wrangler/e2e/dev-registry.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { execSync } from "child_process";
import getPort from "get-port";
import dedent from "ts-dedent";
import { fetch } from "undici";
import { beforeEach, describe, expect, it, vi } from "vitest";
Expand Down Expand Up @@ -140,7 +141,7 @@ describe("unstable_dev()", () => {
});

describe.each([
{ cmd: "wrangler dev --x-registry" },
{ cmd: "wrangler dev" },
{ cmd: "wrangler dev --no-x-registry" },
])("dev registry $cmd", ({ cmd }) => {
let workerName: string;
Expand Down Expand Up @@ -450,4 +451,121 @@ describe.each([
);
});
});

describe("pages dev", () => {
beforeEach(async () => {
await baseSeed(a, {
"wrangler.toml": dedent`
name = "${workerName}"
pages_build_output_dir = "dist"
compatibility_date = "2023-01-01"
[[services]]
binding = "BEE"
service = '${workerName2}'
`,
"dist/_worker.js": dedent/* javascript */ `export default {
fetch(req, env) {
const url = new URL(req.url)
if (url.pathname === "/service") {
return env.BEE.fetch(req);
}
return new Response("Hello from Pages")
},
};`,
});
});
it("can fetch b", async () => {
const worker = helper.runLongLived(cmd, { cwd: b });

const { url } = await worker.waitForReady(5_000);

await expect(fetch(url).then((r) => r.text())).resolves.toBe(
"hello world"
);
});

it("can fetch a (pages project)", async () => {
const port = await getPort();
const worker = helper.runLongLived(
`${cmd.replace("wrangler dev", "wrangler pages dev")} --port ${port}`,
{ cwd: a }
);

const { url } = await worker.waitForReady(5_000);

await expect(fetch(url).then((r) => r.text())).resolves.toBe(
"Hello from Pages"
);
});

it("can fetch b through a (start b, start a)", async () => {
const workerB = helper.runLongLived(cmd, { cwd: b });
// We don't need b's URL, but ensure that b starts up before a
await workerB.waitForReady(5_000);

const port = await getPort();
const workerA = helper.runLongLived(
`${cmd.replace("wrangler dev", "wrangler pages dev")} --port ${port}`,
{ cwd: a }
);
const { url } = await workerA.waitForReady(5_000);

await vi.waitFor(
async () =>
await expect(fetchText(`${url}/service`)).resolves.toBe(
"hello world"
),
{ interval: 1000, timeout: 10_000 }
);

expect(normalizeOutput(workerA.currentOutput)).toContain(
"bindings connect to other `wrangler dev` processes running locally"
);
});

it("can fetch b through a (start a, start b)", async () => {
const port = await getPort();
const workerA = helper.runLongLived(
`${cmd.replace("wrangler dev", "wrangler pages dev")} --port ${port}`,
{ cwd: a }
);
const { url } = await workerA.waitForReady(5_000);

const workerB = helper.runLongLived(cmd, { cwd: b });
await workerB.waitForReady(5_000);

await vi.waitFor(
async () =>
await expect(fetchText(`${url}/service`)).resolves.toBe(
"hello world"
),
{ interval: 1000, timeout: 10_000 }
);
});

it("can fetch b through a (start a, start b) w/o config file", async () => {
await baseSeed(a, {
"wrangler.toml": dedent`
`,
});
const port = await getPort();
const workerA = helper.runLongLived(
`${cmd.replace("wrangler dev", "wrangler pages dev")} dist --service BEE=${workerName2} --port ${port}`,
{ cwd: a }
);
const { url } = await workerA.waitForReady(5_000);

const workerB = helper.runLongLived(cmd, { cwd: b });
await workerB.waitForReady(5_000);

await vi.waitFor(
async () =>
await expect(fetchText(`${url}/service`)).resolves.toBe(
"hello world"
),
{ interval: 1000, timeout: 10_000 }
);
});
});
});
2 changes: 1 addition & 1 deletion packages/wrangler/src/__tests__/pages/pages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe("pages", () => {
--persist-to Specify directory to use for local persistence (defaults to .wrangler/state) [string]
--log-level Specify logging level [choices: \\"debug\\", \\"info\\", \\"log\\", \\"warn\\", \\"error\\", \\"none\\"]
--show-interactive-dev-session Show interactive dev session (defaults to true if the terminal supports interactivity) [boolean]
--experimental-registry, --x-registry Use the experimental file based dev registry for multi-worker development [boolean] [default: false]
--experimental-registry, --x-registry Use the experimental file based dev registry for multi-worker development [boolean] [default: true]
--experimental-vectorize-bind-to-prod Bind to production Vectorize indexes in local development mode [boolean] [default: false]"
`);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/src/pages/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export function Options(yargs: CommonYargsArgv) {
type: "boolean",
describe:
"Use the experimental file based dev registry for multi-worker development",
default: false,
default: true,
},
"experimental-vectorize-bind-to-prod": {
type: "boolean",
Expand Down

0 comments on commit 22a4055

Please sign in to comment.