Skip to content

Commit

Permalink
fixup! [wrangler] fix: stop rebuild attempts when sources are missing (
Browse files Browse the repository at this point in the history
  • Loading branch information
petebacondarwin committed Jan 31, 2024
1 parent a8da1b8 commit 3785c25
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
60 changes: 60 additions & 0 deletions fixtures/pages-workerjs-app/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { execSync } from "node:child_process";
import { rename } from "node:fs/promises";
import path, { resolve } from "node:path";
import { setTimeout } from "node:timers/promises";
import { fetch } from "undici";
import { describe, it } from "vitest";
import { runWranglerPagesDev } from "../../shared/src/run-wrangler-long-lived";
Expand Down Expand Up @@ -60,4 +62,62 @@ describe("Pages _worker.js", () => {
await stop();
}
});

it("should not error if the worker.js file is removed while watching", async ({
expect,
}) => {
const basePath = resolve(__dirname, "..");
const { ip, port, getOutput, clearOutput, stop } =
await runWranglerPagesDev(resolve(__dirname, ".."), "./workerjs-test", [
"--port=0",
"--inspector-port=0",
]);
try {
clearOutput();
await tryRename(
basePath,
"workerjs-test/_worker.js",
"workerjs-test/XXX_worker.js"
);
await setTimeout(1000);
expect(getOutput()).toMatchInlineSnapshot('""');

clearOutput();
await tryRename(
basePath,
"workerjs-test/XXX_worker.js",
"workerjs-test/_worker.js"
);
await setTimeout(1000);
expect(getOutput()).toMatchInlineSnapshot(`
"✨ Compiled Worker successfully
⎔ Reloading local server...
"
`);
} finally {
await stop();
await tryRename(
basePath,
"workerjs-test/XXX_worker.js",
"workerjs-test/_worker.js"
);
}
});

async function tryRename(
basePath: string,
from: string,
to: string
): Promise<void> {
try {
await rename(resolve(basePath, from), resolve(basePath, to));
} catch (e) {
// Do nothing if the file was not found
if ((e as any).code !== "ENOENT") {
throw e;
}
}
}
});
3 changes: 2 additions & 1 deletion fixtures/shared/src/run-wrangler-long-lived.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ async function runLongLivedWrangler(command: string[], cwd: string) {
chunks.push(chunk);
});
const getOutput = () => Buffer.concat(chunks).toString();
const clearOutput = () => (chunks.length = 0);

const timeoutHandle = setTimeout(() => {
if (settledReadyPromise) return;
Expand Down Expand Up @@ -90,5 +91,5 @@ async function runLongLivedWrangler(command: string[], cwd: string) {
}

const { ip, port } = await ready;
return { ip, port, stop, getOutput };
return { ip, port, stop, getOutput, clearOutput };
}

0 comments on commit 3785c25

Please sign in to comment.