Skip to content

Commit 8a7c599

Browse files
committed
fix: improve fixture test reliability/debugability
- Only call `stop()` when `beforeAll()` hooks succeed - Call `stop()`s in `finally`-blocks to ensure cleanup - Add timeout to `runLongLivedWrangler()` and log `stdout`/`stderr`
1 parent f5ede1c commit 8a7c599

File tree

13 files changed

+104
-68
lines changed

13 files changed

+104
-68
lines changed

fixtures/node-app-pages/tests/index.test.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ describe("Pages Dev", () => {
1212
"public",
1313
["--node-compat", "--port=0"]
1414
);
15-
const response = await fetch(`http://${ip}:${port}/stripe`);
15+
try {
16+
const response = await fetch(`http://${ip}:${port}/stripe`);
1617

17-
await expect(response.text()).resolves.toContain(
18-
`"PATH":"path/to/some-file","STRIPE_OBJECT"`
19-
);
20-
21-
await stop();
18+
await expect(response.text()).resolves.toContain(
19+
`"PATH":"path/to/some-file","STRIPE_OBJECT"`
20+
);
21+
} finally {
22+
await stop();
23+
}
2224
});
2325
});

fixtures/pages-functions-app/tests/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { describe, it, beforeAll, afterAll } from "vitest";
44
import { runWranglerPagesDev } from "../../shared/src/run-wrangler-long-lived";
55

