|
| 1 | +import dedent from "ts-dedent"; |
| 2 | +import { afterAll, beforeAll, describe, expect, it } from "vitest"; |
| 3 | +import { CLOUDFLARE_ACCOUNT_ID } from "./helpers/account-id"; |
| 4 | +import { WranglerE2ETestHelper } from "./helpers/e2e-wrangler-test"; |
| 5 | +import { generateResourceName } from "./helpers/generate-resource-name"; |
| 6 | +import { normalizeOutput } from "./helpers/normalize"; |
| 7 | + |
| 8 | +const TIMEOUT = 50_000; |
| 9 | +const workerName = generateResourceName(); |
| 10 | +const normalize = (str: string) => |
| 11 | + normalizeOutput(str, { |
| 12 | + [CLOUDFLARE_ACCOUNT_ID]: "CLOUDFLARE_ACCOUNT_ID", |
| 13 | + }).replaceAll(/^Author:.*$/gm, "Author: [email protected]"); |
| 14 | + |
| 15 | +describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)("deploy", { timeout: TIMEOUT }, () => { |
| 16 | + let helper: WranglerE2ETestHelper; |
| 17 | + beforeAll(async () => { |
| 18 | + helper = new WranglerE2ETestHelper(); |
| 19 | + }); |
| 20 | + |
| 21 | + describe("subdomain warnings", () => { |
| 22 | + beforeAll(async () => { |
| 23 | + await helper.seed({ |
| 24 | + "wrangler.toml": dedent` |
| 25 | + name = "${workerName}" |
| 26 | + main = "src/index.ts" |
| 27 | + compatibility_date = "2023-01-01" |
| 28 | + `, |
| 29 | + "src/index.ts": dedent` |
| 30 | + export default { |
| 31 | + fetch(request) { |
| 32 | + return new Response("Hello World!") |
| 33 | + } |
| 34 | + } |
| 35 | + `, |
| 36 | + "package.json": dedent` |
| 37 | + { |
| 38 | + "name": "${workerName}", |
| 39 | + "version": "0.0.0", |
| 40 | + "private": true |
| 41 | + } |
| 42 | + `, |
| 43 | + }); |
| 44 | + }); |
| 45 | + |
| 46 | + afterAll(async () => { |
| 47 | + await helper.run(`wrangler delete`); |
| 48 | + }); |
| 49 | + |
| 50 | + it("omit subdomain warnings on 1st deploy", async () => { |
| 51 | + const deploy = await helper.run("wrangler deploy"); |
| 52 | + expect(normalize(deploy.stdout)).toMatchInlineSnapshot(` |
| 53 | + "Total Upload: xx KiB / gzip: xx KiB |
| 54 | + Uploaded tmp-e2e-worker-00000000-0000-0000-0000-000000000000 (TIMINGS) |
| 55 | + Deployed tmp-e2e-worker-00000000-0000-0000-0000-000000000000 triggers (TIMINGS) |
| 56 | + https://tmp-e2e-worker-00000000-0000-0000-0000-000000000000.SUBDOMAIN.workers.dev |
| 57 | + Current Version ID: 00000000-0000-0000-0000-000000000000" |
| 58 | + `); |
| 59 | + expect(normalize(deploy.stderr)).toMatchInlineSnapshot(`""`); |
| 60 | + }); |
| 61 | + |
| 62 | + it("show subdomain warnings on 2nd deploy, remote enabled", async () => { |
| 63 | + // Set remote state using `wrangler triggers deploy`. |
| 64 | + await helper.seed({ |
| 65 | + "wrangler.toml": dedent` |
| 66 | + name = "${workerName}" |
| 67 | + main = "src/index.ts" |
| 68 | + compatibility_date = "2023-01-01" |
| 69 | + workers_dev = true |
| 70 | + preview_urls = true |
| 71 | + `, |
| 72 | + }); |
| 73 | + await helper.run("wrangler triggers deploy"); |
| 74 | + // Remove `workers_dev` and `preview_urls` props, and redeploy. |
| 75 | + await helper.seed({ |
| 76 | + "wrangler.toml": dedent` |
| 77 | + name = "${workerName}" |
| 78 | + main = "src/index.ts" |
| 79 | + compatibility_date = "2023-01-01" |
| 80 | + `, |
| 81 | + }); |
| 82 | + const deploy = await helper.run("wrangler deploy"); |
| 83 | + expect(normalize(deploy.stdout)).toMatchInlineSnapshot(` |
| 84 | + "Total Upload: xx KiB / gzip: xx KiB |
| 85 | + Uploaded tmp-e2e-worker-00000000-0000-0000-0000-000000000000 (TIMINGS) |
| 86 | + Deployed tmp-e2e-worker-00000000-0000-0000-0000-000000000000 triggers (TIMINGS) |
| 87 | + https://tmp-e2e-worker-00000000-0000-0000-0000-000000000000.SUBDOMAIN.workers.dev |
| 88 | + Current Version ID: 00000000-0000-0000-0000-000000000000" |
| 89 | + `); |
| 90 | + expect(normalize(deploy.stderr)).toMatchInlineSnapshot(` |
| 91 | + "▲ [WARNING] Worker has preview URLs enabled, but 'preview_urls' is not in the config. |
| 92 | + Using default config 'preview_urls = false', current status will be overwritten." |
| 93 | + `); |
| 94 | + }); |
| 95 | + |
| 96 | + it("show subdomain warnings on 3rd deploy, remote disabled", async () => { |
| 97 | + // Set remote state using `wrangler triggers deploy`. |
| 98 | + await helper.seed({ |
| 99 | + "wrangler.toml": dedent` |
| 100 | + name = "${workerName}" |
| 101 | + main = "src/index.ts" |
| 102 | + compatibility_date = "2023-01-01" |
| 103 | + workers_dev = false |
| 104 | + preview_urls = false |
| 105 | + `, |
| 106 | + }); |
| 107 | + await helper.run("wrangler triggers deploy"); |
| 108 | + // Remove `workers_dev` and `preview_urls` props, and redeploy. |
| 109 | + await helper.seed({ |
| 110 | + "wrangler.toml": dedent` |
| 111 | + name = "${workerName}" |
| 112 | + main = "src/index.ts" |
| 113 | + compatibility_date = "2023-01-01" |
| 114 | + `, |
| 115 | + }); |
| 116 | + const deploy = await helper.run("wrangler deploy"); |
| 117 | + expect(normalize(deploy.stdout)).toMatchInlineSnapshot(` |
| 118 | + "Total Upload: xx KiB / gzip: xx KiB |
| 119 | + Uploaded tmp-e2e-worker-00000000-0000-0000-0000-000000000000 (TIMINGS) |
| 120 | + Deployed tmp-e2e-worker-00000000-0000-0000-0000-000000000000 triggers (TIMINGS) |
| 121 | + https://tmp-e2e-worker-00000000-0000-0000-0000-000000000000.SUBDOMAIN.workers.dev |
| 122 | + Current Version ID: 00000000-0000-0000-0000-000000000000" |
| 123 | + `); |
| 124 | + expect(normalize(deploy.stderr)).toMatchInlineSnapshot(` |
| 125 | + "▲ [WARNING] Worker has workers.dev disabled, but 'workers_dev' is not in the config. |
| 126 | + Using default config 'workers_dev = true', current status will be overwritten." |
| 127 | + `); |
| 128 | + }); |
| 129 | + }); |
| 130 | +}); |
0 commit comments