Skip to content

Commit 6ce34dd

Browse files
cleanup the e2e test for the unenv preset (#10053)
Co-authored-by: Pete Bacon Darwin <[email protected]>
1 parent f467415 commit 6ce34dd

File tree

6 files changed

+86
-154
lines changed

6 files changed

+86
-154
lines changed

packages/wrangler/e2e/deployments.test.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,11 @@ describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)(
6868
assert(match?.groups);
6969
deployedUrl = match.groups.url;
7070

71-
const { text } = await retry(
72-
(s) => s.status !== 200,
73-
async () => {
74-
const r = await fetch(deployedUrl);
75-
return { text: await r.text(), status: r.status };
76-
}
71+
const response = await retry(
72+
(resp) => !resp.ok,
73+
async () => await fetch(deployedUrl)
7774
);
78-
expect(text).toMatchInlineSnapshot('"Hello World!"');
75+
await expect(response.text()).resolves.toEqual("Hello World!");
7976
});
8077

8178
it("lists 1 deployment", async () => {
@@ -110,14 +107,11 @@ describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)(
110107
assert(match?.groups);
111108
deployedUrl = match.groups.url;
112109

113-
const { text } = await retry(
114-
(s) => s.status !== 200 || s.text === "Hello World!",
115-
async () => {
116-
const r = await fetch(deployedUrl);
117-
return { text: await r.text(), status: r.status };
118-
}
110+
const response = await retry(
111+
(resp) => !resp.ok,
112+
async () => await fetch(deployedUrl)
119113
);
120-
expect(text).toMatchInlineSnapshot('"Updated Worker!"');
114+
await expect(response.text()).resolves.toEqual("Updated Worker!");
121115
});
122116

123117
it("lists 2 deployments", async () => {

packages/wrangler/e2e/provision.test.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,11 @@ describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)(
117117
assert(d1Match?.groups);
118118
d1Id = d1Match.groups.d1;
119119

120-
const { text } = await retry(
121-
(s) => s.status !== 200,
122-
async () => {
123-
const r = await fetch(deployedUrl);
124-
return { text: await r.text(), status: r.status };
125-
}
120+
const response = await retry(
121+
(resp) => !resp.ok,
122+
async () => await fetch(deployedUrl)
126123
);
127-
expect(text).toMatchInlineSnapshot('"Hello World!"');
124+
await expect(response.text()).resolves.toEqual("Hello World!");
128125
});
129126

130127
it("can inherit bindings on re-deploy and won't re-provision", async () => {
@@ -144,14 +141,11 @@ describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)(
144141
Current Version ID: 00000000-0000-0000-0000-000000000000"
145142
`);
146143

147-
const { text } = await retry(
148-
(s) => s.status !== 200,
149-
async () => {
150-
const r = await fetch(deployedUrl);
151-
return { text: await r.text(), status: r.status };
152-
}
144+
const response = await retry(
145+
(resp) => !resp.ok,
146+
async () => await fetch(deployedUrl)
153147
);
154-
expect(text).toMatchInlineSnapshot('"Hello World!"');
148+
await expect(response.text()).resolves.toEqual("Hello World!");
155149
});
156150

157151
it("can inherit and provision resources on version upload", async () => {

packages/wrangler/e2e/unenv-preset/local.test.ts

Lines changed: 0 additions & 51 deletions
This file was deleted.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { join } from "node:path";
2+
import { fetch } from "undici";
3+
import { afterAll, beforeAll, describe, expect, test, vi } from "vitest";
4+
import { formatCompatibilityDate } from "../../src/utils/compatibility-date";
5+
import { WranglerE2ETestHelper } from "../helpers/e2e-wrangler-test";
6+
import { generateResourceName } from "../helpers/generate-resource-name";
7+
import { retry } from "../helpers/retry";
8+
import { TESTS } from "./worker/index";
9+
import type { WranglerLongLivedCommand } from "../helpers/wrangler";
10+
11+
describe(`@cloudflare/unenv-preset tests`, () => {
12+
let helper: WranglerE2ETestHelper;
13+
14+
beforeAll(async () => {
15+
helper = new WranglerE2ETestHelper();
16+
await helper.seed({
17+
"wrangler.jsonc": JSON.stringify({
18+
name: generateResourceName(),
19+
main: join(__dirname, "/worker/index.ts"),
20+
compatibility_date: formatCompatibilityDate(new Date()),
21+
compatibility_flags: ["nodejs_compat"],
22+
vars: {
23+
DEBUG: "example",
24+
},
25+
}),
26+
});
27+
});
28+
29+
// Run the tests on:
30+
// - the "local" runtime installed in miniflare
31+
// - the "remote" runtime available in Cloudflare prod
32+
//
33+
// The "local" and "remote" runtimes do not necessarily use the exact same version
34+
// of workerd and we want to make sure the preset works for both.
35+
describe.for(["local", "remote"])("%s tests", (localOrRemote) => {
36+
let url: string;
37+
let wrangler: WranglerLongLivedCommand;
38+
beforeAll(async () => {
39+
wrangler = helper.runLongLived(`wrangler dev --${localOrRemote}`, {
40+
stopOnTestFinished: false,
41+
});
42+
url = (await wrangler.waitForReady()).url;
43+
44+
// Wait for the Worker to be actually responding.
45+
const response = await retry(
46+
(resp) => !resp.ok,
47+
async () => await fetch(`${url}/ping`)
48+
);
49+
await expect(response.text()).resolves.toEqual("pong");
50+
});
51+
52+
afterAll(async () => {
53+
await wrangler.stop();
54+
});
55+
56+
test.for(Object.keys(TESTS))(
57+
"%s",
58+
{ timeout: 20_000 },
59+
async (testName) => {
60+
// Retries the callback until it succeeds or times out.
61+
// Useful for the i.e. DNS tests where underlying requests might error/timeout.
62+
await vi.waitFor(async () => {
63+
const response = await fetch(`${url}/${testName}`);
64+
const body = await response.text();
65+
expect(body).toMatch("OK!");
66+
});
67+
}
68+
);
69+
});
70+
});

packages/wrangler/e2e/unenv-preset/remote.test.ts

Lines changed: 0 additions & 74 deletions
This file was deleted.

packages/wrangler/e2e/unenv-preset/worker/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export default {
2020
const url = new URL(request.url);
2121
const testName = url.pathname.slice(1);
2222
if (testName === "ping") {
23-
// Used by the deploy test to know when the worker is online
2423
return new Response("pong");
2524
}
2625
const test = TESTS[testName];

0 commit comments

Comments
 (0)