Skip to content

Commit a5eb9c4

Browse files
Edge preview authentication proxy - retry failed tests (#12751)
1 parent 6f0a27b commit a5eb9c4

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

packages/edge-preview-authenticated-proxy/tests/index.test.ts

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,15 @@ function createMockFetchImplementation() {
1818
const request = new Request(input, init);
1919
const url = new URL(request.url);
2020

21+
if (url.origin === "https://workers-logging.cfdata.org") {
22+
// Ignore prometheus logging requests
23+
return new Response("OK", { status: 200 });
24+
}
25+
2126
// Only intercept requests to our mock remote URL
2227
if (url.origin !== MOCK_REMOTE_URL) {
23-
return new Response("OK", { status: 200 });
28+
console.error(`Request to unexpected URL: ${request.url}`);
29+
return new Response("BAD", { status: 500 });
2430
}
2531

2632
if (url.pathname === "/exchange") {
@@ -80,8 +86,6 @@ afterEach(() => {
8086
});
8187

8288
describe("Preview Worker", () => {
83-
let tokenId: string | null = null;
84-
8589
it("should obtain token from exchange_url", async ({ expect }) => {
8690
const resp = await SELF.fetch(
8791
`https://preview.devprod.cloudflare.dev/exchange?exchange_url=${encodeURIComponent(
@@ -139,7 +143,7 @@ describe("Preview Worker", () => {
139143
).toMatchInlineSnapshot(
140144
'"token=00000000-0000-0000-0000-000000000000; Domain=random-data.preview.devprod.cloudflare.dev; HttpOnly; Secure; Partitioned; SameSite=None"'
141145
);
142-
tokenId = (resp.headers.get("set-cookie") ?? "")
146+
const tokenId = (resp.headers.get("set-cookie") ?? "")
143147
.split(";")[0]
144148
.split("=")[1];
145149
resp = await SELF.fetch(
@@ -152,9 +156,7 @@ describe("Preview Worker", () => {
152156
}
153157
);
154158

155-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ignoring this test type error for sake of turborepo PR
156-
const json = (await resp.json()) as any;
157-
159+
const json = await resp.json();
158160
expect(json).toMatchObject({
159161
url: `${MOCK_REMOTE_URL}/`,
160162
headers: expect.arrayContaining([["cf-workers-preview-token", token]]),
@@ -180,10 +182,22 @@ describe("Preview Worker", () => {
180182
).toMatchInlineSnapshot(
181183
'"token=00000000-0000-0000-0000-000000000000; Domain=random-data.preview.devprod.cloudflare.dev; HttpOnly; Secure; Partitioned; SameSite=None"'
182184
);
183-
tokenId = (resp.headers.get("set-cookie") ?? "")
184-
.split(";")[0]
185-
.split("=")[1];
186185
});
186+
187+
async function getToken() {
188+
const resp = await SELF.fetch(
189+
`https://random-data.preview.devprod.cloudflare.dev/.update-preview-token?token=TEST_TOKEN&prewarm=${encodeURIComponent(
190+
`${MOCK_REMOTE_URL}/prewarm`
191+
)}&remote=${encodeURIComponent(
192+
MOCK_REMOTE_URL
193+
)}&suffix=${encodeURIComponent("/hello?world")}`,
194+
{
195+
method: "GET",
196+
redirect: "manual",
197+
}
198+
);
199+
return (resp.headers.get("set-cookie") ?? "").split(";")[0].split("=")[1];
200+
}
187201
it("should reject invalid prewarm url", async ({ expect }) => {
188202
vi.spyOn(console, "error").mockImplementation(() => {});
189203
const resp = await SELF.fetch(
@@ -210,6 +224,7 @@ describe("Preview Worker", () => {
210224
});
211225

212226
it("should convert cookie to header", async ({ expect }) => {
227+
const tokenId = await getToken();
213228
const resp = await SELF.fetch(
214229
`https://random-data.preview.devprod.cloudflare.dev`,
215230
{
@@ -229,6 +244,7 @@ describe("Preview Worker", () => {
229244
});
230245
});
231246
it("should not follow redirects", async ({ expect }) => {
247+
const tokenId = await getToken();
232248
const resp = await SELF.fetch(
233249
`https://random-data.preview.devprod.cloudflare.dev/redirect`,
234250
{
@@ -247,6 +263,7 @@ describe("Preview Worker", () => {
247263
expect(await resp.text()).toMatchInlineSnapshot('""');
248264
});
249265
it("should return method", async ({ expect }) => {
266+
const tokenId = await getToken();
250267
const resp = await SELF.fetch(
251268
`https://random-data.preview.devprod.cloudflare.dev/method`,
252269
{
@@ -261,6 +278,7 @@ describe("Preview Worker", () => {
261278
expect(await resp.text()).toMatchInlineSnapshot('"PUT"');
262279
});
263280
it("should return header", async ({ expect }) => {
281+
const tokenId = await getToken();
264282
const resp = await SELF.fetch(
265283
`https://random-data.preview.devprod.cloudflare.dev/header`,
266284
{
@@ -276,6 +294,7 @@ describe("Preview Worker", () => {
276294
expect(await resp.text()).toMatchInlineSnapshot('"custom"');
277295
});
278296
it("should return status", async ({ expect }) => {
297+
const tokenId = await getToken();
279298
const resp = await SELF.fetch(
280299
`https://random-data.preview.devprod.cloudflare.dev/status`,
281300
{

packages/edge-preview-authenticated-proxy/vitest.config.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default defineWorkersConfig({
1515
},
1616
},
1717
},
18+
retry: 2,
1819
},
1920
resolve: {
2021
// promjs has broken package.json (main points to lib/index.js but files are at root)

0 commit comments

Comments
 (0)