Skip to content

Commit

Permalink
add e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonKearl committed Sep 7, 2023
1 parent b50221d commit 6d105a2
Showing 1 changed file with 53 additions and 2 deletions.
55 changes: 53 additions & 2 deletions packages/wrangler/e2e/dev.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe("basic dev tests", () => {
name = "${workerName}"
main = "src/index.ts"
compatibility_date = "2023-01-01"
[vars]
KEY = "value"
`,
Expand Down Expand Up @@ -101,7 +101,7 @@ describe("basic dev tests", () => {
name = "${workerName}"
main = "src/index.ts"
compatibility_date = "2023-01-01"
[vars]
KEY = "updated"
`,
Expand All @@ -117,6 +117,57 @@ describe("basic dev tests", () => {
});
});

it("can recover from syntax error during dev session (local)", async () => {
await runDevSession(workerPath, "", async (port) => {
const { text } = await retry(
(s) => s.status !== 200,
async () => {
const r = await fetch(`http://127.0.0.1:${port}`);
return { text: await r.text(), status: r.status };
}
);
expect(text).toMatchInlineSnapshot('"Hello World!"');

await seed(workerPath, {
"src/index.ts": dedent`
export default {
fetch(request, env) {
return new Response("Updated Worker!")
} // <= added syntax error
}
}`,
});

// Output during error state is indeterminate.
// const { text: text2 } = await retry(
// (s) => s.status !== 200 || s.text === "Hello World!",
// async () => {
// const r = await fetch(`http://127.0.0.1:${port}`);
// return { text: await r.text(), status: r.status };
// }
// );
// expect(text2).toMatchInlineSnapshot('"Hello World!"');

await seed(workerPath, {
"src/index.ts": dedent`
export default {
fetch(request, env) {
return new Response("Updated Worker!")
}
}`,
});

const { text: text3 } = await retry(
(s) => s.status !== 200 || s.text === "Hello World!",
async () => {
const r = await fetch(`http://127.0.0.1:${port}`);
return { text: await r.text(), status: r.status };
}
);
expect(text3).toMatchInlineSnapshot('"Updated Worker!"');
});
});

it("can modify worker during dev session (remote)", async () => {
await runDevSession(workerPath, "--remote --ip 127.0.0.1", async (port) => {
const { text } = await retry(
Expand Down

0 comments on commit 6d105a2

Please sign in to comment.