Skip to content

Commit adf3d6c

Browse files
fixup! test: add test cases for run_worker_first routes behaviour
1 parent d0b7ac4 commit adf3d6c

File tree

1 file changed

+47
-42
lines changed

1 file changed

+47
-42
lines changed

packages/wrangler/e2e/deployments.test.ts

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -224,19 +224,27 @@ const checkAssets = async (testCases: AssetTestCase[], deployedUrl: string) => {
224224
const url = r.url;
225225

226226
if (testCase.content) {
227-
expect(text).toContain(testCase.content);
227+
expect(
228+
text,
229+
`expected content for ${testCase.path} to be ${testCase.content}`
230+
).toContain(testCase.content);
228231
}
229232
if (testCase.redirect) {
230-
expect(new URL(url).pathname).toEqual(
231-
new URL(testCase.redirect, deployedUrl).pathname
232-
);
233+
expect(
234+
new URL(url).pathname,
235+
`expected redirect for ${testCase.path} to be ${testCase.redirect}`
236+
).toEqual(new URL(testCase.redirect, deployedUrl).pathname);
233237
} else {
234-
expect(new URL(url).pathname).toEqual(
235-
new URL(testCase.path, deployedUrl).pathname
236-
);
238+
expect(
239+
new URL(url).pathname,
240+
`unexpected pathname for ${testCase.path}`
241+
).toEqual(new URL(testCase.path, deployedUrl).pathname);
237242
}
238243
},
239-
{ interval: 1_000, timeout: 40_000 }
244+
{
245+
interval: 1_000,
246+
timeout: 40_000,
247+
}
240248
);
241249
}
242250
};
@@ -570,7 +578,7 @@ Current Version ID: 00000000-0000-0000-0000-000000000000`);
570578
await checkAssets(testCases, deployedUrl);
571579
});
572580

573-
it("runs the user Worker ahead of matching assets for matching run_worker_first routes", async () => {
581+
it.only("runs the user Worker ahead of matching assets for matching run_worker_first routes", async () => {
574582
await helper.seed({
575583
"wrangler.toml": dedent`
576584
name = "${workerName}"
@@ -581,7 +589,7 @@ Current Version ID: 00000000-0000-0000-0000-000000000000`);
581589
binding = "ASSETS"
582590
html_handling = "none"
583591
not_found_handling = "404-page"
584-
run_worker_first = ["api/*", "!api/assets/*"]
592+
run_worker_first = ["/api/*", "!/api/assets/*"]
585593
`,
586594
"src/index.ts": dedent`
587595
export default {
@@ -598,7 +606,28 @@ Current Version ID: 00000000-0000-0000-0000-000000000000`);
598606
const output = await helper.run(`wrangler deploy`);
599607
const normalizedStdout = normalize(output.stdout);
600608

601-
expect(normalizedStdout).toMatchInlineSnapshot(`""`);
609+
expect(normalizedStdout).toContain(dedent`
610+
🌀 Building list of assets...
611+
✨ Read 7 files from the assets directory /tmpdir
612+
🌀 Starting asset upload...
613+
🌀 Found 5 new or modified static assets to upload. Proceeding with upload...
614+
+ /404.html
615+
+ /api/index.html
616+
+ /index.html
617+
+ /api/assets/test.html
618+
+ /[boop].html
619+
`);
620+
expect(normalizedStdout).toContain(dedent`
621+
✨ Success! Uploaded 5 files (TIMINGS)
622+
Total Upload: xx KiB / gzip: xx KiB
623+
Your Worker has access to the following bindings:
624+
Binding Resource
625+
env.ASSETS Assets
626+
Uploaded tmp-e2e-worker-00000000-0000-0000-0000-000000000000 (TIMINGS)
627+
Deployed tmp-e2e-worker-00000000-0000-0000-0000-000000000000 triggers (TIMINGS)
628+
https://tmp-e2e-worker-00000000-0000-0000-0000-000000000000.SUBDOMAIN.workers.dev
629+
Current Version ID: 00000000-0000-0000-0000-000000000000
630+
`);
602631

603632
const match = output.stdout.match(
604633
/(?<url>https:\/\/tmp-e2e-.+?\..+?\.workers\.dev)/
@@ -607,38 +636,14 @@ Current Version ID: 00000000-0000-0000-0000-000000000000`);
607636
deployedUrl = match.groups.url;
608637

609638
const testCases: AssetTestCase[] = [
610-
{
611-
path: "/index.html",
612-
content: "<h1>index.html</h1>",
613-
redirect: "/",
614-
},
615-
{
616-
path: "/[boop]",
617-
content: "<h1>[boop].html</h1>",
618-
redirect: "/%5Bboop%5D",
619-
},
620-
{
621-
path: "/missing.html",
622-
content: "<h1>404.html</h1>",
623-
redirect: "/",
624-
},
625-
{
626-
path: "/api",
627-
content: "Hello World from User Worker!",
628-
},
629-
{
630-
path: "/api/foo.html",
631-
content: "Hello World from User Worker!",
632-
},
633-
{
634-
path: "/api/assets",
635-
content: "404.html",
636-
},
637-
{
638-
path: "/api/assets/test.html",
639-
content: "api/assets/test.html",
640-
},
639+
{ path: "/index.html", content: "<h1>index.html</h1>" },
640+
{ path: "/missing.html", content: "<h1>404.html</h1>" },
641+
{ path: "/api/", content: "Hello World from User Worker!" },
642+
{ path: "/api/foo.html", content: "Hello World from User Worker!" },
643+
{ path: "/api/assets/missing", content: "404.html" },
644+
{ path: "/api/assets/test.html", content: "api/assets/test.html" },
641645
];
646+
642647
await checkAssets(testCases, deployedUrl);
643648
});
644649
});

0 commit comments

Comments
 (0)