Skip to content

Commit 22a4055

Browse files
authored
Turn on --x-registry for Pages by default (#7381)
1 parent a3f56d1 commit 22a4055

File tree

4 files changed

+126
-3
lines changed

4 files changed

+126
-3
lines changed

.changeset/seven-eels-reflect.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Turn on `--x-registry` for Pages by default

packages/wrangler/e2e/dev-registry.test.ts

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { execSync } from "child_process";
2+
import getPort from "get-port";
23
import dedent from "ts-dedent";
34
import { fetch } from "undici";
45
import { beforeEach, describe, expect, it, vi } from "vitest";
@@ -140,7 +141,7 @@ describe("unstable_dev()", () => {
140141
});
141142

142143
describe.each([
143-
{ cmd: "wrangler dev --x-registry" },
144+
{ cmd: "wrangler dev" },
144145
{ cmd: "wrangler dev --no-x-registry" },
145146
])("dev registry $cmd", ({ cmd }) => {
146147
let workerName: string;
@@ -450,4 +451,121 @@ describe.each([
450451
);
451452
});
452453
});
454+
455+
describe("pages dev", () => {
456+
beforeEach(async () => {
457+
await baseSeed(a, {
458+
"wrangler.toml": dedent`
459+
name = "${workerName}"
460+
pages_build_output_dir = "dist"
461+
compatibility_date = "2023-01-01"
462+
463+
[[services]]
464+
binding = "BEE"
465+
service = '${workerName2}'
466+
`,
467+
"dist/_worker.js": dedent/* javascript */ `export default {
468+
fetch(req, env) {
469+
const url = new URL(req.url)
470+
if (url.pathname === "/service") {
471+
return env.BEE.fetch(req);
472+
}
473+
return new Response("Hello from Pages")
474+
},
475+
};`,
476+
});
477+
});
478+
it("can fetch b", async () => {
479+
const worker = helper.runLongLived(cmd, { cwd: b });
480+
481+
const { url } = await worker.waitForReady(5_000);
482+
483+
await expect(fetch(url).then((r) => r.text())).resolves.toBe(
484+
"hello world"
485+
);
486+
});
487+
488+
it("can fetch a (pages project)", async () => {
489+
const port = await getPort();
490+
const worker = helper.runLongLived(
491+
`${cmd.replace("wrangler dev", "wrangler pages dev")} --port ${port}`,
492+
{ cwd: a }
493+
);
494+
495+
const { url } = await worker.waitForReady(5_000);
496+
497+
await expect(fetch(url).then((r) => r.text())).resolves.toBe(
498+
"Hello from Pages"
499+
);
500+
});
501+
502+
it("can fetch b through a (start b, start a)", async () => {
503+
const workerB = helper.runLongLived(cmd, { cwd: b });
504+
// We don't need b's URL, but ensure that b starts up before a
505+
await workerB.waitForReady(5_000);
506+
507+
const port = await getPort();
508+
const workerA = helper.runLongLived(
509+
`${cmd.replace("wrangler dev", "wrangler pages dev")} --port ${port}`,
510+
{ cwd: a }
511+
);
512+
const { url } = await workerA.waitForReady(5_000);
513+
514+
await vi.waitFor(
515+
async () =>
516+
await expect(fetchText(`${url}/service`)).resolves.toBe(
517+
"hello world"
518+
),
519+
{ interval: 1000, timeout: 10_000 }
520+
);
521+
522+
expect(normalizeOutput(workerA.currentOutput)).toContain(
523+
"bindings connect to other `wrangler dev` processes running locally"
524+
);
525+
});
526+
527+
it("can fetch b through a (start a, start b)", async () => {
528+
const port = await getPort();
529+
const workerA = helper.runLongLived(
530+
`${cmd.replace("wrangler dev", "wrangler pages dev")} --port ${port}`,
531+
{ cwd: a }
532+
);
533+
const { url } = await workerA.waitForReady(5_000);
534+
535+
const workerB = helper.runLongLived(cmd, { cwd: b });
536+
await workerB.waitForReady(5_000);
537+
538+
await vi.waitFor(
539+
async () =>
540+
await expect(fetchText(`${url}/service`)).resolves.toBe(
541+
"hello world"
542+
),
543+
{ interval: 1000, timeout: 10_000 }
544+
);
545+
});
546+
547+
it("can fetch b through a (start a, start b) w/o config file", async () => {
548+
await baseSeed(a, {
549+
"wrangler.toml": dedent`
550+
`,
551+
});
552+
const port = await getPort();
553+
const workerA = helper.runLongLived(
554+
`${cmd.replace("wrangler dev", "wrangler pages dev")} dist --service BEE=${workerName2} --port ${port}`,
555+
{ cwd: a }
556+
);
557+
const { url } = await workerA.waitForReady(5_000);
558+
559+
const workerB = helper.runLongLived(cmd, { cwd: b });
560+
await workerB.waitForReady(5_000);
561+
562+
await vi.waitFor(
563+
async () =>
564+
await expect(fetchText(`${url}/service`)).resolves.toBe(
565+
"hello world"
566+
),
567+
{ interval: 1000, timeout: 10_000 }
568+
);
569+
});
570+
});
453571
});

packages/wrangler/src/__tests__/pages/pages.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe("pages", () => {
7777
--persist-to Specify directory to use for local persistence (defaults to .wrangler/state) [string]
7878
--log-level Specify logging level [choices: \\"debug\\", \\"info\\", \\"log\\", \\"warn\\", \\"error\\", \\"none\\"]
7979
--show-interactive-dev-session Show interactive dev session (defaults to true if the terminal supports interactivity) [boolean]
80-
--experimental-registry, --x-registry Use the experimental file based dev registry for multi-worker development [boolean] [default: false]
80+
--experimental-registry, --x-registry Use the experimental file based dev registry for multi-worker development [boolean] [default: true]
8181
--experimental-vectorize-bind-to-prod Bind to production Vectorize indexes in local development mode [boolean] [default: false]"
8282
`);
8383
});

packages/wrangler/src/pages/dev.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ export function Options(yargs: CommonYargsArgv) {
249249
type: "boolean",
250250
describe:
251251
"Use the experimental file based dev registry for multi-worker development",
252-
default: false,
252+
default: true,
253253
},
254254
"experimental-vectorize-bind-to-prod": {
255255
type: "boolean",

0 commit comments

Comments
 (0)