-
Notifications
You must be signed in to change notification settings - Fork 690
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
wrangler pages project validate [directory]
command (#3762)
* Add `wrangler pages project validate [directory]` command * Update packages/wrangler/src/pages/validate.tsx Co-authored-by: John Fawcett <jfawcett@cloudflare.com> * Add Pages team as codeowners of their own tests --------- Co-authored-by: John Fawcett <jfawcett@cloudflare.com>
- Loading branch information
1 parent
3bba1eb
commit 18dc7b5
Showing
7 changed files
with
213 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"wrangler": patch | ||
--- | ||
|
||
feat: Add internal `wrangler pages project validate [directory]` command which validates an asset directory |
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages/wrangler/src/__tests__/pages/project-validate.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// /* eslint-disable no-shadow */ | ||
import { writeFileSync } from "node:fs"; | ||
import { endEventLoop } from "../helpers/end-event-loop"; | ||
import { mockConsoleMethods } from "../helpers/mock-console"; | ||
import { runInTempDir } from "../helpers/run-in-tmp"; | ||
import { runWrangler } from "../helpers/run-wrangler"; | ||
|
||
jest.mock("../../pages/constants", () => ({ | ||
...jest.requireActual("../../pages/constants"), | ||
MAX_ASSET_SIZE: 1 * 1024 * 1024, | ||
MAX_ASSET_COUNT: 10, | ||
})); | ||
|
||
describe("project validate", () => { | ||
const std = mockConsoleMethods(); | ||
|
||
runInTempDir(); | ||
|
||
afterEach(async () => { | ||
// Force a tick to ensure that all promises resolve | ||
await endEventLoop(); | ||
}); | ||
|
||
it("should exit cleanly for a good directory", async () => { | ||
writeFileSync("logo.png", "foobar"); | ||
|
||
await runWrangler("pages project validate ."); | ||
|
||
expect(std.out).toMatchInlineSnapshot(`""`); | ||
expect(std.err).toMatchInlineSnapshot(`""`); | ||
}); | ||
|
||
it("should error for a large file", async () => { | ||
writeFileSync("logo.png", Buffer.alloc(1 * 1024 * 1024 + 1)); | ||
|
||
await expect(() => runWrangler("pages project validate .")).rejects | ||
.toThrowErrorMatchingInlineSnapshot(` | ||
"Error: Pages only supports files up to 1.05 MB in size | ||
logo.png is 1.05 MB in size" | ||
`); | ||
}); | ||
|
||
it("should error for a large directory", async () => { | ||
for (let i = 0; i < 10 + 1; i++) { | ||
writeFileSync(`logo${i}.png`, Buffer.alloc(1)); | ||
} | ||
|
||
await expect(() => | ||
runWrangler("pages project validate .") | ||
).rejects.toThrowErrorMatchingInlineSnapshot( | ||
`"Error: Pages only supports up to 10 files in a deployment. Ensure you have specified your build output directory correctly."` | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.