|
1 | 1 | import { mkdirSync, writeFileSync } from "node:fs";
|
2 | 2 | import { chdir } from "node:process";
|
| 3 | +import TOML from "@iarna/toml"; |
3 | 4 | import { execa } from "execa";
|
4 | 5 | import { http, HttpResponse } from "msw";
|
5 | 6 | import dedent from "ts-dedent";
|
@@ -74,7 +75,7 @@ describe("pages deploy", () => {
|
74 | 75 | --commit-message The commit message to attach to this deployment [string]
|
75 | 76 | --commit-dirty Whether or not the workspace should be considered dirty for this deployment [boolean]
|
76 | 77 | --skip-caching Skip asset caching which speeds up builds [boolean]
|
77 |
| - --no-bundle Whether to run bundling on \`_worker.js\` before deploying [boolean] [default: false] |
| 78 | + --no-bundle Whether to run bundling on \`_worker.js\` before deploying [boolean] |
78 | 79 | --upload-source-maps Whether to upload any server-side sourcemaps with this deployment [boolean] [default: false]"
|
79 | 80 | `);
|
80 | 81 | });
|
@@ -5425,6 +5426,51 @@ Failed to publish your Function. Got error: Uncaught TypeError: a is not a funct
|
5425 | 5426 | });
|
5426 | 5427 | });
|
5427 | 5428 |
|
| 5429 | + describe("_worker.js directory bundling", () => { |
| 5430 | + const workerIsBundled = async (contents: FormDataEntryValue | null) => |
| 5431 | + (await toString(contents)).includes("worker_default as default"); |
| 5432 | + |
| 5433 | + ["wrangler.json", "wrangler.toml"].forEach((configPath) => { |
| 5434 | + it( |
| 5435 | + "should not bundle the _worker.js when `no_bundle = true` in Wrangler config: " + |
| 5436 | + configPath, |
| 5437 | + async () => { |
| 5438 | + mkdirSync("public/_worker.js", { recursive: true }); |
| 5439 | + writeFileSync( |
| 5440 | + "public/_worker.js/index.js", |
| 5441 | + ` |
| 5442 | + export default { |
| 5443 | + async fetch(request, env) { |
| 5444 | + return new Response('Ok'); |
| 5445 | + } |
| 5446 | + }; |
| 5447 | + ` |
| 5448 | + ); |
| 5449 | + |
| 5450 | + const config = { |
| 5451 | + name: "foo", |
| 5452 | + no_bundle: true, |
| 5453 | + pages_build_output_dir: "public", |
| 5454 | + }; |
| 5455 | + writeFileSync( |
| 5456 | + `${configPath}`, |
| 5457 | + configPath === "wrangler.json" |
| 5458 | + ? JSON.stringify(config) |
| 5459 | + : TOML.stringify(config) |
| 5460 | + ); |
| 5461 | + |
| 5462 | + simulateServer((generatedWorkerJS) => |
| 5463 | + expect(workerIsBundled(generatedWorkerJS)).resolves.toBeFalsy() |
| 5464 | + ); |
| 5465 | + |
| 5466 | + await runWrangler("pages deploy"); |
| 5467 | + |
| 5468 | + expect(std.out).toContain("✨ Uploading Worker bundle"); |
| 5469 | + } |
| 5470 | + ); |
| 5471 | + }); |
| 5472 | + }); |
| 5473 | + |
5428 | 5474 | describe("source maps", () => {
|
5429 | 5475 | const bundleString = (entry: FormDataEntryValue | null) =>
|
5430 | 5476 | toString(entry).then((str) =>
|
|
0 commit comments