66
describe("Pages Functions", () => {
7-
let ip: string, port: number, stop: () => Promise<unknown>;
7+
let ip: string, port: number, stop: (() => Promise<unknown>) | undefined;
88

99
beforeAll(async () => {
1010
({ ip, port, stop } = await runWranglerPagesDev(
@@ -20,7 +20,7 @@ describe("Pages Functions", () => {
2020
});
2121

2222
afterAll(async () => {
23-
await stop();
23+
await stop?.();
2424
});
2525

2626
it("renders static pages", async ({ expect }) => {

fixtures/pages-functions-wasm-app/tests/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { describe, it, beforeAll, afterAll } from "vitest";
44
import { runWranglerPagesDev } from "../../shared/src/run-wrangler-long-lived";
55

66
describe("Pages Functions with wasm module imports", () => {
7-
let ip: string, port: number, stop: () => Promise<unknown>;
7+
let ip: string, port: number, stop: (() => Promise<unknown>) | undefined;
88

99
beforeAll(async () => {
1010
({ ip, port, stop } = await runWranglerPagesDev(
@@ -15,7 +15,7 @@ describe("Pages Functions with wasm module imports", () => {
1515
});
1616

1717
afterAll(async () => {
18-
await stop();
18+
await stop?.();
1919
});
2020

2121
it("should render static pages", async ({ expect }) => {

fixtures/pages-functions-with-routes-app/tests/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { describe, it, beforeAll, afterAll } from "vitest";
44
import { runWranglerPagesDev } from "../../shared/src/run-wrangler-long-lived";
55

66
describe("Pages Functions with custom _routes.json", () => {
7-
let ip: string, port: number, stop: () => Promise<unknown>;
7+
let ip: string, port: number, stop: (() => Promise<unknown>) | undefined;
88

99
beforeAll(async () => {
1010
({ ip, port, stop } = await runWranglerPagesDev(
@@ -15,7 +15,7 @@ describe("Pages Functions with custom _routes.json", () => {
1515
});
1616

1717
afterAll(async () => {
18-
await stop();
18+
await stop?.();
1919
});
2020

2121
it("should render static pages", async ({ expect }) => {

fixtures/pages-simple-assets/tests/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { describe, it, afterAll, beforeAll } from "vitest";
44
import { runWranglerPagesDev } from "../../shared/src/run-wrangler-long-lived";
55

66
describe("Pages Functions", async () => {
7-
let ip: string, port: number, stop: () => Promise<unknown>;
7+
let ip: string, port: number, stop: (() => Promise<unknown>) | undefined;
88

99
beforeAll(async () => {
1010
({ ip, port, stop } = await runWranglerPagesDev(
@@ -15,7 +15,7 @@ describe("Pages Functions", async () => {
1515
});
1616

1717
afterAll(async () => {
18-
await stop();
18+
await stop?.();
1919
});
2020

2121
it("renders static pages", async ({ expect }) => {

fixtures/pages-workerjs-and-functions-app/tests/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { describe, it, beforeAll, afterAll } from "vitest";
44
import { runWranglerPagesDev } from "../../shared/src/run-wrangler-long-lived";
55

66
describe("Pages project with `_worker.js` and `/functions` directory", () => {
7-
let ip: string, port: number, stop: () => Promise<unknown>;
7+
let ip: string, port: number, stop: (() => Promise<unknown>) | undefined;
88

99
beforeAll(async () => {
1010
({ ip, port, stop } = await runWranglerPagesDev(
@@ -15,7 +15,7 @@ describe("Pages project with `_worker.js` and `/functions` directory", () => {
1515
});
1616

1717
afterAll(async () => {
18-
await stop();
18+
await stop?.();
1919
});
2020

2121
it("renders static pages", async ({ expect }) => {

fixtures/pages-workerjs-app/tests/index.test.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ describe("Pages _worker.js", () => {
3535
"./workerjs-test",
3636
["--no-bundle=false", "--port=0"]
3737
);
38-
await expect(
39-
fetch(`http://${ip}:${port}/`).then((resp) => resp.text())
40-
).resolves.toContain("test");
41-
await stop();
38+
try {
39+
await expect(
40+
fetch(`http://${ip}:${port}/`).then((resp) => resp.text())
41+
).resolves.toContain("test");
42+
} finally {
43+
await stop();
44+
}
4245
});
4346

4447
it("should not throw an error when the _worker.js file imports something if --bundle is true", async ({
@@ -49,9 +52,12 @@ describe("Pages _worker.js", () => {
4952
"./workerjs-test",
5053
["--bundle", "--port=0"]
5154
);
52-
await expect(
53-
fetch(`http://${ip}:${port}/`).then((resp) => resp.text())
54-
).resolves.toContain("test");
55-
await stop();
55+
try {
56+
await expect(
57+
fetch(`http://${ip}:${port}/`).then((resp) => resp.text())
58+
).resolves.toContain("test");
59+
} finally {
60+
await stop();
61+
}
5662
});
5763
});

fixtures/pages-workerjs-directory/tests/index.test.ts

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,41 @@ describe("Pages _worker.js/ directory", () => {
2424
"--r2=R2_REF=other_r2",
2525
]
2626
);
27-
await expect(
28-
fetch(`http://${ip}:${port}/`).then((resp) => resp.text())
29-
).resolves.toContain("Hello, world!");
30-
await expect(
31-
fetch(`http://${ip}:${port}/wasm`).then((resp) => resp.text())
32-
).resolves.toContain("3");
33-
await expect(
34-
fetch(`http://${ip}:${port}/static-js`).then((resp) => resp.text())
35-
).resolves.toEqual("static import text (via js): 'js static'");
36-
await expect(
37-
fetch(`http://${ip}:${port}/static-mjs`).then((resp) => resp.text())
38-
).resolves.toEqual("static import text (via mjs): 'mjs static'");
39-
await expect(
40-
fetch(`http://${ip}:${port}/other-script.js`).then((resp) => resp.text())
41-
).resolves.toContain("other-script-test");
42-
await expect(
43-
fetch(`http://${ip}:${port}/other-other-script.mjs`).then((resp) =>
44-
resp.text()
45-
)
46-
).resolves.toContain("other-other-script-test");
47-
await expect(
48-
fetch(`http://${ip}:${port}/d1`).then((resp) => resp.text())
49-
).resolves.toContain('{"1":1}');
50-
await expect(
51-
fetch(`http://${ip}:${port}/kv`).then((resp) => resp.text())
52-
).resolves.toContain("saved");
53-
await expect(
54-
fetch(`http://${ip}:${port}/r2`).then((resp) => resp.text())
55-
).resolves.toContain("saved");
56-
await stop();
27+
try {
28+
await expect(
29+
fetch(`http://${ip}:${port}/`).then((resp) => resp.text())
30+
).resolves.toContain("Hello, world!");
31+
await expect(
32+
fetch(`http://${ip}:${port}/wasm`).then((resp) => resp.text())
33+
).resolves.toContain("3");
34+
await expect(
35+
fetch(`http://${ip}:${port}/static-js`).then((resp) => resp.text())
36+
).resolves.toEqual("static import text (via js): 'js static'");
37+
await expect(
38+
fetch(`http://${ip}:${port}/static-mjs`).then((resp) => resp.text())
39+
).resolves.toEqual("static import text (via mjs): 'mjs static'");
40+
await expect(
41+
fetch(`http://${ip}:${port}/other-script.js`).then((resp) =>
42+
resp.text()
43+
)
44+
).resolves.toContain("other-script-test");
45+
await expect(
46+
fetch(`http://${ip}:${port}/other-other-script.mjs`).then((resp) =>
47+
resp.text()
48+
)
49+
).resolves.toContain("other-other-script-test");
50+
await expect(
51+
fetch(`http://${ip}:${port}/d1`).then((resp) => resp.text())
52+
).resolves.toContain('{"1":1}');
53+
await expect(
54+
fetch(`http://${ip}:${port}/kv`).then((resp) => resp.text())
55+
).resolves.toContain("saved");
56+
await expect(
57+
fetch(`http://${ip}:${port}/r2`).then((resp) => resp.text())
58+
).resolves.toContain("saved");
59+
} finally {
60+
await stop();
61+
}
5762

5863
expect(existsSync(join(tmpDir, "./v3/d1/D1"))).toBeTruthy();
5964
expect(existsSync(join(tmpDir, "./v3/d1/elsewhere"))).toBeTruthy();

fixtures/pages-workerjs-wasm-app/tests/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { describe, it, beforeAll, afterAll } from "vitest";
44
import { runWranglerPagesDev } from "../../shared/src/run-wrangler-long-lived";
55

66
describe("Pages Advanced Mode with wasm module imports", () => {
7-
let ip: string, port: number, stop: () => Promise<unknown>;
7+
let ip: string, port: number, stop: (() => Promise<unknown>) | undefined;
88

99
beforeAll(async () => {
1010
({ ip, port, stop } = await runWranglerPagesDev(
@@ -15,7 +15,7 @@ describe("Pages Advanced Mode with wasm module imports", () => {
1515
});
1616

1717
afterAll(async () => {
18-
await stop();
18+
await stop?.();
1919
});
2020

2121
it("should render static pages", async ({ expect }) => {

fixtures/pages-workerjs-with-routes-app/tests/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { describe, it, beforeAll, afterAll } from "vitest";
44
import { runWranglerPagesDev } from "../../shared/src/run-wrangler-long-lived";
55

66
describe("Pages Advanced Mode with custom _routes.json", () => {
7-
let ip: string, port: number, stop: () => Promise<unknown>;
7+
let ip: string, port: number, stop: (() => Promise<unknown>) | undefined;
88

99
beforeAll(async () => {
1010
({ ip, port, stop } = await runWranglerPagesDev(
@@ -15,7 +15,7 @@ describe("Pages Advanced Mode with custom _routes.json", () => {
1515
});
1616

1717
afterAll(async () => {
18-
await stop();
18+
await stop?.();
1919
});
2020

2121
it("renders static pages", async ({ expect }) => {

0 commit comments

Comments
 (0)