Skip to content

Commit

Permalink
Bundle controller (#5957)
Browse files Browse the repository at this point in the history
* refactor use-esbuild

initial bundle controller

more stuff

Remove bundler flag

stuff

Remove oversharing

fix tests

more e2e

* fix lint

* fix tests

* Fix tests

* Enable all tests

* remove logging

* less logging

* fix tests + incorporate nodejs compat mode

* reduce diff

* comments

* fix test

* Make sure the dev registry works with dev env

* remove .only

* spaces ->  tabs

* fix snapshots

* remove logs

* de-asynify

* Auth refactor

* Address comments

* remove `.promise`
  • Loading branch information
penalosa authored Jun 10, 2024
1 parent cbebb04 commit 152a6cd
Show file tree
Hide file tree
Showing 18 changed files with 1,279 additions and 350 deletions.
2 changes: 1 addition & 1 deletion fixtures/dev-env/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import assert from "node:assert";
import events from "node:events";
import timers from "node:timers/promises";
import getPort from "get-port";
import { Log, Miniflare } from "miniflare";
import { Miniflare } from "miniflare";
import * as undici from "undici";
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
import { unstable_DevEnv as DevEnv } from "wrangler";
Expand Down
111 changes: 55 additions & 56 deletions packages/wrangler/e2e/dev.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,110 +217,109 @@ describe.each([
);
});

describe("dev registry", () => {
let a: string;
let b: string;

beforeEach(async () => {
a = await makeRoot();
await baseSeed(a, {
"wrangler.toml": dedent`
describe.each([{ cmd: "wrangler dev" }, { cmd: "wrangler dev --x-dev-env" }])(
"dev registry $cmd",
({ cmd }) => {
let a: string;
let b: string;

beforeEach(async () => {
a = await makeRoot();
await baseSeed(a, {
"wrangler.toml": dedent`
name = "a"
main = "src/index.ts"
[[services]]
binding = "BEE"
service = 'b'
`,
"src/index.ts": dedent/* javascript */ `
"src/index.ts": dedent/* javascript */ `
export default {
fetch(req, env) {
return env.BEE.fetch(req);
},
};
`,
"package.json": dedent`
"package.json": dedent`
{
"name": "a",
"version": "0.0.0",
"private": true
}
`,
});
});

b = await makeRoot();
await baseSeed(b, {
"wrangler.toml": dedent`
b = await makeRoot();
await baseSeed(b, {
"wrangler.toml": dedent`
name = "b"
main = "src/index.ts"
compatibility_date = "2023-01-01"
`,
"src/index.ts": dedent/* javascript */ `
"src/index.ts": dedent/* javascript */ `
export default{
fetch() {
return new Response("hello world");
},
};
`,
"package.json": dedent`
"package.json": dedent`
{
"name": "b",
"version": "0.0.0",
"private": true
}
`,
});
});
});

e2eTest("can fetch b", async ({ run, waitForReady }) => {
const worker = run("wrangler dev", { cwd: b });
e2eTest("can fetch b", async ({ run, waitForReady }) => {
const worker = run(cmd, { cwd: b });

const { url } = await waitForReady(worker);
const { url } = await waitForReady(worker);

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

e2eTest(
"can fetch b through a (start b, start a)",
async ({ run, waitForReady, waitForReload }) => {
const workerB = run("wrangler dev", { cwd: b });
// We don't need b's URL, but ensure that b starts up before a
await waitForReady(workerB);
e2eTest(
"can fetch b through a (start b, start a)",
async ({ run, waitForReady, waitForReload }) => {
const workerB = run(cmd, { cwd: b });
// We don't need b's URL, but ensure that b starts up before a
await waitForReady(workerB);

const workerA = run("wrangler dev", { cwd: a });
const { url } = await waitForReady(workerA);
const workerA = run(cmd, { cwd: a });
const { url } = await waitForReady(workerA);

// TODO(soon): Service bindings are only accessible after several reloads. We should fix this
await waitForReload(workerA);
await waitForReload(workerA);
await waitForReload(workerA);
// Give the dev registry some time to settle
await setTimeout(500);

await expect(fetchText(url)).resolves.toMatchInlineSnapshot(
'"hello world"'
);
}
);
await expect(fetchText(url)).resolves.toBe("hello world");
}
);

e2eTest(
"can fetch b through a (start a, start b)",
async ({ run, waitForReady, waitForReload }) => {
const workerA = run("wrangler dev", { cwd: a });
const { url } = await waitForReady(workerA);
e2eTest(
"can fetch b through a (start a, start b)",
async ({ run, waitForReady, waitForReload }) => {
const workerA = run(cmd, { cwd: a });
const { url } = await waitForReady(workerA);

const workerB = run("wrangler dev", { cwd: b });
await waitForReady(workerB);
const workerB = run(cmd, { cwd: b });
await waitForReady(workerB);

// TODO(soon): Service bindings are only accessible after several reloads. We should fix this
await waitForReload(workerA);
await waitForReload(workerA);
await waitForReload(workerA);
// Give the dev registry some time to settle
await setTimeout(500);

await expect(fetchText(url)).resolves.toMatchInlineSnapshot(
'"hello world"'
);
}
);
});
await expect(fetchText(url)).resolves.toBe("hello world");
}
);
}
);

describe("hyperdrive dev tests", () => {
let server: nodeNet.Server;
Expand Down
Loading

0 comments on commit 152a6cd

Please sign in to comment.