Skip to content

Commit

Permalink
tee opt-in
Browse files Browse the repository at this point in the history
  • Loading branch information
penalosa committed Oct 10, 2024
1 parent 08bbfd8 commit f8b18e5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 25 deletions.
40 changes: 20 additions & 20 deletions packages/wrangler/e2e/dev-registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ describe.each([
it("can fetch b", async () => {
const worker = helper.runLongLived(cmd, { cwd: b });

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

await expect(fetch(url).then((r) => r.text())).resolves.toBe(
"hello world"
Expand All @@ -167,12 +167,12 @@ describe.each([
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();
await workerB.waitForReady(5_000, true);

const workerA = helper.runLongLived(cmd, { cwd: a });
const [{ url }] = await Promise.all([
workerA.waitForReady(),
workerA.readUntil(/- BEE: 🟢/),
workerA.waitForReady(5_000, true),
workerA.readUntil(/- BEE: 🟢/, 5_000, true),
]);

// Give the dev registry some time to settle
Expand All @@ -183,12 +183,12 @@ describe.each([

it("can fetch b through a (start a, start b)", async () => {
const workerA = helper.runLongLived(cmd, { cwd: a });
const { url } = await workerA.waitForReady();
const { url } = await workerA.waitForReady(5_000, true);

const workerB = helper.runLongLived(cmd, { cwd: b });
await Promise.all([
workerB.waitForReady(),
workerA.readUntil(/- BEE: 🟢/),
workerB.waitForReady(5_000, true),
workerA.readUntil(/- BEE: 🟢/, 5_000, true),
]);
// Give the dev registry some time to settle
await setTimeout(500);
Expand All @@ -215,13 +215,13 @@ describe.each([
it("can fetch service worker c through a (start c, start a)", async () => {
const workerC = helper.runLongLived(cmd, { cwd: c });
// We don't need c's URL, but ensure that c starts up before a
await workerC.waitForReady();
await workerC.waitForReady(5_000, true);

const workerA = helper.runLongLived(cmd, { cwd: a });

const [{ url }] = await Promise.all([
workerA.waitForReady(),
workerA.readUntil(/- CEE: 🟢/),
workerA.waitForReady(5_000, true),
workerA.readUntil(/- CEE: 🟢/, 5_000, true),
]);
// Give the dev registry some time to settle
await setTimeout(500);
Expand All @@ -236,13 +236,13 @@ describe.each([
"can fetch service worker c through a (start a, start c)",
async () => {
const workerA = helper.runLongLived(cmd, { cwd: a });
const { url } = await workerA.waitForReady();
const { url } = await workerA.waitForReady(5_000, true);

const workerC = helper.runLongLived(cmd, { cwd: c });

await Promise.all([
workerC.waitForReady(),
workerA.readUntil(/- CEE: 🟢/),
workerC.waitForReady(5_000, true),
workerA.readUntil(/- CEE: 🟢/, 5_000, true),
]);
// Give the dev registry some time to settle
await setTimeout(500);
Expand Down Expand Up @@ -280,7 +280,7 @@ describe.each([
it("can fetch DO through a", async () => {
const worker = helper.runLongLived(cmd, { cwd: a });

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

await expect(
fetchJson(`${url}/do`, {
Expand All @@ -295,13 +295,13 @@ describe.each([
"can fetch remote DO attached to a through b (start b, start a)",
async () => {
const workerB = helper.runLongLived(cmd, { cwd: b });
const { url } = await workerB.waitForReady();
const { url } = await workerB.waitForReady(5_000, true);

const workerA = helper.runLongLived(cmd, { cwd: a });

await Promise.all([
workerA.waitForReady(),
workerB.readUntil(/defined in 🟢/),
workerA.waitForReady(5_000, true),
workerB.readUntil(/defined in 🟢/, 5_000, true),
]);

// Give the dev registry some time to settle
Expand All @@ -319,13 +319,13 @@ describe.each([

it("can fetch remote DO attached to a through b (start a, start b)", async () => {
const workerA = helper.runLongLived(cmd, { cwd: a });
await workerA.waitForReady();
await workerA.waitForReady(5_000, true);

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

const [{ url }] = await Promise.all([
workerB.waitForReady(),
workerB.readUntil(/defined in 🟢/),
workerB.waitForReady(5_000, true),
workerB.readUntil(/defined in 🟢/, 5_000, true),
]);

// Give the dev registry some time to settle
Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/e2e/helpers/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class LongLivedCommand {
async readUntil(
regexp: RegExp,
readTimeout?: number,
tee = true
tee = false
): Promise<RegExpMatchArray> {
if (tee) {
const copies = this.stream.tee();
Expand Down
16 changes: 12 additions & 4 deletions packages/wrangler/e2e/helpers/wrangler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,23 @@ export class WranglerLongLivedCommand extends LongLivedCommand {
super(getWranglerCommand(wranglerCommand), getOptions(options));
}

async waitForReady(): Promise<{ url: string }> {
const match = await this.readUntil(/Ready on (?<url>https?:\/\/.*)/, 5_000);
async waitForReady(
readTimeout = 5_000,
tee?: boolean
): Promise<{ url: string }> {
const match = await this.readUntil(
/Ready on (?<url>https?:\/\/.*)/,
readTimeout,
tee
);
return match.groups as { url: string };
}

async waitForReload(readTimeout?: number): Promise<void> {
async waitForReload(readTimeout = 5_000, tee?: boolean): Promise<void> {
await this.readUntil(
/Detected changes, restarted server|Reloading local server\.\.\./,
readTimeout
readTimeout,
tee
);
}
}
Expand Down

0 comments on commit f8b18e5

Please sign in to comment.