Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
petebacondarwin committed Jun 3, 2024
1 parent 7b77e6c commit 0c07af0
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
* So this helper removes these message from the snapshots to keep them consistent.
*/
export function normalizeProgressSteps(str: string): string {
return str.replace(/Uploading... \(\d\/\d\)\r?\n?/g, "");
return str.replace(/Uploading... \(\d+\/\d+\)\r?\n?/g, "");
}
72 changes: 72 additions & 0 deletions packages/wrangler/src/__tests__/pages/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,78 @@ describe("pages deploy", () => {
`);
});

it("should read files to upload in batches from disk to avoid EMFILE errors", async () => {
// Write more than 1000 files to disk
for (let i = 0; i < 4000; i++) {
writeFileSync(`logo-${i}.png`, "foobar".repeat(1000));
}
mockGetUploadTokenRequest(
"<<funfetti-auth-jwt>>",
"some-account-id",
"foo"
);

msw.use(
http.post(
"*/pages/assets/check-missing",
async ({ request }) => {
const body = (await request.json()) as {
hashes: string[];
};
return HttpResponse.json({
success: true,
errors: [],
messages: [],
result: body.hashes,
});
},
{ once: true }
),
http.post("*/pages/assets/upload", async () => {
return HttpResponse.json({
success: true,
errors: [],
messages: [],
result: null,
});
}),
http.post(
"*/accounts/:accountId/pages/projects/foo/deployments",
async () => {
return HttpResponse.json({
success: true,
errors: [],
messages: [],
result: {
url: "https://abcxyz.foo.pages.dev/",
},
});
},
{ once: true }
),
http.get("*/accounts/:accountId/pages/projects/foo", async () => {
return HttpResponse.json({
success: true,
errors: [],
messages: [],
result: { deployment_configs: { production: {}, preview: {} } },
});
})
);

await runWrangler("pages deploy . --project-name=foo");

expect(normalizeProgressSteps(std.out)).toMatchInlineSnapshot(`
"✨ Success! Uploaded 4000 files (TIMINGS)
🌎 Deploying...
✨ Deployment complete! However, we couldn't ascertain the final status of your deployment.
⚡️ Visit your deployment at https://abcxyz.foo.pages.dev/
⚡️ Check the deployment details on the Cloudflare dashboard: https://dash.cloudflare.com/some-account-id/pages/view/foo/undefined"
`);
});

it("should resolve child directories correctly", async () => {
mkdirSync("public");
mkdirSync("public/imgs");
Expand Down

0 comments on commit 0c07af0

Please sign in to comment.