wrangler 0.0.0-e178d6fb → 0.0.0-e1c2f5b9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (239) hide show
  1. package/README.md +16 -2
  2. package/bin/wrangler.js +31 -11
  3. package/miniflare-dist/index.mjs +1340 -330
  4. package/package.json +40 -13
  5. package/src/__tests__/access.test.ts +25 -0
  6. package/src/__tests__/api-dev.test.ts +238 -0
  7. package/src/__tests__/api-devregistry.test.js +64 -0
  8. package/src/__tests__/api.test.ts +80 -0
  9. package/src/__tests__/configuration.test.ts +683 -470
  10. package/src/__tests__/d1.test.ts +123 -0
  11. package/src/__tests__/delete.test.ts +263 -0
  12. package/src/__tests__/deployments.test.ts +105 -0
  13. package/src/__tests__/dev.test.tsx +453 -70
  14. package/src/__tests__/dialogs.test.tsx +40 -0
  15. package/src/__tests__/generate.test.ts +235 -0
  16. package/src/__tests__/get-host-from-url.test.ts +16 -0
  17. package/src/__tests__/helpers/mock-auth-domain.ts +20 -0
  18. package/src/__tests__/helpers/mock-cfetch.ts +92 -26
  19. package/src/__tests__/helpers/mock-console.ts +11 -2
  20. package/src/__tests__/helpers/mock-dialogs.ts +1 -1
  21. package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -0
  22. package/src/__tests__/helpers/mock-known-routes.ts +7 -0
  23. package/src/__tests__/helpers/mock-kv.ts +1 -1
  24. package/src/__tests__/helpers/mock-oauth-flow.ts +74 -53
  25. package/src/__tests__/helpers/mock-process.ts +8 -13
  26. package/src/__tests__/helpers/msw/handlers/access.ts +13 -0
  27. package/src/__tests__/helpers/msw/handlers/deployments.ts +59 -0
  28. package/src/__tests__/helpers/msw/handlers/namespaces.ts +104 -0
  29. package/src/__tests__/helpers/msw/handlers/oauth.ts +31 -0
  30. package/src/__tests__/helpers/msw/handlers/r2.ts +80 -0
  31. package/src/__tests__/helpers/msw/handlers/script.ts +75 -0
  32. package/src/__tests__/helpers/msw/handlers/user.ts +63 -0
  33. package/src/__tests__/helpers/msw/handlers/zones.ts +22 -0
  34. package/src/__tests__/helpers/msw/index.ts +21 -0
  35. package/src/__tests__/helpers/worker-scripts/child-wrangler.toml +1 -0
  36. package/src/__tests__/helpers/worker-scripts/hello-world-worker.js +5 -0
  37. package/src/__tests__/helpers/worker-scripts/hello-world-wrangler.toml +1 -0
  38. package/src/__tests__/helpers/worker-scripts/parent-worker.js +8 -0
  39. package/src/__tests__/helpers/worker-scripts/parent-wrangler.toml +5 -0
  40. package/src/__tests__/index.test.ts +103 -97
  41. package/src/__tests__/init.test.ts +1484 -382
  42. package/src/__tests__/jest.setup.ts +88 -5
  43. package/src/__tests__/kv.test.ts +655 -540
  44. package/src/__tests__/logout.test.ts +47 -0
  45. package/src/__tests__/metrics.test.ts +95 -45
  46. package/src/__tests__/middleware.scheduled.test.ts +145 -0
  47. package/src/__tests__/middleware.test.ts +750 -0
  48. package/src/__tests__/pages-deployment-tail.test.ts +884 -0
  49. package/src/__tests__/pages.test.ts +1301 -119
  50. package/src/__tests__/paths.test.ts +39 -0
  51. package/src/__tests__/publish.test.ts +2266 -1180
  52. package/src/__tests__/pubsub.test.ts +211 -88
  53. package/src/__tests__/queues.test.ts +522 -0
  54. package/src/__tests__/r2.test.ts +363 -203
  55. package/src/__tests__/secret.test.ts +261 -59
  56. package/src/__tests__/tail.test.ts +352 -151
  57. package/src/__tests__/test-old-node-version.js +3 -3
  58. package/src/__tests__/tsconfig-sanity.ts +12 -0
  59. package/src/__tests__/tsconfig.json +8 -0
  60. package/src/__tests__/tsconfig.tsbuildinfo +1 -0
  61. package/src/__tests__/type-generation.test.ts +233 -0
  62. package/src/__tests__/user.test.ts +59 -73
  63. package/src/__tests__/utils-collectKeyValues.test.ts +47 -0
  64. package/src/__tests__/validate-dev-props.test.ts +56 -0
  65. package/src/__tests__/whoami.test.tsx +114 -66
  66. package/src/__tests__/worker-namespace.test.ts +154 -155
  67. package/src/api/dev.ts +170 -38
  68. package/src/api/index.ts +1 -0
  69. package/src/bundle-reporter.tsx +41 -2
  70. package/src/bundle.ts +668 -81
  71. package/src/cfetch/index.ts +40 -3
  72. package/src/cfetch/internal.ts +144 -32
  73. package/src/cli.ts +4 -3
  74. package/src/config/config.ts +27 -3
  75. package/src/config/environment.ts +131 -7
  76. package/src/config/index.ts +128 -8
  77. package/src/config/validation-helpers.ts +19 -6
  78. package/src/config/validation.ts +411 -14
  79. package/src/config-cache.ts +3 -2
  80. package/src/create-worker-preview.ts +31 -6
  81. package/src/create-worker-upload-form.ts +84 -22
  82. package/src/d1/backups.tsx +223 -0
  83. package/src/d1/constants.ts +2 -0
  84. package/src/d1/create.tsx +63 -0
  85. package/src/d1/delete.tsx +56 -0
  86. package/src/d1/execute.tsx +352 -0
  87. package/src/d1/formatTimeAgo.ts +14 -0
  88. package/src/d1/index.ts +101 -0
  89. package/src/d1/list.tsx +48 -0
  90. package/src/d1/migrations/apply.tsx +196 -0
  91. package/src/d1/migrations/create.tsx +77 -0
  92. package/src/d1/migrations/helpers.ts +147 -0
  93. package/src/d1/migrations/index.tsx +3 -0
  94. package/src/d1/migrations/list.tsx +79 -0
  95. package/src/d1/migrations/options.ts +18 -0
  96. package/src/d1/options.ts +22 -0
  97. package/src/d1/types.tsx +24 -0
  98. package/src/d1/utils.ts +48 -0
  99. package/src/delete.ts +108 -0
  100. package/src/deployments.ts +83 -0
  101. package/src/deprecated/index.ts +145 -0
  102. package/src/dev/dev-vars.ts +11 -8
  103. package/src/dev/dev.tsx +220 -58
  104. package/src/dev/get-local-persistence-path.tsx +31 -0
  105. package/src/dev/local.tsx +740 -181
  106. package/src/dev/remote.tsx +340 -123
  107. package/src/dev/start-server.ts +543 -0
  108. package/src/dev/use-esbuild.ts +61 -7
  109. package/src/dev/validate-dev-props.ts +31 -0
  110. package/src/dev-registry.tsx +201 -0
  111. package/src/dev.tsx +614 -258
  112. package/src/dialogs.tsx +41 -8
  113. package/src/{worker-namespace.ts → dispatch-namespace.ts} +23 -22
  114. package/src/docs/index.ts +97 -0
  115. package/src/entry.ts +3 -2
  116. package/src/environment-variables/factory.ts +88 -0
  117. package/src/environment-variables/misc-variables.ts +30 -0
  118. package/src/generate/index.ts +300 -0
  119. package/src/git-client.ts +100 -7
  120. package/src/index.tsx +249 -1560
  121. package/src/init.ts +626 -150
  122. package/src/inspect.ts +137 -32
  123. package/src/{metrics/is-ci.ts → is-ci.ts} +0 -0
  124. package/src/is-interactive.ts +4 -0
  125. package/src/jest.d.ts +4 -0
  126. package/src/{kv.ts → kv/helpers.ts} +3 -3
  127. package/src/kv/index.ts +596 -0
  128. package/src/logger.ts +27 -8
  129. package/src/metrics/index.ts +1 -0
  130. package/src/metrics/metrics-config.ts +4 -4
  131. package/src/metrics/metrics-dispatcher.ts +1 -0
  132. package/src/metrics/metrics-usage-headers.ts +24 -0
  133. package/src/metrics/send-event.ts +13 -8
  134. package/src/miniflare-cli/assets.ts +172 -465
  135. package/src/miniflare-cli/index.ts +149 -24
  136. package/src/miniflare-cli/tsconfig.json +9 -0
  137. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -0
  138. package/src/miniflare-cli/types.ts +11 -0
  139. package/src/module-collection.ts +12 -3
  140. package/src/pages/build.tsx +108 -42
  141. package/src/pages/constants.ts +11 -0
  142. package/src/pages/deployment-tails.tsx +284 -0
  143. package/src/pages/deployments.tsx +9 -31
  144. package/src/pages/dev.tsx +417 -108
  145. package/src/pages/errors.ts +66 -0
  146. package/src/pages/functions/buildPlugin.ts +86 -84
  147. package/src/pages/functions/buildWorker.ts +121 -106
  148. package/src/pages/functions/routes-consolidation.test.ts +250 -0
  149. package/src/pages/functions/routes-consolidation.ts +73 -0
  150. package/src/pages/functions/routes-transformation.test.ts +282 -0
  151. package/src/pages/functions/routes-transformation.ts +115 -0
  152. package/src/pages/functions/routes-validation.test.ts +403 -0
  153. package/src/pages/functions/routes-validation.ts +202 -0
  154. package/src/pages/functions/tsconfig.json +8 -0
  155. package/src/pages/functions/tsconfig.tsbuildinfo +1 -0
  156. package/src/pages/functions.tsx +82 -0
  157. package/src/pages/hash.tsx +13 -0
  158. package/src/pages/index.tsx +73 -55
  159. package/src/pages/projects.tsx +9 -3
  160. package/src/pages/prompt-select-project.tsx +31 -0
  161. package/src/pages/publish.tsx +183 -60
  162. package/src/pages/types.ts +1 -0
  163. package/src/pages/upload.tsx +107 -56
  164. package/src/pages/utils.ts +13 -2
  165. package/src/paths.ts +49 -4
  166. package/src/proxy.ts +375 -157
  167. package/src/publish/index.ts +270 -0
  168. package/src/{publish.ts → publish/publish.ts} +431 -188
  169. package/src/pubsub/pubsub-commands.tsx +4 -3
  170. package/src/queues/cli/commands/consumer/add.ts +71 -0
  171. package/src/queues/cli/commands/consumer/index.ts +22 -0
  172. package/src/queues/cli/commands/consumer/remove.ts +38 -0
  173. package/src/queues/cli/commands/create.ts +25 -0
  174. package/src/queues/cli/commands/delete.ts +26 -0
  175. package/src/queues/cli/commands/index.ts +36 -0
  176. package/src/queues/cli/commands/list.ts +25 -0
  177. package/src/queues/client.ts +135 -0
  178. package/src/queues/utils.ts +18 -0
  179. package/src/r2/constants.ts +4 -0
  180. package/src/r2/helpers.ts +131 -0
  181. package/src/r2/index.ts +289 -0
  182. package/src/routes.ts +140 -0
  183. package/src/secret/index.ts +379 -0
  184. package/src/sites.tsx +3 -3
  185. package/src/tail/createTail.ts +379 -0
  186. package/src/tail/filters.ts +4 -6
  187. package/src/tail/index.ts +199 -284
  188. package/src/tail/printing.ts +43 -3
  189. package/src/tsconfig-sanity.ts +16 -0
  190. package/src/type-generation.ts +181 -0
  191. package/src/user/access.ts +68 -0
  192. package/src/user/auth-variables.ts +113 -0
  193. package/src/user/choose-account.tsx +1 -1
  194. package/src/user/index.ts +0 -1
  195. package/src/user/user.tsx +116 -49
  196. package/src/utils/collectKeyValues.ts +14 -0
  197. package/src/whoami.tsx +80 -2
  198. package/src/worker.ts +69 -9
  199. package/src/yargs-types.ts +24 -0
  200. package/src/zones.ts +124 -9
  201. package/templates/__tests__/pages-dev-util.test.ts +128 -0
  202. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  203. package/templates/__tests__/tsconfig.json +8 -0
  204. package/templates/__tests__/tsconfig.tsbuildinfo +1 -0
  205. package/templates/d1-beta-facade.js +205 -0
  206. package/templates/facade.d.ts +14 -0
  207. package/templates/first-party-worker-module-facade.ts +19 -0
  208. package/templates/format-dev-errors.ts +33 -0
  209. package/templates/init-tests/test-jest-new-worker.js +23 -0
  210. package/templates/init-tests/test-vitest-new-worker.js +24 -0
  211. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  212. package/templates/middleware/common.ts +62 -0
  213. package/templates/middleware/loader-modules.ts +82 -0
  214. package/templates/middleware/loader-sw.ts +233 -0
  215. package/templates/middleware/middleware-miniflare3-json-error.ts +20 -0
  216. package/templates/middleware/middleware-pretty-error.ts +40 -0
  217. package/templates/middleware/middleware-scheduled.ts +15 -0
  218. package/templates/new-worker.js +1 -1
  219. package/templates/pages-dev-pipeline.ts +31 -0
  220. package/templates/pages-dev-util.ts +52 -0
  221. package/templates/pages-shim.ts +4 -1
  222. package/templates/pages-template-plugin.ts +21 -5
  223. package/templates/pages-template-worker.ts +37 -9
  224. package/templates/{static-asset-facade.js → serve-static-assets.ts} +23 -7
  225. package/templates/service-bindings-module-facade.js +54 -0
  226. package/templates/service-bindings-sw-facade.js +42 -0
  227. package/templates/tsconfig-sanity.ts +11 -0
  228. package/templates/tsconfig.init.json +106 -0
  229. package/templates/tsconfig.json +5 -102
  230. package/templates/tsconfig.tsbuildinfo +1 -0
  231. package/wrangler-dist/cli.d.ts +621 -42
  232. package/wrangler-dist/cli.js +144441 -102606
  233. package/src/environment-variables.ts +0 -35
  234. package/src/faye-websocket.d.ts +0 -6
  235. package/src/generate.ts +0 -33
  236. package/src/miniflare-cli/enum-keys.ts +0 -17
  237. package/src/preview.ts +0 -31
  238. package/src/r2.ts +0 -50
  239. package/src/user/env-vars.ts +0 -46
@@ -1,19 +1,32 @@
1
+ import { Buffer } from "node:buffer";
2
+ import { randomFillSync } from "node:crypto";
1
3
  import * as fs from "node:fs";
2
4
  import * as path from "node:path";
3
5
  import * as TOML from "@iarna/toml";
4
6
  import * as esbuild from "esbuild";
7
+ import {
8
+ printBundleSize,
9
+ printOffendingDependencies,
10
+ } from "../bundle-reporter";
5
11
  import { writeAuthConfigFile } from "../user";
6
12
  import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
13
+ import { mockAuthDomain } from "./helpers/mock-auth-domain";
7
14
  import {
8
15
  createFetchResult,
9
16
  setMockRawResponse,
10
17
  setMockResponse,
11
18
  unsetAllMocks,
12
- unsetMockFetchKVGetValues,
19
+ unsetSpecialMockFns,
13
20
  } from "./helpers/mock-cfetch";
14
- import { mockConsoleMethods, normalizeSlashes } from "./helpers/mock-console";
21
+ import {
22
+ mockConsoleMethods,
23
+ normalizeSlashes,
24
+ normalizeTempDirs,
25
+ } from "./helpers/mock-console";
15
26
  import { mockConfirm } from "./helpers/mock-dialogs";
27
+ import { mockGetZoneFromHostRequest } from "./helpers/mock-get-zone-from-host";
16
28
  import { useMockIsTTY } from "./helpers/mock-istty";
29
+ import { mockCollectKnownRoutesRequest } from "./helpers/mock-known-routes";
17
30
  import { mockKeyListRequest } from "./helpers/mock-kv";
18
31
  import { mockGetMemberships, mockOAuthFlow } from "./helpers/mock-oauth-flow";
19
32
  import { runInTempDir } from "./helpers/run-in-tmp";
@@ -22,7 +35,9 @@ import { writeWorkerSource } from "./helpers/write-worker-source";
22
35
  import writeWranglerToml from "./helpers/write-wrangler-toml";
23
36
  import type { Config } from "../config";
24
37
  import type { WorkerMetadata } from "../create-worker-upload-form";
25
- import type { KVNamespaceInfo } from "../kv";
38
+ import type { KVNamespaceInfo } from "../kv/helpers";
39
+ import type { CustomDomainChangeset, CustomDomain } from "../publish/publish";
40
+ import type { PutConsumerBody } from "../queues/client";
26
41
  import type { CfWorkerInit } from "../worker";
27
42
  import type { FormData, File } from "undici";
28
43
 
@@ -33,6 +48,7 @@ describe("publish", () => {
33
48
  const { setIsTTY } = useMockIsTTY();
34
49
  const std = mockConsoleMethods();
35
50
  const {
51
+ mockDomainUsesAccess,
36
52
  mockOAuthServerCallback,
37
53
  mockGrantAccessToken,
38
54
  mockGrantAuthorization,
@@ -44,19 +60,40 @@ describe("publish", () => {
44
60
  setImmediate(fn);
45
61
  });
46
62
  setIsTTY(true);
63
+ setMockResponse(
64
+ "/accounts/:accountId/workers/services/:scriptName",
65
+ () => ({
66
+ default_environment: { script: { last_deployed_from: "dash" } },
67
+ })
68
+ );
69
+ setMockResponse(
70
+ "/accounts/:accountId/workers/deployments/by-script/:scriptTag",
71
+ () => ({
72
+ latest: { number: "2" },
73
+ })
74
+ );
47
75
  });
48
76
 
49
77
  afterEach(() => {
50
78
  unsetAllMocks();
51
- unsetMockFetchKVGetValues();
79
+ unsetSpecialMockFns();
52
80
  });
53
81
 
54
82
  describe("output additional script information", () => {
55
83
  mockApiToken();
56
84
 
57
- it("should print worker information at log level", async () => {
85
+ it("for first party workers, it should print worker information at log level", async () => {
58
86
  setIsTTY(false);
59
- writeWranglerToml();
87
+ fs.writeFileSync(
88
+ "./wrangler.toml",
89
+ TOML.stringify({
90
+ compatibility_date: "2022-01-12",
91
+ name: "test-name",
92
+ first_party_worker: true,
93
+ }),
94
+
95
+ "utf-8"
96
+ );
60
97
  writeWorkerSource();
61
98
  mockSubDomainRequest();
62
99
  mockUploadWorkerRequest({ expectedType: "esm", sendScriptIds: true });
@@ -65,13 +102,14 @@ describe("publish", () => {
65
102
  await runWrangler("publish ./index");
66
103
 
67
104
  expect(std.out).toMatchInlineSnapshot(`
68
- "Total Upload: 0xx KiB / gzip: 0xx KiB
105
+ "Total Upload: xx KiB / gzip: xx KiB
69
106
  Worker ID: abc12345
70
107
  Worker ETag: etag98765
71
108
  Worker PipelineHash: hash9999
72
109
  Uploaded test-name (TIMINGS)
73
110
  Published test-name (TIMINGS)
74
- test-name.test-sub-domain.workers.dev"
111
+ https://test-name.test-sub-domain.workers.dev
112
+ Current Deployment ID: undefined"
75
113
  `);
76
114
  });
77
115
  });
@@ -88,6 +126,7 @@ describe("publish", () => {
88
126
  it("drops a user into the login flow if they're unauthenticated", async () => {
89
127
  writeWranglerToml();
90
128
  writeWorkerSource();
129
+ mockDomainUsesAccess({ usesAccess: false });
91
130
  mockSubDomainRequest();
92
131
  mockUploadWorkerRequest();
93
132
  mockOAuthServerCallback();
@@ -101,18 +140,59 @@ describe("publish", () => {
101
140
  );
102
141
 
103
142
  expect(std.out).toMatchInlineSnapshot(`
104
- "Attempting to login via OAuth...
105
- Opening a link in your default browser: https://dash.cloudflare.com/oauth2/auth?response_type=code&client_id=54d11594-84e4-41aa-b438-e81b8fa78ee7&redirect_uri=http%3A%2F%2Flocalhost%3A8976%2Foauth%2Fcallback&scope=account%3Aread%20user%3Aread%20workers%3Awrite%20workers_kv%3Awrite%20workers_routes%3Awrite%20workers_scripts%3Awrite%20workers_tail%3Aread%20pages%3Awrite%20zone%3Aread%20offline_access&state=MOCK_STATE_PARAM&code_challenge=MOCK_CODE_CHALLENGE&code_challenge_method=S256
106
- Successfully logged in.
107
- Total Upload: 0xx KiB / gzip: 0xx KiB
108
- Uploaded test-name (TIMINGS)
109
- Published test-name (TIMINGS)
110
- test-name.test-sub-domain.workers.dev"
111
- `);
143
+ "Attempting to login via OAuth...
144
+ Opening a link in your default browser: https://dash.cloudflare.com/oauth2/auth?response_type=code&client_id=54d11594-84e4-41aa-b438-e81b8fa78ee7&redirect_uri=http%3A%2F%2Flocalhost%3A8976%2Foauth%2Fcallback&scope=account%3Aread%20user%3Aread%20workers%3Awrite%20workers_kv%3Awrite%20workers_routes%3Awrite%20workers_scripts%3Awrite%20workers_tail%3Aread%20d1%3Awrite%20pages%3Awrite%20zone%3Aread%20offline_access&state=MOCK_STATE_PARAM&code_challenge=MOCK_CODE_CHALLENGE&code_challenge_method=S256
145
+ Successfully logged in.
146
+ Total Upload: xx KiB / gzip: xx KiB
147
+ Uploaded test-name (TIMINGS)
148
+ Published test-name (TIMINGS)
149
+ https://test-name.test-sub-domain.workers.dev
150
+ Current Deployment ID: undefined"
151
+ `);
112
152
  expect(std.warn).toMatchInlineSnapshot(`""`);
113
153
  expect(std.err).toMatchInlineSnapshot(`""`);
114
154
  });
115
155
 
156
+ describe("with an alternative auth domain", () => {
157
+ mockAuthDomain({ domain: "dash.staging.cloudflare.com" });
158
+
159
+ it("drops a user into the login flow if they're unauthenticated", async () => {
160
+ writeWranglerToml();
161
+ writeWorkerSource();
162
+ mockDomainUsesAccess({
163
+ usesAccess: false,
164
+ domain: "dash.staging.cloudflare.com",
165
+ });
166
+ mockSubDomainRequest();
167
+ mockUploadWorkerRequest();
168
+ mockOAuthServerCallback();
169
+ const accessTokenRequest = mockGrantAccessToken({
170
+ domain: "dash.staging.cloudflare.com",
171
+ respondWith: "ok",
172
+ });
173
+ mockGrantAuthorization({ respondWith: "success" });
174
+
175
+ await expect(runWrangler("publish index.js")).resolves.toBeUndefined();
176
+
177
+ expect(accessTokenRequest.actual.url).toEqual(
178
+ accessTokenRequest.expected.url
179
+ );
180
+
181
+ expect(std.out).toMatchInlineSnapshot(`
182
+ "Attempting to login via OAuth...
183
+ Opening a link in your default browser: https://dash.staging.cloudflare.com/oauth2/auth?response_type=code&client_id=54d11594-84e4-41aa-b438-e81b8fa78ee7&redirect_uri=http%3A%2F%2Flocalhost%3A8976%2Foauth%2Fcallback&scope=account%3Aread%20user%3Aread%20workers%3Awrite%20workers_kv%3Awrite%20workers_routes%3Awrite%20workers_scripts%3Awrite%20workers_tail%3Aread%20d1%3Awrite%20pages%3Awrite%20zone%3Aread%20offline_access&state=MOCK_STATE_PARAM&code_challenge=MOCK_CODE_CHALLENGE&code_challenge_method=S256
184
+ Successfully logged in.
185
+ Total Upload: xx KiB / gzip: xx KiB
186
+ Uploaded test-name (TIMINGS)
187
+ Published test-name (TIMINGS)
188
+ https://test-name.test-sub-domain.workers.dev
189
+ Current Deployment ID: undefined"
190
+ `);
191
+ expect(std.warn).toMatchInlineSnapshot(`""`);
192
+ expect(std.err).toMatchInlineSnapshot(`""`);
193
+ });
194
+ });
195
+
116
196
  it("warns a user when they're authenticated with an API token in wrangler config file", async () => {
117
197
  writeWranglerToml();
118
198
  writeWorkerSource();
@@ -125,10 +205,11 @@ describe("publish", () => {
125
205
  await expect(runWrangler("publish index.js")).resolves.toBeUndefined();
126
206
 
127
207
  expect(std.out).toMatchInlineSnapshot(`
128
- "Total Upload: 0xx KiB / gzip: 0xx KiB
208
+ "Total Upload: xx KiB / gzip: xx KiB
129
209
  Uploaded test-name (TIMINGS)
130
210
  Published test-name (TIMINGS)
131
- test-name.test-sub-domain.workers.dev"
211
+ https://test-name.test-sub-domain.workers.dev
212
+ Current Deployment ID: undefined"
132
213
  `);
133
214
  expect(std.warn).toMatchInlineSnapshot(`
134
215
  "▲ [WARNING] It looks like you have used Wrangler 1's \`config\` command to login with an API token.
@@ -165,11 +246,12 @@ describe("publish", () => {
165
246
  await runWrangler("publish index.js");
166
247
 
167
248
  expect(std.out).toMatchInlineSnapshot(`
168
- "Total Upload: 0xx KiB / gzip: 0xx KiB
169
- Uploaded test-name (TIMINGS)
170
- Published test-name (TIMINGS)
171
- test-name.test-sub-domain.workers.dev"
172
- `);
249
+ "Total Upload: xx KiB / gzip: xx KiB
250
+ Uploaded test-name (TIMINGS)
251
+ Published test-name (TIMINGS)
252
+ https://test-name.test-sub-domain.workers.dev
253
+ Current Deployment ID: undefined"
254
+ `);
173
255
  expect(std.err).toMatchInlineSnapshot(`""`);
174
256
  });
175
257
 
@@ -189,11 +271,12 @@ describe("publish", () => {
189
271
  await runWrangler("publish index.js");
190
272
 
191
273
  expect(std.out).toMatchInlineSnapshot(`
192
- "Total Upload: 0xx KiB / gzip: 0xx KiB
193
- Uploaded test-name (TIMINGS)
194
- Published test-name (TIMINGS)
195
- test-name.test-sub-domain.workers.dev"
196
- `);
274
+ "Total Upload: xx KiB / gzip: xx KiB
275
+ Uploaded test-name (TIMINGS)
276
+ Published test-name (TIMINGS)
277
+ https://test-name.test-sub-domain.workers.dev
278
+ Current Deployment ID: undefined"
279
+ `);
197
280
  expect(std.err).toMatchInlineSnapshot(`""`);
198
281
  });
199
282
 
@@ -291,11 +374,12 @@ describe("publish", () => {
291
374
  });
292
375
  await runWrangler("publish index.js --env some-env");
293
376
  expect(std.out).toMatchInlineSnapshot(`
294
- "Total Upload: 0xx KiB / gzip: 0xx KiB
295
- Uploaded test-name-some-env (TIMINGS)
296
- Published test-name-some-env (TIMINGS)
297
- test-name-some-env.test-sub-domain.workers.dev"
298
- `);
377
+ "Total Upload: xx KiB / gzip: xx KiB
378
+ Uploaded test-name-some-env (TIMINGS)
379
+ Published test-name-some-env (TIMINGS)
380
+ https://test-name-some-env.test-sub-domain.workers.dev
381
+ Current Deployment ID: undefined"
382
+ `);
299
383
  expect(std.err).toMatchInlineSnapshot(`""`);
300
384
  expect(std.warn).toMatchInlineSnapshot(`""`);
301
385
  });
@@ -310,11 +394,12 @@ describe("publish", () => {
310
394
  });
311
395
  await runWrangler("publish index.js --legacy-env true");
312
396
  expect(std.out).toMatchInlineSnapshot(`
313
- "Total Upload: 0xx KiB / gzip: 0xx KiB
314
- Uploaded test-name (TIMINGS)
315
- Published test-name (TIMINGS)
316
- test-name.test-sub-domain.workers.dev"
317
- `);
397
+ "Total Upload: xx KiB / gzip: xx KiB
398
+ Uploaded test-name (TIMINGS)
399
+ Published test-name (TIMINGS)
400
+ https://test-name.test-sub-domain.workers.dev
401
+ Current Deployment ID: undefined"
402
+ `);
318
403
  expect(std.err).toMatchInlineSnapshot(`""`);
319
404
  expect(std.warn).toMatchInlineSnapshot(`""`);
320
405
  });
@@ -329,11 +414,12 @@ describe("publish", () => {
329
414
  });
330
415
  await runWrangler("publish index.js --env some-env --legacy-env true");
331
416
  expect(std.out).toMatchInlineSnapshot(`
332
- "Total Upload: 0xx KiB / gzip: 0xx KiB
333
- Uploaded test-name-some-env (TIMINGS)
334
- Published test-name-some-env (TIMINGS)
335
- test-name-some-env.test-sub-domain.workers.dev"
336
- `);
417
+ "Total Upload: xx KiB / gzip: xx KiB
418
+ Uploaded test-name-some-env (TIMINGS)
419
+ Published test-name-some-env (TIMINGS)
420
+ https://test-name-some-env.test-sub-domain.workers.dev
421
+ Current Deployment ID: undefined"
422
+ `);
337
423
  expect(std.err).toMatchInlineSnapshot(`""`);
338
424
  expect(std.warn).toMatchInlineSnapshot(`""`);
339
425
  });
@@ -348,11 +434,12 @@ describe("publish", () => {
348
434
  });
349
435
  await runWrangler("publish index.js --env some-env --legacy-env true");
350
436
  expect(std.out).toMatchInlineSnapshot(`
351
- "Total Upload: 0xx KiB / gzip: 0xx KiB
352
- Uploaded test-name-some-env (TIMINGS)
353
- Published test-name-some-env (TIMINGS)
354
- test-name-some-env.test-sub-domain.workers.dev"
355
- `);
437
+ "Total Upload: xx KiB / gzip: xx KiB
438
+ Uploaded test-name-some-env (TIMINGS)
439
+ Published test-name-some-env (TIMINGS)
440
+ https://test-name-some-env.test-sub-domain.workers.dev
441
+ Current Deployment ID: undefined"
442
+ `);
356
443
  expect(std.err).toMatchInlineSnapshot(`""`);
357
444
  expect(std.warn).toMatchInlineSnapshot(`
358
445
  "▲ [WARNING] Processing wrangler.toml configuration:
@@ -378,17 +465,17 @@ describe("publish", () => {
378
465
  await expect(
379
466
  runWrangler("publish index.js --env some-env --legacy-env true")
380
467
  ).rejects.toThrowErrorMatchingInlineSnapshot(`
381
- "Processing wrangler.toml configuration:
382
- - No environment found in configuration with name \\"some-env\\".
383
- Before using \`--env=some-env\` there should be an equivalent environment section in the configuration.
384
- The available configured environment names are: [\\"other-env\\"]
468
+ "Processing wrangler.toml configuration:
469
+ - No environment found in configuration with name \\"some-env\\".
470
+ Before using \`--env=some-env\` there should be an equivalent environment section in the configuration.
471
+ The available configured environment names are: [\\"other-env\\"]
385
472
 
386
- Consider adding an environment configuration section to the wrangler.toml file:
387
- \`\`\`
388
- [env.some-env]
389
- \`\`\`
390
- "
391
- `);
473
+ Consider adding an environment configuration section to the wrangler.toml file:
474
+ \`\`\`
475
+ [env.some-env]
476
+ \`\`\`
477
+ "
478
+ `);
392
479
  });
393
480
 
394
481
  it("should throw an error w/ helpful message when using --env --name", async () => {
@@ -418,11 +505,12 @@ describe("publish", () => {
418
505
  });
419
506
  await runWrangler("publish index.js --legacy-env false");
420
507
  expect(std.out).toMatchInlineSnapshot(`
421
- "Total Upload: 0xx KiB / gzip: 0xx KiB
422
- Uploaded test-name (TIMINGS)
423
- Published test-name (TIMINGS)
424
- test-name.test-sub-domain.workers.dev"
425
- `);
508
+ "Total Upload: xx KiB / gzip: xx KiB
509
+ Uploaded test-name (TIMINGS)
510
+ Published test-name (TIMINGS)
511
+ https://test-name.test-sub-domain.workers.dev
512
+ Current Deployment ID: undefined"
513
+ `);
426
514
  expect(std.err).toMatchInlineSnapshot(`""`);
427
515
  expect(std.warn).toMatchInlineSnapshot(`
428
516
  "▲ [WARNING] Processing wrangler.toml configuration:
@@ -444,11 +532,12 @@ describe("publish", () => {
444
532
  });
445
533
  await runWrangler("publish index.js --env some-env --legacy-env false");
446
534
  expect(std.out).toMatchInlineSnapshot(`
447
- "Total Upload: 0xx KiB / gzip: 0xx KiB
448
- Uploaded test-name (some-env) (TIMINGS)
449
- Published test-name (some-env) (TIMINGS)
450
- some-env.test-name.test-sub-domain.workers.dev"
451
- `);
535
+ "Total Upload: xx KiB / gzip: xx KiB
536
+ Uploaded test-name (some-env) (TIMINGS)
537
+ Published test-name (some-env) (TIMINGS)
538
+ https://some-env.test-name.test-sub-domain.workers.dev
539
+ Current Deployment ID: undefined"
540
+ `);
452
541
  expect(std.err).toMatchInlineSnapshot(`""`);
453
542
  expect(std.warn).toMatchInlineSnapshot(`
454
543
  "▲ [WARNING] Processing wrangler.toml configuration:
@@ -487,14 +576,15 @@ describe("publish", () => {
487
576
  mockSubDomainRequest();
488
577
  await runWrangler("publish ./some-path/worker/index.js");
489
578
  expect(std.out).toMatchInlineSnapshot(`
490
- "Your worker has access to the following bindings:
491
- - Vars:
492
- - xyz: \\"123\\"
493
- Total Upload: 0xx KiB / gzip: 0xx KiB
494
- Uploaded test-name (TIMINGS)
495
- Published test-name (TIMINGS)
496
- test-name.test-sub-domain.workers.dev"
497
- `);
579
+ "Total Upload: xx KiB / gzip: xx KiB
580
+ Your worker has access to the following bindings:
581
+ - Vars:
582
+ - xyz: 123
583
+ Uploaded test-name (TIMINGS)
584
+ Published test-name (TIMINGS)
585
+ https://test-name.test-sub-domain.workers.dev
586
+ Current Deployment ID: undefined"
587
+ `);
498
588
  expect(std.err).toMatchInlineSnapshot(`""`);
499
589
  });
500
590
 
@@ -524,10 +614,11 @@ describe("publish", () => {
524
614
  Object {
525
615
  "debug": "",
526
616
  "err": "",
527
- "out": "Total Upload: 0xx KiB / gzip: 0xx KiB
617
+ "out": "Total Upload: xx KiB / gzip: xx KiB
528
618
  Uploaded test-name (TIMINGS)
529
619
  Published test-name (TIMINGS)
530
- test-name.test-sub-domain.workers.dev",
620
+ https://test-name.test-sub-domain.workers.dev
621
+ Current Deployment ID: undefined",
531
622
  "warn": "▲ [WARNING] Processing wrangler.toml configuration:
532
623
 
533
624
  - The \\"route\\" field in your configuration is an empty string and will be ignored.
@@ -537,7 +628,6 @@ describe("publish", () => {
537
628
  }
538
629
  `);
539
630
  });
540
-
541
631
  it("should publish to a route with a pattern/{zone_id|zone_name} combo", async () => {
542
632
  writeWranglerToml({
543
633
  routes: [
@@ -568,20 +658,21 @@ describe("publish", () => {
568
658
  });
569
659
  await runWrangler("publish ./index");
570
660
  expect(std).toMatchInlineSnapshot(`
571
- Object {
572
- "debug": "",
573
- "err": "",
574
- "out": "Total Upload: 0xx KiB / gzip: 0xx KiB
575
- Uploaded test-name (TIMINGS)
576
- Published test-name (TIMINGS)
577
- some-example.com/some-route/*
578
- *a-boring-website.com (zone id: 54sdf7fsda)
579
- *another-boring-website.com (zone name: some-zone.com)
580
- example.com/some-route/* (zone id: JGHFHG654gjcj)
581
- more-examples.com/*",
582
- "warn": "",
583
- }
584
- `);
661
+ Object {
662
+ "debug": "",
663
+ "err": "",
664
+ "out": "Total Upload: xx KiB / gzip: xx KiB
665
+ Uploaded test-name (TIMINGS)
666
+ Published test-name (TIMINGS)
667
+ some-example.com/some-route/*
668
+ *a-boring-website.com (zone id: 54sdf7fsda)
669
+ *another-boring-website.com (zone name: some-zone.com)
670
+ example.com/some-route/* (zone id: JGHFHG654gjcj)
671
+ more-examples.com/*
672
+ Current Deployment ID: undefined",
673
+ "warn": "",
674
+ }
675
+ `);
585
676
  });
586
677
 
587
678
  it("should publish to a route with a pattern/{zone_id|zone_name} combo (service environments)", async () => {
@@ -629,25 +720,26 @@ describe("publish", () => {
629
720
  });
630
721
  await runWrangler("publish ./index --legacy-env false --env staging");
631
722
  expect(std).toMatchInlineSnapshot(`
632
- Object {
633
- "debug": "",
634
- "err": "",
635
- "out": "Total Upload: 0xx KiB / gzip: 0xx KiB
636
- Uploaded test-name (staging) (TIMINGS)
637
- Published test-name (staging) (TIMINGS)
638
- some-example.com/some-route/*
639
- *a-boring-website.com (zone id: 54sdf7fsda)
640
- *another-boring-website.com (zone name: some-zone.com)
641
- example.com/some-route/* (zone id: JGHFHG654gjcj)
642
- more-examples.com/*",
643
- "warn": "▲ [WARNING] Processing wrangler.toml configuration:
723
+ Object {
724
+ "debug": "",
725
+ "err": "",
726
+ "out": "Total Upload: xx KiB / gzip: xx KiB
727
+ Uploaded test-name (staging) (TIMINGS)
728
+ Published test-name (staging) (TIMINGS)
729
+ some-example.com/some-route/*
730
+ *a-boring-website.com (zone id: 54sdf7fsda)
731
+ *another-boring-website.com (zone name: some-zone.com)
732
+ example.com/some-route/* (zone id: JGHFHG654gjcj)
733
+ more-examples.com/*
734
+ Current Deployment ID: undefined",
735
+ "warn": "▲ [WARNING] Processing wrangler.toml configuration:
644
736
 
645
- - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in
646
- the future. DO NOT USE IN PRODUCTION.
737
+ - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in
738
+ the future. DO NOT USE IN PRODUCTION.
647
739
 
648
- ",
649
- }
650
- `);
740
+ ",
741
+ }
742
+ `);
651
743
  });
652
744
 
653
745
  it("should publish to legacy environment specific routes", async () => {
@@ -738,11 +830,12 @@ describe("publish", () => {
738
830
  "
739
831
  `);
740
832
  expect(std.out).toMatchInlineSnapshot(`
741
- "Total Upload: 0xx KiB / gzip: 0xx KiB
742
- Uploaded test-name (TIMINGS)
743
- Published test-name (TIMINGS)
744
- example.com/some-route/*"
745
- `);
833
+ "Total Upload: xx KiB / gzip: xx KiB
834
+ Uploaded test-name (TIMINGS)
835
+ Published test-name (TIMINGS)
836
+ example.com/some-route/*
837
+ Current Deployment ID: undefined"
838
+ `);
746
839
  });
747
840
 
748
841
  it("should error if the bulk-routes API fails and trying to push to a non-production environment", async () => {
@@ -769,9 +862,9 @@ describe("publish", () => {
769
862
  });
770
863
  await expect(runWrangler("publish ./index --env=staging")).rejects
771
864
  .toThrowErrorMatchingInlineSnapshot(`
772
- "Service environments combined with an API token that doesn't have 'All Zones' permissions is not supported.
773
- Either turn off service environments by setting \`legacy_env = true\`, creating an API token with 'All Zones' permissions, or logging in via OAuth"
774
- `);
865
+ "Service environments combined with an API token that doesn't have 'All Zones' permissions is not supported.
866
+ Either turn off service environments by setting \`legacy_env = true\`, creating an API token with 'All Zones' permissions, or logging in via OAuth"
867
+ `);
775
868
  });
776
869
 
777
870
  describe("custom domains", () => {
@@ -782,6 +875,7 @@ describe("publish", () => {
782
875
  writeWorkerSource();
783
876
  mockUpdateWorkerRequest({ enabled: false });
784
877
  mockUploadWorkerRequest({ expectedType: "esm" });
878
+ mockCustomDomainsChangesetRequest({});
785
879
  mockPublishCustomDomainsRequest({
786
880
  publishFlags: {
787
881
  override_scope: true,
@@ -794,63 +888,145 @@ describe("publish", () => {
794
888
  expect(std.out).toContain("api.example.com (custom domain)");
795
889
  });
796
890
 
797
- it("should allow retrying if publish fails with a conflicting custom domain error", async () => {
891
+ it("should confirm override if custom domain publish would override an existing domain", async () => {
798
892
  writeWranglerToml({
799
893
  routes: [{ pattern: "api.example.com", custom_domain: true }],
800
894
  });
801
895
  writeWorkerSource();
802
896
  mockUpdateWorkerRequest({ enabled: false });
803
897
  mockUploadWorkerRequest({ expectedType: "esm" });
804
- mockPublishCustomDomainsRequestConflictWithoutOverride({
805
- originConflicts: true,
898
+ mockCustomDomainsChangesetRequest({
899
+ originConflicts: [
900
+ {
901
+ id: "101",
902
+ zone_id: "",
903
+ zone_name: "",
904
+ hostname: "api.example.com",
905
+ service: "test-name",
906
+ environment: "",
907
+ },
908
+ ],
909
+ });
910
+ mockCustomDomainLookup({
911
+ id: "101",
912
+ zone_id: "",
913
+ zone_name: "",
914
+ hostname: "api.example.com",
915
+ service: "other-script",
916
+ environment: "",
917
+ });
918
+ mockPublishCustomDomainsRequest({
919
+ publishFlags: {
920
+ override_scope: true,
921
+ override_existing_origin: true,
922
+ override_existing_dns_record: false,
923
+ },
806
924
  domains: [{ hostname: "api.example.com" }],
807
925
  });
808
926
  mockConfirm({
809
- text: `Custom Domains already exist for these domains: "api.example.com"\nUpdate them to point to this script instead?`,
927
+ text: `Custom Domains already exist for these domains:
928
+ \t• api.example.com (used as a domain for "other-script")
929
+ Update them to point to this script instead?`,
810
930
  result: true,
811
931
  });
812
932
  await runWrangler("publish ./index");
813
933
  expect(std.out).toContain("api.example.com (custom domain)");
814
934
  });
815
935
 
816
- it("should allow retrying if publish fails with a conflicting DNS record error", async () => {
936
+ it("should confirm override if custom domain publish contains a conflicting DNS record", async () => {
817
937
  writeWranglerToml({
818
938
  routes: [{ pattern: "api.example.com", custom_domain: true }],
819
939
  });
820
940
  writeWorkerSource();
821
941
  mockUpdateWorkerRequest({ enabled: false });
822
942
  mockUploadWorkerRequest({ expectedType: "esm" });
823
- mockPublishCustomDomainsRequestConflictWithoutOverride({
824
- dnsRecordConflicts: true,
943
+ mockCustomDomainsChangesetRequest({
944
+ dnsRecordConflicts: [
945
+ {
946
+ id: "",
947
+ zone_id: "",
948
+ zone_name: "",
949
+ hostname: "api.example.com",
950
+ service: "test-name",
951
+ environment: "",
952
+ },
953
+ ],
954
+ });
955
+ mockPublishCustomDomainsRequest({
956
+ publishFlags: {
957
+ override_scope: true,
958
+ override_existing_origin: false,
959
+ override_existing_dns_record: true,
960
+ },
825
961
  domains: [{ hostname: "api.example.com" }],
826
962
  });
827
963
  mockConfirm({
828
- text: `You already have conflicting DNS records for these domains: "api.example.com"\nUpdate them to point to this script instead?`,
964
+ text: `You already have DNS records that conflict for these Custom Domains:
965
+ \t• api.example.com
966
+ Update them to point to this script instead?`,
829
967
  result: true,
830
968
  });
831
969
  await runWrangler("publish ./index");
832
970
  expect(std.out).toContain("api.example.com (custom domain)");
833
971
  });
834
972
 
835
- it("should allow retrying for conflicting custom domains and then again for conflicting dns", async () => {
973
+ it("should confirm for conflicting custom domains and then again for conflicting dns", async () => {
836
974
  writeWranglerToml({
837
975
  routes: [{ pattern: "api.example.com", custom_domain: true }],
838
976
  });
839
977
  writeWorkerSource();
840
978
  mockUpdateWorkerRequest({ enabled: false });
841
979
  mockUploadWorkerRequest({ expectedType: "esm" });
842
- mockPublishCustomDomainsRequestConflictWithoutOverride({
843
- originConflicts: true,
844
- dnsRecordConflicts: true,
980
+ mockCustomDomainsChangesetRequest({
981
+ originConflicts: [
982
+ {
983
+ id: "101",
984
+ zone_id: "",
985
+ zone_name: "",
986
+ hostname: "api.example.com",
987
+ service: "test-name",
988
+ environment: "",
989
+ },
990
+ ],
991
+ dnsRecordConflicts: [
992
+ {
993
+ id: "",
994
+ zone_id: "",
995
+ zone_name: "",
996
+ hostname: "api.example.com",
997
+ service: "test-name",
998
+ environment: "",
999
+ },
1000
+ ],
1001
+ });
1002
+ mockCustomDomainLookup({
1003
+ id: "101",
1004
+ zone_id: "",
1005
+ zone_name: "",
1006
+ hostname: "api.example.com",
1007
+ service: "other-script",
1008
+ environment: "",
1009
+ });
1010
+ mockPublishCustomDomainsRequest({
1011
+ publishFlags: {
1012
+ override_scope: true,
1013
+ override_existing_origin: true,
1014
+ override_existing_dns_record: true,
1015
+ },
845
1016
  domains: [{ hostname: "api.example.com" }],
846
1017
  });
847
1018
  mockConfirm(
848
1019
  {
849
- text: `Custom Domains already exist for these domains: "api.example.com"\nUpdate them to point to this script instead?`,
1020
+ text: `Custom Domains already exist for these domains:
1021
+ \t• api.example.com (used as a domain for "other-script")
1022
+ Update them to point to this script instead?`,
850
1023
  result: true,
851
1024
  },
852
1025
  {
853
- text: `You already have conflicting DNS records for these domains: "api.example.com"\nUpdate them to point to this script instead?`,
1026
+ text: `You already have DNS records that conflict for these Custom Domains:
1027
+ \t• api.example.com
1028
+ Update them to point to this script instead?`,
1029
+
854
1030
  result: true,
855
1031
  }
856
1032
  );
@@ -882,19 +1058,37 @@ describe("publish", () => {
882
1058
  );
883
1059
  });
884
1060
 
885
- it("should not retry publish on error if user does not confirm", async () => {
1061
+ it("should not continue with publishing an override if user does not confirm", async () => {
886
1062
  writeWranglerToml({
887
1063
  routes: [{ pattern: "api.example.com", custom_domain: true }],
888
1064
  });
889
1065
  writeWorkerSource();
890
1066
  mockUpdateWorkerRequest({ enabled: false });
891
1067
  mockUploadWorkerRequest({ expectedType: "esm" });
892
- mockPublishCustomDomainsRequestConflictWithoutOverride({
893
- dnsRecordConflicts: true,
894
- domains: [{ hostname: "api.example.com" }],
1068
+ mockCustomDomainsChangesetRequest({
1069
+ originConflicts: [
1070
+ {
1071
+ id: "101",
1072
+ zone_id: "",
1073
+ zone_name: "",
1074
+ hostname: "api.example.com",
1075
+ service: "test-name",
1076
+ environment: "",
1077
+ },
1078
+ ],
1079
+ });
1080
+ mockCustomDomainLookup({
1081
+ id: "101",
1082
+ zone_id: "",
1083
+ zone_name: "",
1084
+ hostname: "api.example.com",
1085
+ service: "other-script",
1086
+ environment: "",
895
1087
  });
896
1088
  mockConfirm({
897
- text: `You already have conflicting DNS records for these domains: "api.example.com"\nUpdate them to point to this script instead?`,
1089
+ text: `Custom Domains already exist for these domains:
1090
+ \t• api.example.com (used as a domain for "other-script")
1091
+ Update them to point to this script instead?`,
898
1092
  result: false,
899
1093
  });
900
1094
  await runWrangler("publish ./index");
@@ -917,11 +1111,12 @@ describe("publish", () => {
917
1111
  await runWrangler("publish ./index");
918
1112
 
919
1113
  expect(std.out).toMatchInlineSnapshot(`
920
- "Total Upload: 0xx KiB / gzip: 0xx KiB
921
- Uploaded test-name (TIMINGS)
922
- Published test-name (TIMINGS)
923
- test-name.test-sub-domain.workers.dev"
924
- `);
1114
+ "Total Upload: xx KiB / gzip: xx KiB
1115
+ Uploaded test-name (TIMINGS)
1116
+ Published test-name (TIMINGS)
1117
+ https://test-name.test-sub-domain.workers.dev
1118
+ Current Deployment ID: undefined"
1119
+ `);
925
1120
  expect(std.err).toMatchInlineSnapshot(`""`);
926
1121
  });
927
1122
 
@@ -934,11 +1129,12 @@ describe("publish", () => {
934
1129
  await runWrangler("publish ./index");
935
1130
 
936
1131
  expect(std.out).toMatchInlineSnapshot(`
937
- "Total Upload: 0xx KiB / gzip: 0xx KiB
938
- Uploaded test-name (TIMINGS)
939
- Published test-name (TIMINGS)
940
- test-name.test-sub-domain.workers.dev"
941
- `);
1132
+ "Total Upload: xx KiB / gzip: xx KiB
1133
+ Uploaded test-name (TIMINGS)
1134
+ Published test-name (TIMINGS)
1135
+ https://test-name.test-sub-domain.workers.dev
1136
+ Current Deployment ID: undefined"
1137
+ `);
942
1138
  expect(std.err).toMatchInlineSnapshot(`""`);
943
1139
  });
944
1140
 
@@ -951,11 +1147,12 @@ describe("publish", () => {
951
1147
  await runWrangler("publish");
952
1148
 
953
1149
  expect(std.out).toMatchInlineSnapshot(`
954
- "Total Upload: 0xx KiB / gzip: 0xx KiB
955
- Uploaded test-name (TIMINGS)
956
- Published test-name (TIMINGS)
957
- test-name.test-sub-domain.workers.dev"
958
- `);
1150
+ "Total Upload: xx KiB / gzip: xx KiB
1151
+ Uploaded test-name (TIMINGS)
1152
+ Published test-name (TIMINGS)
1153
+ https://test-name.test-sub-domain.workers.dev
1154
+ Current Deployment ID: undefined"
1155
+ `);
959
1156
  expect(std.err).toMatchInlineSnapshot(`""`);
960
1157
  });
961
1158
 
@@ -970,11 +1167,12 @@ describe("publish", () => {
970
1167
  await runWrangler("publish");
971
1168
 
972
1169
  expect(std.out).toMatchInlineSnapshot(`
973
- "Total Upload: 0xx KiB / gzip: 0xx KiB
974
- Uploaded test-name (TIMINGS)
975
- Published test-name (TIMINGS)
976
- test-name.test-sub-domain.workers.dev"
977
- `);
1170
+ "Total Upload: xx KiB / gzip: xx KiB
1171
+ Uploaded test-name (TIMINGS)
1172
+ Published test-name (TIMINGS)
1173
+ https://test-name.test-sub-domain.workers.dev
1174
+ Current Deployment ID: undefined"
1175
+ `);
978
1176
  expect(std.err).toMatchInlineSnapshot(`""`);
979
1177
  });
980
1178
 
@@ -987,11 +1185,12 @@ describe("publish", () => {
987
1185
  await runWrangler("publish");
988
1186
 
989
1187
  expect(std.out).toMatchInlineSnapshot(`
990
- "Total Upload: 0xx KiB / gzip: 0xx KiB
991
- Uploaded test-name (TIMINGS)
992
- Published test-name (TIMINGS)
993
- test-name.test-sub-domain.workers.dev"
994
- `);
1188
+ "Total Upload: xx KiB / gzip: xx KiB
1189
+ Uploaded test-name (TIMINGS)
1190
+ Published test-name (TIMINGS)
1191
+ https://test-name.test-sub-domain.workers.dev
1192
+ Current Deployment ID: undefined"
1193
+ `);
995
1194
  expect(std.err).toMatchInlineSnapshot(`""`);
996
1195
  expect(std.warn).toMatchInlineSnapshot(`
997
1196
  "▲ [WARNING] Processing wrangler.toml configuration:
@@ -1023,11 +1222,12 @@ describe("publish", () => {
1023
1222
  await runWrangler("publish");
1024
1223
 
1025
1224
  expect(std.out).toMatchInlineSnapshot(`
1026
- "Total Upload: 0xx KiB / gzip: 0xx KiB
1027
- Uploaded test-name (TIMINGS)
1028
- Published test-name (TIMINGS)
1029
- test-name.test-sub-domain.workers.dev"
1030
- `);
1225
+ "Total Upload: xx KiB / gzip: xx KiB
1226
+ Uploaded test-name (TIMINGS)
1227
+ Published test-name (TIMINGS)
1228
+ https://test-name.test-sub-domain.workers.dev
1229
+ Current Deployment ID: undefined"
1230
+ `);
1031
1231
  expect(std.err).toMatchInlineSnapshot(`""`);
1032
1232
  expect(std.warn).toMatchInlineSnapshot(`
1033
1233
  "▲ [WARNING] Processing ../wrangler.toml configuration:
@@ -1058,11 +1258,11 @@ describe("publish", () => {
1058
1258
  });
1059
1259
  await expect(runWrangler("publish")).rejects
1060
1260
  .toThrowErrorMatchingInlineSnapshot(`
1061
- "Processing wrangler.toml configuration:
1062
- - Don't define both the \`main\` and \`build.upload.main\` fields in your configuration.
1063
- They serve the same purpose: to point to the entry-point of your worker.
1064
- Delete the \`build.upload.main\` and \`build.upload.dir\` field from your config."
1065
- `);
1261
+ "Processing wrangler.toml configuration:
1262
+ - Don't define both the \`main\` and \`build.upload.main\` fields in your configuration.
1263
+ They serve the same purpose: to point to the entry-point of your worker.
1264
+ Delete the \`build.upload.main\` and \`build.upload.dir\` field from your config."
1265
+ `);
1066
1266
  });
1067
1267
 
1068
1268
  it("should be able to transpile TypeScript (esm)", async () => {
@@ -1073,11 +1273,12 @@ describe("publish", () => {
1073
1273
  await runWrangler("publish index.ts");
1074
1274
 
1075
1275
  expect(std.out).toMatchInlineSnapshot(`
1076
- "Total Upload: 0xx KiB / gzip: 0xx KiB
1077
- Uploaded test-name (TIMINGS)
1078
- Published test-name (TIMINGS)
1079
- test-name.test-sub-domain.workers.dev"
1080
- `);
1276
+ "Total Upload: xx KiB / gzip: xx KiB
1277
+ Uploaded test-name (TIMINGS)
1278
+ Published test-name (TIMINGS)
1279
+ https://test-name.test-sub-domain.workers.dev
1280
+ Current Deployment ID: undefined"
1281
+ `);
1081
1282
  expect(std.err).toMatchInlineSnapshot(`""`);
1082
1283
  });
1083
1284
 
@@ -1092,11 +1293,12 @@ describe("publish", () => {
1092
1293
  await runWrangler("publish index.ts");
1093
1294
 
1094
1295
  expect(std.out).toMatchInlineSnapshot(`
1095
- "Total Upload: 0xx KiB / gzip: 0xx KiB
1096
- Uploaded test-name (TIMINGS)
1097
- Published test-name (TIMINGS)
1098
- test-name.test-sub-domain.workers.dev"
1099
- `);
1296
+ "Total Upload: xx KiB / gzip: xx KiB
1297
+ Uploaded test-name (TIMINGS)
1298
+ Published test-name (TIMINGS)
1299
+ https://test-name.test-sub-domain.workers.dev
1300
+ Current Deployment ID: undefined"
1301
+ `);
1100
1302
  expect(std.err).toMatchInlineSnapshot(`""`);
1101
1303
  });
1102
1304
 
@@ -1123,11 +1325,12 @@ export default{
1123
1325
  mockSubDomainRequest();
1124
1326
  await runWrangler("publish index.js");
1125
1327
  expect(std.out).toMatchInlineSnapshot(`
1126
- "Total Upload: 0xx KiB / gzip: 0xx KiB
1127
- Uploaded test-name (TIMINGS)
1128
- Published test-name (TIMINGS)
1129
- test-name.test-sub-domain.workers.dev"
1130
- `);
1328
+ "Total Upload: xx KiB / gzip: xx KiB
1329
+ Uploaded test-name (TIMINGS)
1330
+ Published test-name (TIMINGS)
1331
+ https://test-name.test-sub-domain.workers.dev
1332
+ Current Deployment ID: undefined"
1333
+ `);
1131
1334
  expect(std.err).toMatchInlineSnapshot(`""`);
1132
1335
  });
1133
1336
 
@@ -1140,11 +1343,12 @@ export default{
1140
1343
  await runWrangler("publish ./src/index.js");
1141
1344
 
1142
1345
  expect(std.out).toMatchInlineSnapshot(`
1143
- "Total Upload: 0xx KiB / gzip: 0xx KiB
1144
- Uploaded test-name (TIMINGS)
1145
- Published test-name (TIMINGS)
1146
- test-name.test-sub-domain.workers.dev"
1147
- `);
1346
+ "Total Upload: xx KiB / gzip: xx KiB
1347
+ Uploaded test-name (TIMINGS)
1348
+ Published test-name (TIMINGS)
1349
+ https://test-name.test-sub-domain.workers.dev
1350
+ Current Deployment ID: undefined"
1351
+ `);
1148
1352
  expect(std.err).toMatchInlineSnapshot(`""`);
1149
1353
  });
1150
1354
 
@@ -1177,14 +1381,14 @@ export default {};`
1177
1381
  `);
1178
1382
 
1179
1383
  expect(std).toMatchInlineSnapshot(`
1180
- Object {
1181
- "debug": "",
1182
- "err": "",
1183
- "out": "--dry-run: exiting now.
1184
- Total Upload: 0xx KiB / gzip: 0xx KiB",
1185
- "warn": "",
1186
- }
1187
- `);
1384
+ Object {
1385
+ "debug": "",
1386
+ "err": "",
1387
+ "out": "Total Upload: xx KiB / gzip: xx KiB
1388
+ --dry-run: exiting now.",
1389
+ "warn": "",
1390
+ }
1391
+ `);
1188
1392
  });
1189
1393
 
1190
1394
  it("should not preserve exports on a service-worker format worker", async () => {
@@ -1210,16 +1414,16 @@ addEventListener('fetch', event => {});`
1210
1414
  ).toMatchInlineSnapshot(`Array []`);
1211
1415
 
1212
1416
  expect(std).toMatchInlineSnapshot(`
1213
- Object {
1214
- "debug": "",
1215
- "err": "",
1216
- "out": "--dry-run: exiting now.
1217
- Total Upload: 0xx KiB / gzip: 0xx KiB",
1218
- "warn": "▲ [WARNING] The entrypoint index.js has exports like an ES Module, but hasn't defined a default export like a module worker normally would. Building the worker using \\"service-worker\\" format...
1417
+ Object {
1418
+ "debug": "",
1419
+ "err": "",
1420
+ "out": "Total Upload: xx KiB / gzip: xx KiB
1421
+ --dry-run: exiting now.",
1422
+ "warn": "▲ [WARNING] The entrypoint index.js has exports like an ES Module, but hasn't defined a default export like a module worker normally would. Building the worker using \\"service-worker\\" format...
1219
1423
 
1220
- ",
1221
- }
1222
- `);
1424
+ ",
1425
+ }
1426
+ `);
1223
1427
  });
1224
1428
 
1225
1429
  it("should be able to transpile entry-points in sub-directories (sw)", async () => {
@@ -1234,11 +1438,12 @@ addEventListener('fetch', event => {});`
1234
1438
  await runWrangler("publish ./src/index.js");
1235
1439
 
1236
1440
  expect(std.out).toMatchInlineSnapshot(`
1237
- "Total Upload: 0xx KiB / gzip: 0xx KiB
1238
- Uploaded test-name (TIMINGS)
1239
- Published test-name (TIMINGS)
1240
- test-name.test-sub-domain.workers.dev"
1241
- `);
1441
+ "Total Upload: xx KiB / gzip: xx KiB
1442
+ Uploaded test-name (TIMINGS)
1443
+ Published test-name (TIMINGS)
1444
+ https://test-name.test-sub-domain.workers.dev
1445
+ Current Deployment ID: undefined"
1446
+ `);
1242
1447
  expect(std.err).toMatchInlineSnapshot(`""`);
1243
1448
  });
1244
1449
 
@@ -1253,9 +1458,9 @@ addEventListener('fetch', event => {});`
1253
1458
 
1254
1459
  await expect(runWrangler("publish ./index.js")).rejects
1255
1460
  .toThrowErrorMatchingInlineSnapshot(`
1256
- "Processing wrangler.toml configuration:
1257
- - \\"site.bucket\\" is a required field."
1258
- `);
1461
+ "Processing wrangler.toml configuration:
1462
+ - \\"site.bucket\\" is a required field."
1463
+ `);
1259
1464
 
1260
1465
  expect(std.out).toMatchInlineSnapshot(`
1261
1466
  "
@@ -1308,30 +1513,31 @@ addEventListener('fetch', event => {});`
1308
1513
  await runWrangler("publish ./index.js");
1309
1514
 
1310
1515
  expect(std).toMatchInlineSnapshot(`
1311
- Object {
1312
- "debug": "",
1313
- "err": "",
1314
- "out": "Reading file-1.txt...
1315
- Uploading as file-1.2ca234f380.txt...
1316
- Reading file-2.txt...
1317
- Uploading as file-2.5938485188.txt...
1318
- ↗️ Done syncing assets
1319
- Total Upload: 0xx KiB / gzip: 0xx KiB
1320
- Uploaded test-name (TIMINGS)
1321
- Published test-name (TIMINGS)
1322
- test-name.test-sub-domain.workers.dev",
1323
- "warn": "▲ [WARNING] Processing wrangler.toml configuration:
1516
+ Object {
1517
+ "debug": "",
1518
+ "err": "",
1519
+ "out": "Reading file-1.txt...
1520
+ Uploading as file-1.2ca234f380.txt...
1521
+ Reading file-2.txt...
1522
+ Uploading as file-2.5938485188.txt...
1523
+ ↗️ Done syncing assets
1524
+ Total Upload: xx KiB / gzip: xx KiB
1525
+ Uploaded test-name (TIMINGS)
1526
+ Published test-name (TIMINGS)
1527
+ https://test-name.test-sub-domain.workers.dev
1528
+ Current Deployment ID: undefined",
1529
+ "warn": "▲ [WARNING] Processing wrangler.toml configuration:
1324
1530
 
1325
- - Deprecation: \\"site.entry-point\\":
1326
- Delete the \`site.entry-point\` field, then add the top level \`main\` field to your configuration
1327
- file:
1328
- \`\`\`
1329
- main = \\"index.js\\"
1330
- \`\`\`
1531
+ - Deprecation: \\"site.entry-point\\":
1532
+ Delete the \`site.entry-point\` field, then add the top level \`main\` field to your configuration
1533
+ file:
1534
+ \`\`\`
1535
+ main = \\"index.js\\"
1536
+ \`\`\`
1331
1537
 
1332
- ",
1333
- }
1334
- `);
1538
+ ",
1539
+ }
1540
+ `);
1335
1541
  });
1336
1542
 
1337
1543
  it("should resolve site.entry-point relative to wrangler.toml", async () => {
@@ -1363,16 +1569,17 @@ addEventListener('fetch', event => {});`
1363
1569
  await runWrangler("publish --config ./my-site/wrangler.toml");
1364
1570
 
1365
1571
  expect(std.out).toMatchInlineSnapshot(`
1366
- "Reading file-1.txt...
1367
- Uploading as file-1.2ca234f380.txt...
1368
- Reading file-2.txt...
1369
- Uploading as file-2.5938485188.txt...
1370
- ↗️ Done syncing assets
1371
- Total Upload: 0xx KiB / gzip: 0xx KiB
1372
- Uploaded test-name (TIMINGS)
1373
- Published test-name (TIMINGS)
1374
- test-name.test-sub-domain.workers.dev"
1375
- `);
1572
+ "Reading file-1.txt...
1573
+ Uploading as file-1.2ca234f380.txt...
1574
+ Reading file-2.txt...
1575
+ Uploading as file-2.5938485188.txt...
1576
+ ↗️ Done syncing assets
1577
+ Total Upload: xx KiB / gzip: xx KiB
1578
+ Uploaded test-name (TIMINGS)
1579
+ Published test-name (TIMINGS)
1580
+ https://test-name.test-sub-domain.workers.dev
1581
+ Current Deployment ID: undefined"
1582
+ `);
1376
1583
  expect(std.err).toMatchInlineSnapshot(`""`);
1377
1584
  expect(normalizeSlashes(std.warn)).toMatchInlineSnapshot(`
1378
1585
  "▲ [WARNING] Processing my-site/wrangler.toml configuration:
@@ -1399,11 +1606,11 @@ addEventListener('fetch', event => {});`
1399
1606
 
1400
1607
  await expect(runWrangler("publish")).rejects
1401
1608
  .toThrowErrorMatchingInlineSnapshot(`
1402
- "Processing wrangler.toml configuration:
1403
- - Don't define both the \`main\` and \`site.entry-point\` fields in your configuration.
1404
- They serve the same purpose: to point to the entry-point of your worker.
1405
- Delete the deprecated \`site.entry-point\` field from your config."
1406
- `);
1609
+ "Processing wrangler.toml configuration:
1610
+ - Don't define both the \`main\` and \`site.entry-point\` fields in your configuration.
1611
+ They serve the same purpose: to point to the entry-point of your worker.
1612
+ Delete the deprecated \`site.entry-point\` field from your config."
1613
+ `);
1407
1614
  });
1408
1615
 
1409
1616
  it("should error if there is no entry-point specified", async () => {
@@ -1438,7 +1645,9 @@ addEventListener('fetch', event => {});`
1438
1645
  id: "__test-name-workers_sites_assets-id",
1439
1646
  };
1440
1647
  writeAssets(assets);
1441
- mockUploadWorkerRequest({ expectedMainModule: "stdin.js" });
1648
+ mockUploadWorkerRequest({
1649
+ expectedMainModule: "serve-static-assets.entry.js",
1650
+ });
1442
1651
  mockSubDomainRequest();
1443
1652
  mockListKVNamespacesRequest(kvNamespace);
1444
1653
  mockKeyListRequest(kvNamespace.id, []);
@@ -1447,28 +1656,29 @@ addEventListener('fetch', event => {});`
1447
1656
  await runWrangler("publish --assets assets --latest --name test-name");
1448
1657
 
1449
1658
  expect(std).toMatchInlineSnapshot(`
1450
- Object {
1451
- "debug": "",
1452
- "err": "",
1453
- "out": "Reading file-1.txt...
1454
- Uploading as file-1.2ca234f380.txt...
1455
- Reading file-2.txt...
1456
- Uploading as file-2.5938485188.txt...
1457
- ↗️ Done syncing assets
1458
- Total Upload: 52xx KiB / gzip: 13xx KiB
1459
- Uploaded test-name (TIMINGS)
1460
- Published test-name (TIMINGS)
1461
- test-name.test-sub-domain.workers.dev",
1462
- "warn": "▲ [WARNING] The --assets argument is experimental and may change or break at any time
1659
+ Object {
1660
+ "debug": "",
1661
+ "err": "",
1662
+ "out": "Reading file-1.txt...
1663
+ Uploading as file-1.2ca234f380.txt...
1664
+ Reading file-2.txt...
1665
+ Uploading as file-2.5938485188.txt...
1666
+ ↗️ Done syncing assets
1667
+ Total Upload: xx KiB / gzip: xx KiB
1668
+ Uploaded test-name (TIMINGS)
1669
+ Published test-name (TIMINGS)
1670
+ https://test-name.test-sub-domain.workers.dev
1671
+ Current Deployment ID: undefined",
1672
+ "warn": "▲ [WARNING] The --assets argument is experimental and may change or break at any time
1463
1673
 
1464
1674
 
1465
- ▲ [WARNING] Using the latest version of the Workers runtime. To silence this warning, please choose a specific version of the runtime with --compatibility-date, or add a compatibility_date to your wrangler.toml.
1675
+ ▲ [WARNING] Using the latest version of the Workers runtime. To silence this warning, please choose a specific version of the runtime with --compatibility-date, or add a compatibility_date to your wrangler.toml.
1466
1676
 
1467
1677
 
1468
1678
 
1469
- ",
1470
- }
1471
- `);
1679
+ ",
1680
+ }
1681
+ `);
1472
1682
  });
1473
1683
  });
1474
1684
 
@@ -1498,16 +1708,17 @@ addEventListener('fetch', event => {});`
1498
1708
  await runWrangler("publish");
1499
1709
 
1500
1710
  expect(std.out).toMatchInlineSnapshot(`
1501
- "Reading file-1.txt...
1502
- Uploading as file-1.2ca234f380.txt...
1503
- Reading file-2.txt...
1504
- Uploading as file-2.5938485188.txt...
1505
- ↗️ Done syncing assets
1506
- Total Upload: 0xx KiB / gzip: 0xx KiB
1507
- Uploaded test-name (TIMINGS)
1508
- Published test-name (TIMINGS)
1509
- test-name.test-sub-domain.workers.dev"
1510
- `);
1711
+ "Reading file-1.txt...
1712
+ Uploading as file-1.2ca234f380.txt...
1713
+ Reading file-2.txt...
1714
+ Uploading as file-2.5938485188.txt...
1715
+ ↗️ Done syncing assets
1716
+ Total Upload: xx KiB / gzip: xx KiB
1717
+ Uploaded test-name (TIMINGS)
1718
+ Published test-name (TIMINGS)
1719
+ https://test-name.test-sub-domain.workers.dev
1720
+ Current Deployment ID: undefined"
1721
+ `);
1511
1722
  expect(std.err).toMatchInlineSnapshot(`""`);
1512
1723
  });
1513
1724
 
@@ -1526,7 +1737,7 @@ addEventListener('fetch', event => {});`
1526
1737
  writeWorkerSource();
1527
1738
  writeAssets(assets);
1528
1739
  mockUploadWorkerRequest({
1529
- expectedMainModule: "stdin.js",
1740
+ expectedMainModule: "serve-static-assets.entry.js",
1530
1741
  });
1531
1742
  mockSubDomainRequest();
1532
1743
  mockListKVNamespacesRequest(kvNamespace);
@@ -1535,23 +1746,24 @@ addEventListener('fetch', event => {});`
1535
1746
  await runWrangler("publish --assets assets");
1536
1747
 
1537
1748
  expect(std).toMatchInlineSnapshot(`
1538
- Object {
1539
- "debug": "",
1540
- "err": "",
1541
- "out": "Reading file-1.txt...
1542
- Uploading as file-1.2ca234f380.txt...
1543
- Reading file-2.txt...
1544
- Uploading as file-2.5938485188.txt...
1545
- ↗️ Done syncing assets
1546
- Total Upload: 52xx KiB / gzip: 13xx KiB
1547
- Uploaded test-name (TIMINGS)
1548
- Published test-name (TIMINGS)
1549
- test-name.test-sub-domain.workers.dev",
1550
- "warn": "▲ [WARNING] The --assets argument is experimental and may change or break at any time
1749
+ Object {
1750
+ "debug": "",
1751
+ "err": "",
1752
+ "out": "Reading file-1.txt...
1753
+ Uploading as file-1.2ca234f380.txt...
1754
+ Reading file-2.txt...
1755
+ Uploading as file-2.5938485188.txt...
1756
+ ↗️ Done syncing assets
1757
+ Total Upload: xx KiB / gzip: xx KiB
1758
+ Uploaded test-name (TIMINGS)
1759
+ Published test-name (TIMINGS)
1760
+ https://test-name.test-sub-domain.workers.dev
1761
+ Current Deployment ID: undefined",
1762
+ "warn": "▲ [WARNING] The --assets argument is experimental and may change or break at any time
1551
1763
 
1552
- ",
1553
- }
1554
- `);
1764
+ ",
1765
+ }
1766
+ `);
1555
1767
  });
1556
1768
 
1557
1769
  it("should error when trying to use --assets with a service-worker Worker", async () => {
@@ -1634,6 +1846,7 @@ addEventListener('fetch', event => {});`
1634
1846
  it("should error if config.assets and --site are used together", async () => {
1635
1847
  writeWranglerToml({
1636
1848
  main: "./index.js",
1849
+ // @ts-expect-error we allow string inputs here
1637
1850
  assets: "abc",
1638
1851
  });
1639
1852
  writeWorkerSource();
@@ -1663,6 +1876,7 @@ addEventListener('fetch', event => {});`
1663
1876
  it("should error if config.assets and config.site are used together", async () => {
1664
1877
  writeWranglerToml({
1665
1878
  main: "./index.js",
1879
+ // @ts-expect-error we allow string inputs here
1666
1880
  assets: "abc",
1667
1881
  site: {
1668
1882
  bucket: "xyz",
@@ -1708,7 +1922,7 @@ addEventListener('fetch', event => {});`
1708
1922
  writeWorkerSource();
1709
1923
  writeAssets(assets);
1710
1924
  mockUploadWorkerRequest({
1711
- expectedMainModule: "stdin.js",
1925
+ expectedMainModule: "serve-static-assets.entry.js",
1712
1926
  });
1713
1927
  mockSubDomainRequest();
1714
1928
  mockListKVNamespacesRequest(kvNamespace);
@@ -1717,28 +1931,30 @@ addEventListener('fetch', event => {});`
1717
1931
 
1718
1932
  await runWrangler("publish --assets ./assets");
1719
1933
  expect(std).toMatchInlineSnapshot(`
1720
- Object {
1721
- "debug": "",
1722
- "err": "",
1723
- "out": "Reading subdir/file-1.txt...
1724
- Uploading as subdir/file-1.2ca234f380.txt...
1725
- Reading subdir/file-2.txt...
1726
- Uploading as subdir/file-2.5938485188.txt...
1727
- ↗️ Done syncing assets
1728
- Total Upload: 52xx KiB / gzip: 13xx KiB
1729
- Uploaded test-name (TIMINGS)
1730
- Published test-name (TIMINGS)
1731
- test-name.test-sub-domain.workers.dev",
1732
- "warn": "▲ [WARNING] The --assets argument is experimental and may change or break at any time
1934
+ Object {
1935
+ "debug": "",
1936
+ "err": "",
1937
+ "out": "Reading subdir/file-1.txt...
1938
+ Uploading as subdir/file-1.2ca234f380.txt...
1939
+ Reading subdir/file-2.txt...
1940
+ Uploading as subdir/file-2.5938485188.txt...
1941
+ ↗️ Done syncing assets
1942
+ Total Upload: xx KiB / gzip: xx KiB
1943
+ Uploaded test-name (TIMINGS)
1944
+ Published test-name (TIMINGS)
1945
+ https://test-name.test-sub-domain.workers.dev
1946
+ Current Deployment ID: undefined",
1947
+ "warn": "▲ [WARNING] The --assets argument is experimental and may change or break at any time
1733
1948
 
1734
- ",
1735
- }
1736
- `);
1949
+ ",
1950
+ }
1951
+ `);
1737
1952
  });
1738
1953
 
1739
1954
  it("should warn if config.assets is used", async () => {
1740
1955
  writeWranglerToml({
1741
1956
  main: "./index.js",
1957
+ // @ts-expect-error we allow string inputs here
1742
1958
  assets: "./assets",
1743
1959
  });
1744
1960
  const assets = [
@@ -1753,7 +1969,7 @@ addEventListener('fetch', event => {});`
1753
1969
  writeWorkerSource();
1754
1970
  writeAssets(assets);
1755
1971
  mockUploadWorkerRequest({
1756
- expectedMainModule: "stdin.js",
1972
+ expectedMainModule: "serve-static-assets.entry.js",
1757
1973
  });
1758
1974
  mockSubDomainRequest();
1759
1975
  mockListKVNamespacesRequest(kvNamespace);
@@ -1762,25 +1978,26 @@ addEventListener('fetch', event => {});`
1762
1978
 
1763
1979
  await runWrangler("publish");
1764
1980
  expect(std).toMatchInlineSnapshot(`
1765
- Object {
1766
- "debug": "",
1767
- "err": "",
1768
- "out": "Reading subdir/file-1.txt...
1769
- Uploading as subdir/file-1.2ca234f380.txt...
1770
- Reading subdir/file-2.txt...
1771
- Uploading as subdir/file-2.5938485188.txt...
1772
- ↗️ Done syncing assets
1773
- Total Upload: 52xx KiB / gzip: 13xx KiB
1774
- Uploaded test-name (TIMINGS)
1775
- Published test-name (TIMINGS)
1776
- test-name.test-sub-domain.workers.dev",
1777
- "warn": "▲ [WARNING] Processing wrangler.toml configuration:
1981
+ Object {
1982
+ "debug": "",
1983
+ "err": "",
1984
+ "out": "Reading subdir/file-1.txt...
1985
+ Uploading as subdir/file-1.2ca234f380.txt...
1986
+ Reading subdir/file-2.txt...
1987
+ Uploading as subdir/file-2.5938485188.txt...
1988
+ ↗️ Done syncing assets
1989
+ Total Upload: xx KiB / gzip: xx KiB
1990
+ Uploaded test-name (TIMINGS)
1991
+ Published test-name (TIMINGS)
1992
+ https://test-name.test-sub-domain.workers.dev
1993
+ Current Deployment ID: undefined",
1994
+ "warn": "▲ [WARNING] Processing wrangler.toml configuration:
1778
1995
 
1779
- - \\"assets\\" fields are experimental and may change or break at any time.
1996
+ - \\"assets\\" fields are experimental and may change or break at any time.
1780
1997
 
1781
- ",
1782
- }
1783
- `);
1998
+ ",
1999
+ }
2000
+ `);
1784
2001
  });
1785
2002
 
1786
2003
  it("should not contain backslash for assets with nested directories", async () => {
@@ -1821,16 +2038,17 @@ addEventListener('fetch', event => {});`
1821
2038
  await runWrangler("publish");
1822
2039
 
1823
2040
  expect(std.out).toMatchInlineSnapshot(`
1824
- "Reading subdir/file-1.txt...
1825
- Uploading as subdir/file-1.2ca234f380.txt...
1826
- Reading subdir/file-2.txt...
1827
- Uploading as subdir/file-2.5938485188.txt...
1828
- ↗️ Done syncing assets
1829
- Total Upload: 0xx KiB / gzip: 0xx KiB
1830
- Uploaded test-name (TIMINGS)
1831
- Published test-name (TIMINGS)
1832
- test-name.test-sub-domain.workers.dev"
1833
- `);
2041
+ "Reading subdir/file-1.txt...
2042
+ Uploading as subdir/file-1.2ca234f380.txt...
2043
+ Reading subdir/file-2.txt...
2044
+ Uploading as subdir/file-2.5938485188.txt...
2045
+ ↗️ Done syncing assets
2046
+ Total Upload: xx KiB / gzip: xx KiB
2047
+ Uploaded test-name (TIMINGS)
2048
+ Published test-name (TIMINGS)
2049
+ https://test-name.test-sub-domain.workers.dev
2050
+ Current Deployment ID: undefined"
2051
+ `);
1834
2052
  expect(std.err).toMatchInlineSnapshot(`""`);
1835
2053
  });
1836
2054
 
@@ -1878,16 +2096,17 @@ addEventListener('fetch', event => {});`
1878
2096
  await runWrangler("publish");
1879
2097
 
1880
2098
  expect(std.out).toMatchInlineSnapshot(`
1881
- "Reading file-1.txt...
1882
- Uploading as file-1.2ca234f380.txt...
1883
- Reading file-2.txt...
1884
- Uploading as file-2.5938485188.txt...
1885
- ↗️ Done syncing assets
1886
- Total Upload: 0xx KiB / gzip: 0xx KiB
1887
- Uploaded test-name (TIMINGS)
1888
- Published test-name (TIMINGS)
1889
- test-name.test-sub-domain.workers.dev"
1890
- `);
2099
+ "Reading file-1.txt...
2100
+ Uploading as file-1.2ca234f380.txt...
2101
+ Reading file-2.txt...
2102
+ Uploading as file-2.5938485188.txt...
2103
+ ↗️ Done syncing assets
2104
+ Total Upload: xx KiB / gzip: xx KiB
2105
+ Uploaded test-name (TIMINGS)
2106
+ Published test-name (TIMINGS)
2107
+ https://test-name.test-sub-domain.workers.dev
2108
+ Current Deployment ID: undefined"
2109
+ `);
1891
2110
  expect(std.err).toMatchInlineSnapshot(`""`);
1892
2111
  });
1893
2112
 
@@ -1929,16 +2148,17 @@ addEventListener('fetch', event => {});`
1929
2148
  await runWrangler("publish");
1930
2149
 
1931
2150
  expect(std.out).toMatchInlineSnapshot(`
1932
- "Reading file-1.txt...
1933
- Uploading as file-1.2ca234f380.txt...
1934
- Reading file-2.txt...
1935
- Uploading as file-2.5938485188.txt...
1936
- ↗️ Done syncing assets
1937
- Total Upload: 0xx KiB / gzip: 0xx KiB
1938
- Uploaded test-name (TIMINGS)
1939
- Published test-name (TIMINGS)
1940
- test-name.test-sub-domain.workers.dev"
1941
- `);
2151
+ "Reading file-1.txt...
2152
+ Uploading as file-1.2ca234f380.txt...
2153
+ Reading file-2.txt...
2154
+ Uploading as file-2.5938485188.txt...
2155
+ ↗️ Done syncing assets
2156
+ Total Upload: xx KiB / gzip: xx KiB
2157
+ Uploaded test-name (TIMINGS)
2158
+ Published test-name (TIMINGS)
2159
+ https://test-name.test-sub-domain.workers.dev
2160
+ Current Deployment ID: undefined"
2161
+ `);
1942
2162
  expect(std.err).toMatchInlineSnapshot(`""`);
1943
2163
  });
1944
2164
 
@@ -1978,16 +2198,17 @@ addEventListener('fetch', event => {});`
1978
2198
  await runWrangler("publish --env some-env --legacy-env false");
1979
2199
 
1980
2200
  expect(std.out).toMatchInlineSnapshot(`
1981
- "Reading file-1.txt...
1982
- Uploading as file-1.2ca234f380.txt...
1983
- Reading file-2.txt...
1984
- Uploading as file-2.5938485188.txt...
1985
- ↗️ Done syncing assets
1986
- Total Upload: 0xx KiB / gzip: 0xx KiB
1987
- Uploaded test-name (some-env) (TIMINGS)
1988
- Published test-name (some-env) (TIMINGS)
1989
- some-env.test-name.test-sub-domain.workers.dev"
1990
- `);
2201
+ "Reading file-1.txt...
2202
+ Uploading as file-1.2ca234f380.txt...
2203
+ Reading file-2.txt...
2204
+ Uploading as file-2.5938485188.txt...
2205
+ ↗️ Done syncing assets
2206
+ Total Upload: xx KiB / gzip: xx KiB
2207
+ Uploaded test-name (some-env) (TIMINGS)
2208
+ Published test-name (some-env) (TIMINGS)
2209
+ https://some-env.test-name.test-sub-domain.workers.dev
2210
+ Current Deployment ID: undefined"
2211
+ `);
1991
2212
  expect(std.err).toMatchInlineSnapshot(`""`);
1992
2213
  });
1993
2214
 
@@ -2028,16 +2249,17 @@ addEventListener('fetch', event => {});`
2028
2249
  await runWrangler("publish --env some-env --legacy-env true");
2029
2250
 
2030
2251
  expect(std.out).toMatchInlineSnapshot(`
2031
- "Reading file-1.txt...
2032
- Uploading as file-1.2ca234f380.txt...
2033
- Reading file-2.txt...
2034
- Uploading as file-2.5938485188.txt...
2035
- ↗️ Done syncing assets
2036
- Total Upload: 0xx KiB / gzip: 0xx KiB
2037
- Uploaded test-name-some-env (TIMINGS)
2038
- Published test-name-some-env (TIMINGS)
2039
- test-name-some-env.test-sub-domain.workers.dev"
2040
- `);
2252
+ "Reading file-1.txt...
2253
+ Uploading as file-1.2ca234f380.txt...
2254
+ Reading file-2.txt...
2255
+ Uploading as file-2.5938485188.txt...
2256
+ ↗️ Done syncing assets
2257
+ Total Upload: xx KiB / gzip: xx KiB
2258
+ Uploaded test-name-some-env (TIMINGS)
2259
+ Published test-name-some-env (TIMINGS)
2260
+ https://test-name-some-env.test-sub-domain.workers.dev
2261
+ Current Deployment ID: undefined"
2262
+ `);
2041
2263
  expect(std.err).toMatchInlineSnapshot(`""`);
2042
2264
  });
2043
2265
 
@@ -2071,16 +2293,17 @@ addEventListener('fetch', event => {});`
2071
2293
  await runWrangler("publish");
2072
2294
 
2073
2295
  expect(std.out).toMatchInlineSnapshot(`
2074
- "Reading file-1.txt...
2075
- Skipping - already uploaded.
2076
- Reading file-2.txt...
2077
- Uploading as file-2.5938485188.txt...
2078
- ↗️ Done syncing assets
2079
- Total Upload: 0xx KiB / gzip: 0xx KiB
2080
- Uploaded test-name (TIMINGS)
2081
- Published test-name (TIMINGS)
2082
- test-name.test-sub-domain.workers.dev"
2083
- `);
2296
+ "Reading file-1.txt...
2297
+ Skipping - already uploaded.
2298
+ Reading file-2.txt...
2299
+ Uploading as file-2.5938485188.txt...
2300
+ ↗️ Done syncing assets
2301
+ Total Upload: xx KiB / gzip: xx KiB
2302
+ Uploaded test-name (TIMINGS)
2303
+ Published test-name (TIMINGS)
2304
+ https://test-name.test-sub-domain.workers.dev
2305
+ Current Deployment ID: undefined"
2306
+ `);
2084
2307
  expect(std.err).toMatchInlineSnapshot(`""`);
2085
2308
  });
2086
2309
 
@@ -2113,14 +2336,15 @@ addEventListener('fetch', event => {});`
2113
2336
  await runWrangler("publish --site-include file-1.txt");
2114
2337
 
2115
2338
  expect(std.out).toMatchInlineSnapshot(`
2116
- "Reading file-1.txt...
2117
- Uploading as file-1.2ca234f380.txt...
2118
- ↗️ Done syncing assets
2119
- Total Upload: 0xx KiB / gzip: 0xx KiB
2120
- Uploaded test-name (TIMINGS)
2121
- Published test-name (TIMINGS)
2122
- test-name.test-sub-domain.workers.dev"
2123
- `);
2339
+ "Reading file-1.txt...
2340
+ Uploading as file-1.2ca234f380.txt...
2341
+ ↗️ Done syncing assets
2342
+ Total Upload: xx KiB / gzip: xx KiB
2343
+ Uploaded test-name (TIMINGS)
2344
+ Published test-name (TIMINGS)
2345
+ https://test-name.test-sub-domain.workers.dev
2346
+ Current Deployment ID: undefined"
2347
+ `);
2124
2348
  expect(std.err).toMatchInlineSnapshot(`""`);
2125
2349
  });
2126
2350
 
@@ -2153,14 +2377,15 @@ addEventListener('fetch', event => {});`
2153
2377
  await runWrangler("publish --site-exclude file-2.txt");
2154
2378
 
2155
2379
  expect(std.out).toMatchInlineSnapshot(`
2156
- "Reading file-1.txt...
2157
- Uploading as file-1.2ca234f380.txt...
2158
- ↗️ Done syncing assets
2159
- Total Upload: 0xx KiB / gzip: 0xx KiB
2160
- Uploaded test-name (TIMINGS)
2161
- Published test-name (TIMINGS)
2162
- test-name.test-sub-domain.workers.dev"
2163
- `);
2380
+ "Reading file-1.txt...
2381
+ Uploading as file-1.2ca234f380.txt...
2382
+ ↗️ Done syncing assets
2383
+ Total Upload: xx KiB / gzip: xx KiB
2384
+ Uploaded test-name (TIMINGS)
2385
+ Published test-name (TIMINGS)
2386
+ https://test-name.test-sub-domain.workers.dev
2387
+ Current Deployment ID: undefined"
2388
+ `);
2164
2389
  expect(std.err).toMatchInlineSnapshot(`""`);
2165
2390
  });
2166
2391
 
@@ -2194,14 +2419,15 @@ addEventListener('fetch', event => {});`
2194
2419
  await runWrangler("publish");
2195
2420
 
2196
2421
  expect(std.out).toMatchInlineSnapshot(`
2197
- "Reading file-1.txt...
2198
- Uploading as file-1.2ca234f380.txt...
2199
- ↗️ Done syncing assets
2200
- Total Upload: 0xx KiB / gzip: 0xx KiB
2201
- Uploaded test-name (TIMINGS)
2202
- Published test-name (TIMINGS)
2203
- test-name.test-sub-domain.workers.dev"
2204
- `);
2422
+ "Reading file-1.txt...
2423
+ Uploading as file-1.2ca234f380.txt...
2424
+ ↗️ Done syncing assets
2425
+ Total Upload: xx KiB / gzip: xx KiB
2426
+ Uploaded test-name (TIMINGS)
2427
+ Published test-name (TIMINGS)
2428
+ https://test-name.test-sub-domain.workers.dev
2429
+ Current Deployment ID: undefined"
2430
+ `);
2205
2431
  expect(std.err).toMatchInlineSnapshot(`""`);
2206
2432
  });
2207
2433
 
@@ -2235,14 +2461,15 @@ addEventListener('fetch', event => {});`
2235
2461
  await runWrangler("publish");
2236
2462
 
2237
2463
  expect(std.out).toMatchInlineSnapshot(`
2238
- "Reading file-1.txt...
2239
- Uploading as file-1.2ca234f380.txt...
2240
- ↗️ Done syncing assets
2241
- Total Upload: 0xx KiB / gzip: 0xx KiB
2242
- Uploaded test-name (TIMINGS)
2243
- Published test-name (TIMINGS)
2244
- test-name.test-sub-domain.workers.dev"
2245
- `);
2464
+ "Reading file-1.txt...
2465
+ Uploading as file-1.2ca234f380.txt...
2466
+ ↗️ Done syncing assets
2467
+ Total Upload: xx KiB / gzip: xx KiB
2468
+ Uploaded test-name (TIMINGS)
2469
+ Published test-name (TIMINGS)
2470
+ https://test-name.test-sub-domain.workers.dev
2471
+ Current Deployment ID: undefined"
2472
+ `);
2246
2473
  expect(std.err).toMatchInlineSnapshot(`""`);
2247
2474
  });
2248
2475
 
@@ -2276,14 +2503,15 @@ addEventListener('fetch', event => {});`
2276
2503
  await runWrangler("publish --site-include file-1.txt");
2277
2504
 
2278
2505
  expect(std.out).toMatchInlineSnapshot(`
2279
- "Reading file-1.txt...
2280
- Uploading as file-1.2ca234f380.txt...
2281
- ↗️ Done syncing assets
2282
- Total Upload: 0xx KiB / gzip: 0xx KiB
2283
- Uploaded test-name (TIMINGS)
2284
- Published test-name (TIMINGS)
2285
- test-name.test-sub-domain.workers.dev"
2286
- `);
2506
+ "Reading file-1.txt...
2507
+ Uploading as file-1.2ca234f380.txt...
2508
+ ↗️ Done syncing assets
2509
+ Total Upload: xx KiB / gzip: xx KiB
2510
+ Uploaded test-name (TIMINGS)
2511
+ Published test-name (TIMINGS)
2512
+ https://test-name.test-sub-domain.workers.dev
2513
+ Current Deployment ID: undefined"
2514
+ `);
2287
2515
  expect(std.err).toMatchInlineSnapshot(`""`);
2288
2516
  });
2289
2517
 
@@ -2317,14 +2545,15 @@ addEventListener('fetch', event => {});`
2317
2545
  await runWrangler("publish --site-exclude file-2.txt");
2318
2546
 
2319
2547
  expect(std.out).toMatchInlineSnapshot(`
2320
- "Reading file-1.txt...
2321
- Uploading as file-1.2ca234f380.txt...
2322
- ↗️ Done syncing assets
2323
- Total Upload: 0xx KiB / gzip: 0xx KiB
2324
- Uploaded test-name (TIMINGS)
2325
- Published test-name (TIMINGS)
2326
- test-name.test-sub-domain.workers.dev"
2327
- `);
2548
+ "Reading file-1.txt...
2549
+ Uploading as file-1.2ca234f380.txt...
2550
+ ↗️ Done syncing assets
2551
+ Total Upload: xx KiB / gzip: xx KiB
2552
+ Uploaded test-name (TIMINGS)
2553
+ Published test-name (TIMINGS)
2554
+ https://test-name.test-sub-domain.workers.dev
2555
+ Current Deployment ID: undefined"
2556
+ `);
2328
2557
  expect(std.err).toMatchInlineSnapshot(`""`);
2329
2558
  });
2330
2559
 
@@ -2360,14 +2589,15 @@ addEventListener('fetch', event => {});`
2360
2589
  await runWrangler("publish");
2361
2590
 
2362
2591
  expect(std.out).toMatchInlineSnapshot(`
2363
- "Reading directory-1/file-1.txt...
2364
- Uploading as directory-1/file-1.2ca234f380.txt...
2365
- ↗️ Done syncing assets
2366
- Total Upload: 0xx KiB / gzip: 0xx KiB
2367
- Uploaded test-name (TIMINGS)
2368
- Published test-name (TIMINGS)
2369
- test-name.test-sub-domain.workers.dev"
2370
- `);
2592
+ "Reading directory-1/file-1.txt...
2593
+ Uploading as directory-1/file-1.2ca234f380.txt...
2594
+ ↗️ Done syncing assets
2595
+ Total Upload: xx KiB / gzip: xx KiB
2596
+ Uploaded test-name (TIMINGS)
2597
+ Published test-name (TIMINGS)
2598
+ https://test-name.test-sub-domain.workers.dev
2599
+ Current Deployment ID: undefined"
2600
+ `);
2371
2601
  expect(std.err).toMatchInlineSnapshot(`""`);
2372
2602
  });
2373
2603
 
@@ -2407,14 +2637,15 @@ addEventListener('fetch', event => {});`
2407
2637
  await runWrangler("publish");
2408
2638
 
2409
2639
  expect(std.out).toMatchInlineSnapshot(`
2410
- "Reading .well-known/file-2.txt...
2411
- Uploading as .well-known/file-2.5938485188.txt...
2412
- ↗️ Done syncing assets
2413
- Total Upload: 0xx KiB / gzip: 0xx KiB
2414
- Uploaded test-name (TIMINGS)
2415
- Published test-name (TIMINGS)
2416
- test-name.test-sub-domain.workers.dev"
2417
- `);
2640
+ "Reading .well-known/file-2.txt...
2641
+ Uploading as .well-known/file-2.5938485188.txt...
2642
+ ↗️ Done syncing assets
2643
+ Total Upload: xx KiB / gzip: xx KiB
2644
+ Uploaded test-name (TIMINGS)
2645
+ Published test-name (TIMINGS)
2646
+ https://test-name.test-sub-domain.workers.dev
2647
+ Current Deployment ID: undefined"
2648
+ `);
2418
2649
  expect(std.err).toMatchInlineSnapshot(`""`);
2419
2650
  });
2420
2651
 
@@ -2515,57 +2746,58 @@ addEventListener('fetch', event => {});`
2515
2746
  }
2516
2747
 
2517
2748
  expect(std).toMatchInlineSnapshot(`
2518
- Object {
2519
- "debug": "",
2520
- "err": "",
2521
- "out": "Reading file-00.txt...
2522
- Uploading as file-00.be5be5dd26.txt...
2523
- Reading file-01.txt...
2524
- Uploading as file-01.4842d35994.txt...
2525
- Reading file-02.txt...
2526
- Uploading as file-02.990572ec63.txt...
2527
- Reading file-03.txt...
2528
- Uploading as file-03.9d7dda9045.txt...
2529
- Reading file-04.txt...
2530
- Uploading as file-04.2b6fac6382.txt...
2531
- Reading file-05.txt...
2532
- Uploading as file-05.55762dc758.txt...
2533
- Reading file-06.txt...
2534
- Uploading as file-06.f408a6b020.txt...
2535
- Reading file-07.txt...
2536
- Uploading as file-07.64c051715b.txt...
2537
- Reading file-08.txt...
2538
- Uploading as file-08.d286789adb.txt...
2539
- Reading file-09.txt...
2540
- Uploading as file-09.6838c183a8.txt...
2541
- Reading file-10.txt...
2542
- Uploading as file-10.6e03221d2a.txt...
2543
- Reading file-11.txt...
2544
- Uploading as file-11.37d3fb2eff.txt...
2545
- Reading file-12.txt...
2546
- Uploading as file-12.b3556942f8.txt...
2547
- Reading file-13.txt...
2548
- Uploading as file-13.680caf51b1.txt...
2549
- Reading file-14.txt...
2550
- Uploading as file-14.51e88468f0.txt...
2551
- Reading file-15.txt...
2552
- Uploading as file-15.8e3fedb394.txt...
2553
- Reading file-16.txt...
2554
- Uploading as file-16.c81c5e426f.txt...
2555
- Reading file-17.txt...
2556
- Uploading as file-17.4b2ae3c47b.txt...
2557
- Reading file-18.txt...
2558
- Uploading as file-18.07f245e02b.txt...
2559
- Reading file-19.txt...
2560
- Uploading as file-19.f0d69f705d.txt...
2561
- ↗️ Done syncing assets
2562
- Total Upload: 1xx KiB / gzip: 0xx KiB
2563
- Uploaded test-name (TIMINGS)
2564
- Published test-name (TIMINGS)
2565
- test-name.test-sub-domain.workers.dev",
2566
- "warn": "",
2567
- }
2568
- `);
2749
+ Object {
2750
+ "debug": "",
2751
+ "err": "",
2752
+ "out": "Reading file-00.txt...
2753
+ Uploading as file-00.be5be5dd26.txt...
2754
+ Reading file-01.txt...
2755
+ Uploading as file-01.4842d35994.txt...
2756
+ Reading file-02.txt...
2757
+ Uploading as file-02.990572ec63.txt...
2758
+ Reading file-03.txt...
2759
+ Uploading as file-03.9d7dda9045.txt...
2760
+ Reading file-04.txt...
2761
+ Uploading as file-04.2b6fac6382.txt...
2762
+ Reading file-05.txt...
2763
+ Uploading as file-05.55762dc758.txt...
2764
+ Reading file-06.txt...
2765
+ Uploading as file-06.f408a6b020.txt...
2766
+ Reading file-07.txt...
2767
+ Uploading as file-07.64c051715b.txt...
2768
+ Reading file-08.txt...
2769
+ Uploading as file-08.d286789adb.txt...
2770
+ Reading file-09.txt...
2771
+ Uploading as file-09.6838c183a8.txt...
2772
+ Reading file-10.txt...
2773
+ Uploading as file-10.6e03221d2a.txt...
2774
+ Reading file-11.txt...
2775
+ Uploading as file-11.37d3fb2eff.txt...
2776
+ Reading file-12.txt...
2777
+ Uploading as file-12.b3556942f8.txt...
2778
+ Reading file-13.txt...
2779
+ Uploading as file-13.680caf51b1.txt...
2780
+ Reading file-14.txt...
2781
+ Uploading as file-14.51e88468f0.txt...
2782
+ Reading file-15.txt...
2783
+ Uploading as file-15.8e3fedb394.txt...
2784
+ Reading file-16.txt...
2785
+ Uploading as file-16.c81c5e426f.txt...
2786
+ Reading file-17.txt...
2787
+ Uploading as file-17.4b2ae3c47b.txt...
2788
+ Reading file-18.txt...
2789
+ Uploading as file-18.07f245e02b.txt...
2790
+ Reading file-19.txt...
2791
+ Uploading as file-19.f0d69f705d.txt...
2792
+ ↗️ Done syncing assets
2793
+ Total Upload: xx KiB / gzip: xx KiB
2794
+ Uploaded test-name (TIMINGS)
2795
+ Published test-name (TIMINGS)
2796
+ https://test-name.test-sub-domain.workers.dev
2797
+ Current Deployment ID: undefined",
2798
+ "warn": "",
2799
+ }
2800
+ `);
2569
2801
  });
2570
2802
 
2571
2803
  it("should error if the asset key is over 512 characters", async () => {
@@ -2651,18 +2883,19 @@ addEventListener('fetch', event => {});`
2651
2883
  await runWrangler("publish");
2652
2884
 
2653
2885
  expect(std.out).toMatchInlineSnapshot(`
2654
- "Reading file-1.txt...
2655
- Skipping - already uploaded.
2656
- Reading file-2.txt...
2657
- Uploading as file-2.5938485188.txt...
2658
- Deleting file-3.somehash.txt from the asset store...
2659
- Deleting file-4.anotherhash.txt from the asset store...
2660
- ↗️ Done syncing assets
2661
- Total Upload: 0xx KiB / gzip: 0xx KiB
2662
- Uploaded test-name (TIMINGS)
2663
- Published test-name (TIMINGS)
2664
- test-name.test-sub-domain.workers.dev"
2665
- `);
2886
+ "Reading file-1.txt...
2887
+ Skipping - already uploaded.
2888
+ Reading file-2.txt...
2889
+ Uploading as file-2.5938485188.txt...
2890
+ Deleting file-3.somehash.txt from the asset store...
2891
+ Deleting file-4.anotherhash.txt from the asset store...
2892
+ ↗️ Done syncing assets
2893
+ Total Upload: xx KiB / gzip: xx KiB
2894
+ Uploaded test-name (TIMINGS)
2895
+ Published test-name (TIMINGS)
2896
+ https://test-name.test-sub-domain.workers.dev
2897
+ Current Deployment ID: undefined"
2898
+ `);
2666
2899
  expect(std.err).toMatchInlineSnapshot(`""`);
2667
2900
  });
2668
2901
 
@@ -2707,16 +2940,17 @@ addEventListener('fetch', event => {});`
2707
2940
  process.chdir("../");
2708
2941
 
2709
2942
  expect(std.out).toMatchInlineSnapshot(`
2710
- "Reading file-1.txt...
2711
- Uploading as file-1.2ca234f380.txt...
2712
- Reading file-2.txt...
2713
- Uploading as file-2.5938485188.txt...
2714
- ↗️ Done syncing assets
2715
- Total Upload: 0xx KiB / gzip: 0xx KiB
2716
- Uploaded test-name (TIMINGS)
2717
- Published test-name (TIMINGS)
2718
- test-name.test-sub-domain.workers.dev"
2719
- `);
2943
+ "Reading file-1.txt...
2944
+ Uploading as file-1.2ca234f380.txt...
2945
+ Reading file-2.txt...
2946
+ Uploading as file-2.5938485188.txt...
2947
+ ↗️ Done syncing assets
2948
+ Total Upload: xx KiB / gzip: xx KiB
2949
+ Uploaded test-name (TIMINGS)
2950
+ Published test-name (TIMINGS)
2951
+ https://test-name.test-sub-domain.workers.dev
2952
+ Current Deployment ID: undefined"
2953
+ `);
2720
2954
  expect(std.err).toMatchInlineSnapshot(`""`);
2721
2955
  });
2722
2956
 
@@ -2745,21 +2979,22 @@ addEventListener('fetch', event => {});`
2745
2979
  await runWrangler("publish --site .");
2746
2980
 
2747
2981
  expect(std).toMatchInlineSnapshot(`
2748
- Object {
2749
- "debug": "",
2750
- "err": "",
2751
- "out": "Reading file-1.txt...
2752
- Uploading as file-1.2ca234f380.txt...
2753
- Reading file-2.txt...
2754
- Uploading as file-2.5938485188.txt...
2755
- ↗️ Done syncing assets
2756
- Total Upload: 0xx KiB / gzip: 0xx KiB
2757
- Uploaded test-name (TIMINGS)
2758
- Published test-name (TIMINGS)
2759
- test-name.test-sub-domain.workers.dev",
2760
- "warn": "",
2761
- }
2762
- `);
2982
+ Object {
2983
+ "debug": "",
2984
+ "err": "",
2985
+ "out": "Reading file-1.txt...
2986
+ Uploading as file-1.2ca234f380.txt...
2987
+ Reading file-2.txt...
2988
+ Uploading as file-2.5938485188.txt...
2989
+ ↗️ Done syncing assets
2990
+ Total Upload: xx KiB / gzip: xx KiB
2991
+ Uploaded test-name (TIMINGS)
2992
+ Published test-name (TIMINGS)
2993
+ https://test-name.test-sub-domain.workers.dev
2994
+ Current Deployment ID: undefined",
2995
+ "warn": "",
2996
+ }
2997
+ `);
2763
2998
  });
2764
2999
 
2765
3000
  it("should use the relative path from current working directory to Worker directory when using `--assets`", async () => {
@@ -2777,7 +3012,7 @@ addEventListener('fetch', event => {});`
2777
3012
  writeWorkerSource();
2778
3013
  writeAssets(assets, "my-assets");
2779
3014
  mockUploadWorkerRequest({
2780
- expectedMainModule: "stdin.js",
3015
+ expectedMainModule: "serve-static-assets.entry.js",
2781
3016
  });
2782
3017
  mockSubDomainRequest();
2783
3018
  mockListKVNamespacesRequest(kvNamespace);
@@ -2787,23 +3022,24 @@ addEventListener('fetch', event => {});`
2787
3022
  await runWrangler("publish --assets .");
2788
3023
 
2789
3024
  expect(std).toMatchInlineSnapshot(`
2790
- Object {
2791
- "debug": "",
2792
- "err": "",
2793
- "out": "Reading file-1.txt...
2794
- Uploading as file-1.2ca234f380.txt...
2795
- Reading file-2.txt...
2796
- Uploading as file-2.5938485188.txt...
2797
- ↗️ Done syncing assets
2798
- Total Upload: 52xx KiB / gzip: 13xx KiB
2799
- Uploaded test-name (TIMINGS)
2800
- Published test-name (TIMINGS)
2801
- test-name.test-sub-domain.workers.dev",
2802
- "warn": "▲ [WARNING] The --assets argument is experimental and may change or break at any time
3025
+ Object {
3026
+ "debug": "",
3027
+ "err": "",
3028
+ "out": "Reading file-1.txt...
3029
+ Uploading as file-1.2ca234f380.txt...
3030
+ Reading file-2.txt...
3031
+ Uploading as file-2.5938485188.txt...
3032
+ ↗️ Done syncing assets
3033
+ Total Upload: xx KiB / gzip: xx KiB
3034
+ Uploaded test-name (TIMINGS)
3035
+ Published test-name (TIMINGS)
3036
+ https://test-name.test-sub-domain.workers.dev
3037
+ Current Deployment ID: undefined",
3038
+ "warn": "▲ [WARNING] The --assets argument is experimental and may change or break at any time
2803
3039
 
2804
- ",
2805
- }
2806
- `);
3040
+ ",
3041
+ }
3042
+ `);
2807
3043
  });
2808
3044
  });
2809
3045
 
@@ -2817,11 +3053,12 @@ addEventListener('fetch', event => {});`
2817
3053
  await runWrangler("publish ./index");
2818
3054
 
2819
3055
  expect(std.out).toMatchInlineSnapshot(`
2820
- "Total Upload: 0xx KiB / gzip: 0xx KiB
2821
- Uploaded test-name (TIMINGS)
2822
- Published test-name (TIMINGS)
2823
- test-name.test-sub-domain.workers.dev"
2824
- `);
3056
+ "Total Upload: xx KiB / gzip: xx KiB
3057
+ Uploaded test-name (TIMINGS)
3058
+ Published test-name (TIMINGS)
3059
+ https://test-name.test-sub-domain.workers.dev
3060
+ Current Deployment ID: undefined"
3061
+ `);
2825
3062
  expect(std.err).toMatchInlineSnapshot(`""`);
2826
3063
  });
2827
3064
 
@@ -2837,11 +3074,12 @@ addEventListener('fetch', event => {});`
2837
3074
  await runWrangler("publish ./index");
2838
3075
 
2839
3076
  expect(std.out).toMatchInlineSnapshot(`
2840
- "Total Upload: 0xx KiB / gzip: 0xx KiB
2841
- Uploaded test-name (TIMINGS)
2842
- Published test-name (TIMINGS)
2843
- test-name.test-sub-domain.workers.dev"
2844
- `);
3077
+ "Total Upload: xx KiB / gzip: xx KiB
3078
+ Uploaded test-name (TIMINGS)
3079
+ Published test-name (TIMINGS)
3080
+ https://test-name.test-sub-domain.workers.dev
3081
+ Current Deployment ID: undefined"
3082
+ `);
2845
3083
  expect(std.err).toMatchInlineSnapshot(`""`);
2846
3084
  });
2847
3085
 
@@ -2856,11 +3094,12 @@ addEventListener('fetch', event => {});`
2856
3094
  await runWrangler("publish ./index");
2857
3095
 
2858
3096
  expect(std.out).toMatchInlineSnapshot(`
2859
- "Total Upload: 0xx KiB / gzip: 0xx KiB
2860
- Uploaded test-name (TIMINGS)
2861
- Published test-name (TIMINGS)
2862
- test-name.test-sub-domain.workers.dev"
2863
- `);
3097
+ "Total Upload: xx KiB / gzip: xx KiB
3098
+ Uploaded test-name (TIMINGS)
3099
+ Published test-name (TIMINGS)
3100
+ https://test-name.test-sub-domain.workers.dev
3101
+ Current Deployment ID: undefined"
3102
+ `);
2864
3103
  expect(std.err).toMatchInlineSnapshot(`""`);
2865
3104
  });
2866
3105
 
@@ -2875,10 +3114,11 @@ addEventListener('fetch', event => {});`
2875
3114
  await runWrangler("publish ./index");
2876
3115
 
2877
3116
  expect(std.out).toMatchInlineSnapshot(`
2878
- "Total Upload: 0xx KiB / gzip: 0xx KiB
2879
- Uploaded test-name (TIMINGS)
2880
- No publish targets for test-name (TIMINGS)"
2881
- `);
3117
+ "Total Upload: xx KiB / gzip: xx KiB
3118
+ Uploaded test-name (TIMINGS)
3119
+ No publish targets for test-name (TIMINGS)
3120
+ Current Deployment ID: undefined"
3121
+ `);
2882
3122
  expect(std.err).toMatchInlineSnapshot(`""`);
2883
3123
  });
2884
3124
 
@@ -2895,10 +3135,11 @@ addEventListener('fetch', event => {});`
2895
3135
  await runWrangler("publish ./index");
2896
3136
 
2897
3137
  expect(std.out).toMatchInlineSnapshot(`
2898
- "Total Upload: 0xx KiB / gzip: 0xx KiB
2899
- Uploaded test-name (TIMINGS)
2900
- No publish targets for test-name (TIMINGS)"
2901
- `);
3138
+ "Total Upload: xx KiB / gzip: xx KiB
3139
+ Uploaded test-name (TIMINGS)
3140
+ No publish targets for test-name (TIMINGS)
3141
+ Current Deployment ID: undefined"
3142
+ `);
2902
3143
  expect(std.err).toMatchInlineSnapshot(`""`);
2903
3144
  });
2904
3145
 
@@ -2919,10 +3160,11 @@ addEventListener('fetch', event => {});`
2919
3160
  await runWrangler("publish ./index --env dev --legacy-env false");
2920
3161
 
2921
3162
  expect(std.out).toMatchInlineSnapshot(`
2922
- "Total Upload: 0xx KiB / gzip: 0xx KiB
2923
- Uploaded test-name (dev) (TIMINGS)
2924
- No publish targets for test-name (dev) (TIMINGS)"
2925
- `);
3163
+ "Total Upload: xx KiB / gzip: xx KiB
3164
+ Uploaded test-name (dev) (TIMINGS)
3165
+ No publish targets for test-name (dev) (TIMINGS)
3166
+ Current Deployment ID: undefined"
3167
+ `);
2926
3168
  expect(std.err).toMatchInlineSnapshot(`""`);
2927
3169
  });
2928
3170
 
@@ -2944,10 +3186,11 @@ addEventListener('fetch', event => {});`
2944
3186
  await runWrangler("publish ./index --env dev --legacy-env false");
2945
3187
 
2946
3188
  expect(std.out).toMatchInlineSnapshot(`
2947
- "Total Upload: 0xx KiB / gzip: 0xx KiB
2948
- Uploaded test-name (dev) (TIMINGS)
2949
- No publish targets for test-name (dev) (TIMINGS)"
2950
- `);
3189
+ "Total Upload: xx KiB / gzip: xx KiB
3190
+ Uploaded test-name (dev) (TIMINGS)
3191
+ No publish targets for test-name (dev) (TIMINGS)
3192
+ Current Deployment ID: undefined"
3193
+ `);
2951
3194
  expect(std.err).toMatchInlineSnapshot(`""`);
2952
3195
  });
2953
3196
 
@@ -2969,11 +3212,12 @@ addEventListener('fetch', event => {});`
2969
3212
  await runWrangler("publish ./index --env dev --legacy-env false");
2970
3213
 
2971
3214
  expect(std.out).toMatchInlineSnapshot(`
2972
- "Total Upload: 0xx KiB / gzip: 0xx KiB
2973
- Uploaded test-name (dev) (TIMINGS)
2974
- Published test-name (dev) (TIMINGS)
2975
- dev.test-name.test-sub-domain.workers.dev"
2976
- `);
3215
+ "Total Upload: xx KiB / gzip: xx KiB
3216
+ Uploaded test-name (dev) (TIMINGS)
3217
+ Published test-name (dev) (TIMINGS)
3218
+ https://dev.test-name.test-sub-domain.workers.dev
3219
+ Current Deployment ID: undefined"
3220
+ `);
2977
3221
  expect(std.err).toMatchInlineSnapshot(`""`);
2978
3222
  });
2979
3223
 
@@ -2996,11 +3240,12 @@ addEventListener('fetch', event => {});`
2996
3240
  await runWrangler("publish ./index --env dev --legacy-env false");
2997
3241
 
2998
3242
  expect(std.out).toMatchInlineSnapshot(`
2999
- "Total Upload: 0xx KiB / gzip: 0xx KiB
3000
- Uploaded test-name (dev) (TIMINGS)
3001
- Published test-name (dev) (TIMINGS)
3002
- dev.test-name.test-sub-domain.workers.dev"
3003
- `);
3243
+ "Total Upload: xx KiB / gzip: xx KiB
3244
+ Uploaded test-name (dev) (TIMINGS)
3245
+ Published test-name (dev) (TIMINGS)
3246
+ https://dev.test-name.test-sub-domain.workers.dev
3247
+ Current Deployment ID: undefined"
3248
+ `);
3004
3249
  expect(std.err).toMatchInlineSnapshot(`""`);
3005
3250
  });
3006
3251
 
@@ -3024,11 +3269,12 @@ addEventListener('fetch', event => {});`
3024
3269
  await runWrangler("publish ./index --env dev --legacy-env false");
3025
3270
 
3026
3271
  expect(std.out).toMatchInlineSnapshot(`
3027
- "Total Upload: 0xx KiB / gzip: 0xx KiB
3028
- Uploaded test-name (dev) (TIMINGS)
3029
- Published test-name (dev) (TIMINGS)
3030
- dev.test-name.test-sub-domain.workers.dev"
3031
- `);
3272
+ "Total Upload: xx KiB / gzip: xx KiB
3273
+ Uploaded test-name (dev) (TIMINGS)
3274
+ Published test-name (dev) (TIMINGS)
3275
+ https://dev.test-name.test-sub-domain.workers.dev
3276
+ Current Deployment ID: undefined"
3277
+ `);
3032
3278
  expect(std.err).toMatchInlineSnapshot(`""`);
3033
3279
  });
3034
3280
 
@@ -3055,11 +3301,12 @@ addEventListener('fetch', event => {});`
3055
3301
  await runWrangler("publish ./index --env dev --legacy-env false");
3056
3302
 
3057
3303
  expect(std.out).toMatchInlineSnapshot(`
3058
- "Total Upload: 0xx KiB / gzip: 0xx KiB
3059
- Uploaded test-name (dev) (TIMINGS)
3060
- Published test-name (dev) (TIMINGS)
3061
- dev.test-name.test-sub-domain.workers.dev"
3062
- `);
3304
+ "Total Upload: xx KiB / gzip: xx KiB
3305
+ Uploaded test-name (dev) (TIMINGS)
3306
+ Published test-name (dev) (TIMINGS)
3307
+ https://dev.test-name.test-sub-domain.workers.dev
3308
+ Current Deployment ID: undefined"
3309
+ `);
3063
3310
  expect(std.err).toMatchInlineSnapshot(`""`);
3064
3311
  });
3065
3312
 
@@ -3088,11 +3335,12 @@ addEventListener('fetch', event => {});`
3088
3335
  );
3089
3336
 
3090
3337
  expect(std.out).toMatchInlineSnapshot(`
3091
- "Total Upload: 0xx KiB / gzip: 0xx KiB
3092
- Uploaded test-name (dev) (TIMINGS)
3093
- Published test-name (dev) (TIMINGS)
3094
- dev.test-name.test-sub-domain.workers.dev"
3095
- `);
3338
+ "Total Upload: xx KiB / gzip: xx KiB
3339
+ Uploaded test-name (dev) (TIMINGS)
3340
+ Published test-name (dev) (TIMINGS)
3341
+ https://dev.test-name.test-sub-domain.workers.dev
3342
+ Current Deployment ID: undefined"
3343
+ `);
3096
3344
  expect(std.err).toMatchInlineSnapshot(`""`);
3097
3345
  });
3098
3346
 
@@ -3115,6 +3363,29 @@ addEventListener('fetch', event => {});`
3115
3363
  `);
3116
3364
  });
3117
3365
 
3366
+ it("should error if a compatibility_date is missing and suggest the correct month", async () => {
3367
+ jest.spyOn(Date.prototype, "getMonth").mockImplementation(() => 11);
3368
+ jest.spyOn(Date.prototype, "getFullYear").mockImplementation(() => 2020);
3369
+ jest.spyOn(Date.prototype, "getDate").mockImplementation(() => 1);
3370
+
3371
+ writeWorkerSource();
3372
+ let err: undefined | Error;
3373
+ try {
3374
+ await runWrangler("publish ./index.js");
3375
+ } catch (e) {
3376
+ err = e as Error;
3377
+ }
3378
+
3379
+ expect(err?.message).toMatchInlineSnapshot(`
3380
+ "A compatibility_date is required when publishing. Add the following to your wrangler.toml file:.
3381
+ \`\`\`
3382
+ compatibility_date = \\"2020-12-01\\"
3383
+ \`\`\`
3384
+ Or you could pass it in your terminal as \`--compatibility-date 2020-12-01\`
3385
+ See https://developers.cloudflare.com/workers/platform/compatibility-dates for more information."
3386
+ `);
3387
+ });
3388
+
3118
3389
  it("should enable the workers.dev domain if workers_dev is undefined and subdomain is not already available", async () => {
3119
3390
  writeWranglerToml();
3120
3391
  writeWorkerSource();
@@ -3125,11 +3396,12 @@ addEventListener('fetch', event => {});`
3125
3396
  await runWrangler("publish ./index");
3126
3397
 
3127
3398
  expect(std.out).toMatchInlineSnapshot(`
3128
- "Total Upload: 0xx KiB / gzip: 0xx KiB
3129
- Uploaded test-name (TIMINGS)
3130
- Published test-name (TIMINGS)
3131
- test-name.test-sub-domain.workers.dev"
3132
- `);
3399
+ "Total Upload: xx KiB / gzip: xx KiB
3400
+ Uploaded test-name (TIMINGS)
3401
+ Published test-name (TIMINGS)
3402
+ https://test-name.test-sub-domain.workers.dev
3403
+ Current Deployment ID: undefined"
3404
+ `);
3133
3405
  expect(std.err).toMatchInlineSnapshot(`""`);
3134
3406
  });
3135
3407
 
@@ -3143,15 +3415,16 @@ addEventListener('fetch', event => {});`
3143
3415
  await runWrangler("publish ./index");
3144
3416
 
3145
3417
  expect(std.out).toMatchInlineSnapshot(`
3146
- "Total Upload: 0xx KiB / gzip: 0xx KiB
3147
- Uploaded test-name (TIMINGS)
3148
- Published test-name (TIMINGS)
3149
- test-name.test-sub-domain.workers.dev"
3150
- `);
3418
+ "Total Upload: xx KiB / gzip: xx KiB
3419
+ Uploaded test-name (TIMINGS)
3420
+ Published test-name (TIMINGS)
3421
+ https://test-name.test-sub-domain.workers.dev
3422
+ Current Deployment ID: undefined"
3423
+ `);
3151
3424
  expect(std.err).toMatchInlineSnapshot(`""`);
3152
3425
  });
3153
3426
 
3154
- it("should error politely when publishing to workers_dev when there is no workers.dev subdomain", async () => {
3427
+ it("should offer to create a new workers.dev subdomain when publishing to workers_dev without one", async () => {
3155
3428
  writeWranglerToml({
3156
3429
  workers_dev: true,
3157
3430
  });
@@ -3159,12 +3432,16 @@ addEventListener('fetch', event => {});`
3159
3432
  mockUploadWorkerRequest();
3160
3433
  mockSubDomainRequest("does-not-exist", false);
3161
3434
 
3435
+ mockConfirm({
3436
+ text: `Would you like to register a workers.dev subdomain now?`,
3437
+ result: false,
3438
+ });
3439
+
3162
3440
  await expect(runWrangler("publish ./index")).rejects
3163
3441
  .toThrowErrorMatchingInlineSnapshot(`
3164
- "Error: You need to register a workers.dev subdomain before publishing to workers.dev
3165
- You can either publish your worker to one or more routes by specifying them in wrangler.toml, or register a workers.dev subdomain here:
3166
- https://dash.cloudflare.com/some-account-id/workers/onboarding"
3167
- `);
3442
+ "You can either publish your worker to one or more routes by specifying them in wrangler.toml, or register a workers.dev subdomain here:
3443
+ https://dash.cloudflare.com/some-account-id/workers/onboarding"
3444
+ `);
3168
3445
  });
3169
3446
 
3170
3447
  it("should not deploy to workers.dev if there are any routes defined", async () => {
@@ -3181,11 +3458,12 @@ addEventListener('fetch', event => {});`
3181
3458
  await runWrangler("publish index.js");
3182
3459
 
3183
3460
  expect(std.out).toMatchInlineSnapshot(`
3184
- "Total Upload: 0xx KiB / gzip: 0xx KiB
3185
- Uploaded test-name (TIMINGS)
3186
- Published test-name (TIMINGS)
3187
- http://example.com/*"
3188
- `);
3461
+ "Total Upload: xx KiB / gzip: xx KiB
3462
+ Uploaded test-name (TIMINGS)
3463
+ Published test-name (TIMINGS)
3464
+ http://example.com/*
3465
+ Current Deployment ID: undefined"
3466
+ `);
3189
3467
  expect(std.err).toMatchInlineSnapshot(`""`);
3190
3468
  expect(std.warn).toMatchInlineSnapshot(`""`);
3191
3469
  });
@@ -3215,11 +3493,12 @@ addEventListener('fetch', event => {});`
3215
3493
  await runWrangler("publish index.js --env production");
3216
3494
 
3217
3495
  expect(std.out).toMatchInlineSnapshot(`
3218
- "Total Upload: 0xx KiB / gzip: 0xx KiB
3219
- Uploaded test-name-production (TIMINGS)
3220
- Published test-name-production (TIMINGS)
3221
- http://production.example.com/*"
3222
- `);
3496
+ "Total Upload: xx KiB / gzip: xx KiB
3497
+ Uploaded test-name-production (TIMINGS)
3498
+ Published test-name-production (TIMINGS)
3499
+ http://production.example.com/*
3500
+ Current Deployment ID: undefined"
3501
+ `);
3223
3502
  expect(std.err).toMatchInlineSnapshot(`""`);
3224
3503
  expect(std.warn).toMatchInlineSnapshot(`""`);
3225
3504
  });
@@ -3248,11 +3527,12 @@ addEventListener('fetch', event => {});`
3248
3527
  await runWrangler("publish index.js --env production");
3249
3528
 
3250
3529
  expect(std.out).toMatchInlineSnapshot(`
3251
- "Total Upload: 0xx KiB / gzip: 0xx KiB
3252
- Uploaded test-name-production (TIMINGS)
3253
- Published test-name-production (TIMINGS)
3254
- http://production.example.com/*"
3255
- `);
3530
+ "Total Upload: xx KiB / gzip: xx KiB
3531
+ Uploaded test-name-production (TIMINGS)
3532
+ Published test-name-production (TIMINGS)
3533
+ http://production.example.com/*
3534
+ Current Deployment ID: undefined"
3535
+ `);
3256
3536
  expect(std.err).toMatchInlineSnapshot(`""`);
3257
3537
  expect(std.warn).toMatchInlineSnapshot(`""`);
3258
3538
  });
@@ -3274,12 +3554,13 @@ addEventListener('fetch', event => {});`
3274
3554
  await runWrangler("publish index.js");
3275
3555
 
3276
3556
  expect(std.out).toMatchInlineSnapshot(`
3277
- "Total Upload: 0xx KiB / gzip: 0xx KiB
3278
- Uploaded test-name (TIMINGS)
3279
- Published test-name (TIMINGS)
3280
- test-name.test-sub-domain.workers.dev
3281
- http://example.com/*"
3282
- `);
3557
+ "Total Upload: xx KiB / gzip: xx KiB
3558
+ Uploaded test-name (TIMINGS)
3559
+ Published test-name (TIMINGS)
3560
+ https://test-name.test-sub-domain.workers.dev
3561
+ http://example.com/*
3562
+ Current Deployment ID: undefined"
3563
+ `);
3283
3564
  expect(std.err).toMatchInlineSnapshot(`""`);
3284
3565
  expect(std.warn).toMatchInlineSnapshot(`""`);
3285
3566
  });
@@ -3309,12 +3590,13 @@ addEventListener('fetch', event => {});`
3309
3590
  await runWrangler("publish index.js --env production");
3310
3591
 
3311
3592
  expect(std.out).toMatchInlineSnapshot(`
3312
- "Total Upload: 0xx KiB / gzip: 0xx KiB
3313
- Uploaded test-name-production (TIMINGS)
3314
- Published test-name-production (TIMINGS)
3315
- test-name-production.test-sub-domain.workers.dev
3316
- http://production.example.com/*"
3317
- `);
3593
+ "Total Upload: xx KiB / gzip: xx KiB
3594
+ Uploaded test-name-production (TIMINGS)
3595
+ Published test-name-production (TIMINGS)
3596
+ https://test-name-production.test-sub-domain.workers.dev
3597
+ http://production.example.com/*
3598
+ Current Deployment ID: undefined"
3599
+ `);
3318
3600
  expect(std.err).toMatchInlineSnapshot(`""`);
3319
3601
  expect(std.warn).toMatchInlineSnapshot(`""`);
3320
3602
  });
@@ -3344,12 +3626,13 @@ addEventListener('fetch', event => {});`
3344
3626
  await runWrangler("publish index.js --env production");
3345
3627
 
3346
3628
  expect(std.out).toMatchInlineSnapshot(`
3347
- "Total Upload: 0xx KiB / gzip: 0xx KiB
3348
- Uploaded test-name-production (TIMINGS)
3349
- Published test-name-production (TIMINGS)
3350
- test-name-production.test-sub-domain.workers.dev
3351
- http://production.example.com/*"
3352
- `);
3629
+ "Total Upload: xx KiB / gzip: xx KiB
3630
+ Uploaded test-name-production (TIMINGS)
3631
+ Published test-name-production (TIMINGS)
3632
+ https://test-name-production.test-sub-domain.workers.dev
3633
+ http://production.example.com/*
3634
+ Current Deployment ID: undefined"
3635
+ `);
3353
3636
  expect(std.err).toMatchInlineSnapshot(`""`);
3354
3637
  expect(std.warn).toMatchInlineSnapshot(`""`);
3355
3638
  });
@@ -3379,11 +3662,12 @@ addEventListener('fetch', event => {});`
3379
3662
  await runWrangler("publish index.js --env production");
3380
3663
 
3381
3664
  expect(std.out).toMatchInlineSnapshot(`
3382
- "Total Upload: 0xx KiB / gzip: 0xx KiB
3383
- Uploaded test-name-production (TIMINGS)
3384
- Published test-name-production (TIMINGS)
3385
- http://production.example.com/*"
3386
- `);
3665
+ "Total Upload: xx KiB / gzip: xx KiB
3666
+ Uploaded test-name-production (TIMINGS)
3667
+ Published test-name-production (TIMINGS)
3668
+ http://production.example.com/*
3669
+ Current Deployment ID: undefined"
3670
+ `);
3387
3671
  expect(std.err).toMatchInlineSnapshot(`""`);
3388
3672
  expect(std.warn).toMatchInlineSnapshot(`""`);
3389
3673
  });
@@ -3413,11 +3697,12 @@ addEventListener('fetch', event => {});`
3413
3697
  await runWrangler("publish index.js --env production");
3414
3698
 
3415
3699
  expect(std.out).toMatchInlineSnapshot(`
3416
- "Total Upload: 0xx KiB / gzip: 0xx KiB
3417
- Uploaded test-name-production (TIMINGS)
3418
- Published test-name-production (TIMINGS)
3419
- http://production.example.com/*"
3420
- `);
3700
+ "Total Upload: xx KiB / gzip: xx KiB
3701
+ Uploaded test-name-production (TIMINGS)
3702
+ Published test-name-production (TIMINGS)
3703
+ http://production.example.com/*
3704
+ Current Deployment ID: undefined"
3705
+ `);
3421
3706
  expect(std.err).toMatchInlineSnapshot(`""`);
3422
3707
  expect(std.warn).toMatchInlineSnapshot(`""`);
3423
3708
  });
@@ -3451,20 +3736,17 @@ addEventListener('fetch', event => {});`
3451
3736
  mockSubDomainRequest();
3452
3737
  mockUploadWorkerRequest();
3453
3738
  await runWrangler("build");
3454
- expect(fs.readFileSync("dist/index.js", "utf-8")).toMatchInlineSnapshot(`
3455
- "(() => {
3456
- // index.js
3457
- console.log(123);
3458
- console.log(globalThis.abc);
3459
- function foo() {
3460
- const abc2 = \\"a string\\";
3461
- console.log(abc2);
3462
- }
3463
- console.log(foo);
3464
- })();
3465
- //# sourceMappingURL=index.js.map
3466
- "
3467
- `);
3739
+
3740
+ const outFile = normalizeSlashes(
3741
+ normalizeTempDirs(fs.readFileSync("dist/index.js", "utf-8"))
3742
+ );
3743
+
3744
+ // We don't check against the whole file as there is middleware being injected
3745
+ expect(outFile).toContain("console.log(123);");
3746
+ expect(outFile).toContain("console.log(globalThis.abc);");
3747
+ expect(outFile).toContain(`const abc2 = "a string";`);
3748
+ expect(outFile).toContain("console.log(abc2);");
3749
+ expect(outFile).toContain("console.log(foo);");
3468
3750
  });
3469
3751
 
3470
3752
  it("can be overriden in environments", async () => {
@@ -3490,17 +3772,62 @@ addEventListener('fetch', event => {});`
3490
3772
  mockSubDomainRequest();
3491
3773
  mockUploadWorkerRequest();
3492
3774
  await runWrangler("build --env staging");
3493
- expect(fs.readFileSync("dist/index.js", "utf-8")).toMatchInlineSnapshot(`
3494
- "(() => {
3495
- // index.js
3496
- console.log(456);
3497
- })();
3498
- //# sourceMappingURL=index.js.map
3499
- "
3500
- `);
3775
+
3776
+ const outFile = normalizeSlashes(
3777
+ normalizeTempDirs(fs.readFileSync("dist/index.js", "utf-8"))
3778
+ );
3779
+
3780
+ // We don't check against the whole file as there is middleware being injected
3781
+ expect(outFile).toContain("console.log(456);");
3501
3782
  });
3502
- });
3503
3783
 
3784
+ it("can be overridden with cli args", async () => {
3785
+ writeWranglerToml({
3786
+ main: "index.js",
3787
+ define: {
3788
+ abc: "123",
3789
+ },
3790
+ });
3791
+ fs.writeFileSync(
3792
+ "index.js",
3793
+ `
3794
+ console.log(abc);
3795
+ `
3796
+ );
3797
+ mockSubDomainRequest();
3798
+ mockUploadWorkerRequest();
3799
+ await runWrangler("publish --dry-run --outdir dist --define abc:789");
3800
+
3801
+ expect(fs.readFileSync("dist/index.js", "utf-8")).toContain(
3802
+ `console.log(789);`
3803
+ );
3804
+ });
3805
+
3806
+ it("can be overridden with cli args containing colons", async () => {
3807
+ writeWranglerToml({
3808
+ main: "index.js",
3809
+ define: {
3810
+ abc: "123",
3811
+ },
3812
+ });
3813
+ fs.writeFileSync(
3814
+ "index.js",
3815
+ `
3816
+ console.log(abc);
3817
+ `
3818
+ );
3819
+ mockSubDomainRequest();
3820
+ mockUploadWorkerRequest();
3821
+ await runWrangler(
3822
+ "publish --dry-run --outdir dist --define abc:'https://www.abc.net.au/news/'"
3823
+ );
3824
+
3825
+ expect(fs.readFileSync("dist/index.js", "utf-8")).toContain(
3826
+ // eslint-disable-next-line no-useless-escape
3827
+ `console.log(\"https://www.abc.net.au/news/\");`
3828
+ );
3829
+ });
3830
+ });
3504
3831
  describe("custom builds", () => {
3505
3832
  beforeEach(() => {
3506
3833
  // @ts-expect-error disable the mock we'd setup earlier
@@ -3521,14 +3848,15 @@ addEventListener('fetch', event => {});`
3521
3848
 
3522
3849
  await runWrangler("publish index.js");
3523
3850
  expect(std.out).toMatchInlineSnapshot(`
3524
- "Running custom build: node -e \\"console.log('custom build'); require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')\\"
3525
- Total Upload: 0xx KiB / gzip: 0xx KiB
3526
- Uploaded test-name (TIMINGS)
3527
- Published test-name (TIMINGS)
3528
- test-name.test-sub-domain.workers.dev"
3529
- `);
3530
- expect(std.err).toMatchInlineSnapshot(`""`);
3531
- expect(std.warn).toMatchInlineSnapshot(`""`);
3851
+ "Running custom build: node -e \\"console.log('custom build'); require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')\\"
3852
+ Total Upload: xx KiB / gzip: xx KiB
3853
+ Uploaded test-name (TIMINGS)
3854
+ Published test-name (TIMINGS)
3855
+ https://test-name.test-sub-domain.workers.dev
3856
+ Current Deployment ID: undefined"
3857
+ `);
3858
+ expect(std.err).toMatchInlineSnapshot(`""`);
3859
+ expect(std.warn).toMatchInlineSnapshot(`""`);
3532
3860
  });
3533
3861
 
3534
3862
  if (process.platform !== "win32") {
@@ -3546,12 +3874,13 @@ addEventListener('fetch', event => {});`
3546
3874
 
3547
3875
  await runWrangler("publish index.js");
3548
3876
  expect(std.out).toMatchInlineSnapshot(`
3549
- "Running custom build: echo \\"custom build\\" && echo \\"export default { fetch(){ return new Response(123) } }\\" > index.js
3550
- Total Upload: 0xx KiB / gzip: 0xx KiB
3551
- Uploaded test-name (TIMINGS)
3552
- Published test-name (TIMINGS)
3553
- test-name.test-sub-domain.workers.dev"
3554
- `);
3877
+ "Running custom build: echo \\"custom build\\" && echo \\"export default { fetch(){ return new Response(123) } }\\" > index.js
3878
+ Total Upload: xx KiB / gzip: xx KiB
3879
+ Uploaded test-name (TIMINGS)
3880
+ Published test-name (TIMINGS)
3881
+ https://test-name.test-sub-domain.workers.dev
3882
+ Current Deployment ID: undefined"
3883
+ `);
3555
3884
  expect(std.err).toMatchInlineSnapshot(`""`);
3556
3885
  expect(std.warn).toMatchInlineSnapshot(`""`);
3557
3886
  });
@@ -3567,9 +3896,9 @@ addEventListener('fetch', event => {});`
3567
3896
 
3568
3897
  await expect(runWrangler("publish index.js")).rejects
3569
3898
  .toThrowErrorMatchingInlineSnapshot(`
3570
- "The expected output file at \\"index.js\\" was not found after running custom build: node -e \\"console.log('custom build');\\".
3571
- The \`main\` property in wrangler.toml should point to the file generated by the custom build."
3572
- `);
3899
+ "The expected output file at \\"index.js\\" was not found after running custom build: node -e \\"console.log('custom build');\\".
3900
+ The \`main\` property in wrangler.toml should point to the file generated by the custom build."
3901
+ `);
3573
3902
  expect(std.out).toMatchInlineSnapshot(`
3574
3903
  "Running custom build: node -e \\"console.log('custom build');\\"
3575
3904
 
@@ -3599,16 +3928,16 @@ addEventListener('fetch', event => {});`
3599
3928
 
3600
3929
  await expect(runWrangler("publish")).rejects
3601
3930
  .toThrowErrorMatchingInlineSnapshot(`
3602
- "The expected output file at \\".\\" was not found after running custom build: node -e \\"console.log('custom build');\\".
3603
- The \`main\` property in wrangler.toml should point to the file generated by the custom build.
3604
- The provided entry-point path, \\".\\", points to a directory, rather than a file.
3605
-
3606
- Did you mean to set the main field to one of:
3607
- \`\`\`
3608
- main = \\"./worker.js\\"
3609
- main = \\"./dist/index.ts\\"
3610
- \`\`\`"
3611
- `);
3931
+ "The expected output file at \\".\\" was not found after running custom build: node -e \\"console.log('custom build');\\".
3932
+ The \`main\` property in wrangler.toml should point to the file generated by the custom build.
3933
+ The provided entry-point path, \\".\\", points to a directory, rather than a file.
3934
+
3935
+ Did you mean to set the main field to one of:
3936
+ \`\`\`
3937
+ main = \\"./worker.js\\"
3938
+ main = \\"./dist/index.ts\\"
3939
+ \`\`\`"
3940
+ `);
3612
3941
  expect(std.out).toMatchInlineSnapshot(`
3613
3942
  "Running custom build: node -e \\"console.log('custom build');\\"
3614
3943
 
@@ -3653,11 +3982,12 @@ addEventListener('fetch', event => {});`
3653
3982
  mockSubDomainRequest();
3654
3983
  await runWrangler("publish index.js --minify");
3655
3984
  expect(std.out).toMatchInlineSnapshot(`
3656
- "Total Upload: 0xx KiB / gzip: 0xx KiB
3657
- Uploaded test-name (TIMINGS)
3658
- Published test-name (TIMINGS)
3659
- test-name.test-sub-domain.workers.dev"
3660
- `);
3985
+ "Total Upload: xx KiB / gzip: xx KiB
3986
+ Uploaded test-name (TIMINGS)
3987
+ Published test-name (TIMINGS)
3988
+ https://test-name.test-sub-domain.workers.dev
3989
+ Current Deployment ID: undefined"
3990
+ `);
3661
3991
  expect(std.err).toMatchInlineSnapshot(`""`);
3662
3992
  });
3663
3993
 
@@ -3692,11 +4022,12 @@ addEventListener('fetch', event => {});`
3692
4022
  mockSubDomainRequest();
3693
4023
  await runWrangler("publish -e testEnv index.js");
3694
4024
  expect(std.out).toMatchInlineSnapshot(`
3695
- "Total Upload: 0xx KiB / gzip: 0xx KiB
3696
- Uploaded test-name (testEnv) (TIMINGS)
3697
- Published test-name (testEnv) (TIMINGS)
3698
- testEnv.test-name.test-sub-domain.workers.dev"
3699
- `);
4025
+ "Total Upload: xx KiB / gzip: xx KiB
4026
+ Uploaded test-name (testEnv) (TIMINGS)
4027
+ Published test-name (testEnv) (TIMINGS)
4028
+ https://testEnv.test-name.test-sub-domain.workers.dev
4029
+ Current Deployment ID: undefined"
4030
+ `);
3700
4031
  expect(std.err).toMatchInlineSnapshot(`""`);
3701
4032
  });
3702
4033
  });
@@ -3716,14 +4047,15 @@ addEventListener('fetch', event => {});`
3716
4047
  mockUploadWorkerRequest();
3717
4048
  await runWrangler("publish index.js");
3718
4049
  expect(std.out).toMatchInlineSnapshot(`
3719
- "Your worker has access to the following bindings:
3720
- - Durable Objects:
3721
- - SOMENAME: SomeClass
3722
- Total Upload: 0xx KiB / gzip: 0xx KiB
3723
- Uploaded test-name (TIMINGS)
3724
- Published test-name (TIMINGS)
3725
- test-name.test-sub-domain.workers.dev"
3726
- `);
4050
+ "Total Upload: xx KiB / gzip: xx KiB
4051
+ Your worker has access to the following bindings:
4052
+ - Durable Objects:
4053
+ - SOMENAME: SomeClass
4054
+ Uploaded test-name (TIMINGS)
4055
+ Published test-name (TIMINGS)
4056
+ https://test-name.test-sub-domain.workers.dev
4057
+ Current Deployment ID: undefined"
4058
+ `);
3727
4059
  expect(std.err).toMatchInlineSnapshot(`""`);
3728
4060
  expect(std.warn).toMatchInlineSnapshot(`
3729
4061
  "▲ [WARNING] Processing wrangler.toml configuration:
@@ -3766,14 +4098,15 @@ addEventListener('fetch', event => {});`
3766
4098
  mockUploadWorkerRequest();
3767
4099
  await runWrangler("publish index.js");
3768
4100
  expect(std.out).toMatchInlineSnapshot(`
3769
- "Your worker has access to the following bindings:
3770
- - Durable Objects:
3771
- - SOMENAME: SomeClass (defined in some-script)
3772
- Total Upload: 0xx KiB / gzip: 0xx KiB
3773
- Uploaded test-name (TIMINGS)
3774
- Published test-name (TIMINGS)
3775
- test-name.test-sub-domain.workers.dev"
3776
- `);
4101
+ "Total Upload: xx KiB / gzip: xx KiB
4102
+ Your worker has access to the following bindings:
4103
+ - Durable Objects:
4104
+ - SOMENAME: SomeClass (defined in some-script)
4105
+ Uploaded test-name (TIMINGS)
4106
+ Published test-name (TIMINGS)
4107
+ https://test-name.test-sub-domain.workers.dev
4108
+ Current Deployment ID: undefined"
4109
+ `);
3777
4110
  expect(std.err).toMatchInlineSnapshot(`""`);
3778
4111
  expect(std.warn).toMatchInlineSnapshot(`""`);
3779
4112
  });
@@ -3809,15 +4142,16 @@ addEventListener('fetch', event => {});`
3809
4142
 
3810
4143
  await runWrangler("publish index.js");
3811
4144
  expect(std.out).toMatchInlineSnapshot(`
3812
- "Your worker has access to the following bindings:
3813
- - Durable Objects:
3814
- - SOMENAME: SomeClass
3815
- - SOMEOTHERNAME: SomeOtherClass
3816
- Total Upload: 0xx KiB / gzip: 0xx KiB
3817
- Uploaded test-name (TIMINGS)
3818
- Published test-name (TIMINGS)
3819
- test-name.test-sub-domain.workers.dev"
3820
- `);
4145
+ "Total Upload: xx KiB / gzip: xx KiB
4146
+ Your worker has access to the following bindings:
4147
+ - Durable Objects:
4148
+ - SOMENAME: SomeClass
4149
+ - SOMEOTHERNAME: SomeOtherClass
4150
+ Uploaded test-name (TIMINGS)
4151
+ Published test-name (TIMINGS)
4152
+ https://test-name.test-sub-domain.workers.dev
4153
+ Current Deployment ID: undefined"
4154
+ `);
3821
4155
  expect(std.err).toMatchInlineSnapshot(`""`);
3822
4156
  expect(std.warn).toMatchInlineSnapshot(`""`);
3823
4157
  });
@@ -3857,20 +4191,21 @@ addEventListener('fetch', event => {});`
3857
4191
 
3858
4192
  await runWrangler("publish index.js");
3859
4193
  expect(std).toMatchInlineSnapshot(`
3860
- Object {
3861
- "debug": "",
3862
- "err": "",
3863
- "out": "Your worker has access to the following bindings:
3864
- - Durable Objects:
3865
- - SOMENAME: SomeClass
3866
- - SOMEOTHERNAME: SomeOtherClass
3867
- Total Upload: 0xx KiB / gzip: 0xx KiB
3868
- Uploaded test-name (TIMINGS)
3869
- Published test-name (TIMINGS)
3870
- test-name.test-sub-domain.workers.dev",
3871
- "warn": "",
3872
- }
3873
- `);
4194
+ Object {
4195
+ "debug": "",
4196
+ "err": "",
4197
+ "out": "Total Upload: xx KiB / gzip: xx KiB
4198
+ Your worker has access to the following bindings:
4199
+ - Durable Objects:
4200
+ - SOMENAME: SomeClass
4201
+ - SOMEOTHERNAME: SomeOtherClass
4202
+ Uploaded test-name (TIMINGS)
4203
+ Published test-name (TIMINGS)
4204
+ https://test-name.test-sub-domain.workers.dev
4205
+ Current Deployment ID: undefined",
4206
+ "warn": "",
4207
+ }
4208
+ `);
3874
4209
  });
3875
4210
 
3876
4211
  it("should not send migrations if they've all already been sent", async () => {
@@ -3901,20 +4236,21 @@ addEventListener('fetch', event => {});`
3901
4236
 
3902
4237
  await runWrangler("publish index.js");
3903
4238
  expect(std).toMatchInlineSnapshot(`
3904
- Object {
3905
- "debug": "",
3906
- "err": "",
3907
- "out": "Your worker has access to the following bindings:
3908
- - Durable Objects:
3909
- - SOMENAME: SomeClass
3910
- - SOMEOTHERNAME: SomeOtherClass
3911
- Total Upload: 0xx KiB / gzip: 0xx KiB
3912
- Uploaded test-name (TIMINGS)
3913
- Published test-name (TIMINGS)
3914
- test-name.test-sub-domain.workers.dev",
3915
- "warn": "",
3916
- }
3917
- `);
4239
+ Object {
4240
+ "debug": "",
4241
+ "err": "",
4242
+ "out": "Total Upload: xx KiB / gzip: xx KiB
4243
+ Your worker has access to the following bindings:
4244
+ - Durable Objects:
4245
+ - SOMENAME: SomeClass
4246
+ - SOMEOTHERNAME: SomeOtherClass
4247
+ Uploaded test-name (TIMINGS)
4248
+ Published test-name (TIMINGS)
4249
+ https://test-name.test-sub-domain.workers.dev
4250
+ Current Deployment ID: undefined",
4251
+ "warn": "",
4252
+ }
4253
+ `);
3918
4254
  });
3919
4255
 
3920
4256
  describe("service environments", () => {
@@ -3950,15 +4286,16 @@ addEventListener('fetch', event => {});`
3950
4286
 
3951
4287
  await runWrangler("publish index.js --legacy-env false");
3952
4288
  expect(std.out).toMatchInlineSnapshot(`
3953
- "Your worker has access to the following bindings:
3954
- - Durable Objects:
3955
- - SOMENAME: SomeClass
3956
- - SOMEOTHERNAME: SomeOtherClass
3957
- Total Upload: 0xx KiB / gzip: 0xx KiB
3958
- Uploaded test-name (TIMINGS)
3959
- Published test-name (TIMINGS)
3960
- test-name.test-sub-domain.workers.dev"
3961
- `);
4289
+ "Total Upload: xx KiB / gzip: xx KiB
4290
+ Your worker has access to the following bindings:
4291
+ - Durable Objects:
4292
+ - SOMENAME: SomeClass
4293
+ - SOMEOTHERNAME: SomeOtherClass
4294
+ Uploaded test-name (TIMINGS)
4295
+ Published test-name (TIMINGS)
4296
+ https://test-name.test-sub-domain.workers.dev
4297
+ Current Deployment ID: undefined"
4298
+ `);
3962
4299
  expect(std.err).toMatchInlineSnapshot(`""`);
3963
4300
  expect(std.warn).toMatchInlineSnapshot(`
3964
4301
  "▲ [WARNING] Processing wrangler.toml configuration:
@@ -4013,15 +4350,16 @@ addEventListener('fetch', event => {});`
4013
4350
 
4014
4351
  await runWrangler("publish index.js --legacy-env false --env xyz");
4015
4352
  expect(std.out).toMatchInlineSnapshot(`
4016
- "Your worker has access to the following bindings:
4017
- - Durable Objects:
4018
- - SOMENAME: SomeClass
4019
- - SOMEOTHERNAME: SomeOtherClass
4020
- Total Upload: 0xx KiB / gzip: 0xx KiB
4021
- Uploaded test-name (xyz) (TIMINGS)
4022
- Published test-name (xyz) (TIMINGS)
4023
- xyz.test-name.test-sub-domain.workers.dev"
4024
- `);
4353
+ "Total Upload: xx KiB / gzip: xx KiB
4354
+ Your worker has access to the following bindings:
4355
+ - Durable Objects:
4356
+ - SOMENAME: SomeClass
4357
+ - SOMEOTHERNAME: SomeOtherClass
4358
+ Uploaded test-name (xyz) (TIMINGS)
4359
+ Published test-name (xyz) (TIMINGS)
4360
+ https://xyz.test-name.test-sub-domain.workers.dev
4361
+ Current Deployment ID: undefined"
4362
+ `);
4025
4363
  expect(std.err).toMatchInlineSnapshot(`""`);
4026
4364
  expect(std.warn).toMatchInlineSnapshot(`
4027
4365
  "▲ [WARNING] Processing wrangler.toml configuration:
@@ -4034,6 +4372,7 @@ addEventListener('fetch', event => {});`
4034
4372
  });
4035
4373
 
4036
4374
  it("should use a script's current migration tag when publishing migrations", async () => {
4375
+ unsetAllMocks();
4037
4376
  writeWranglerToml({
4038
4377
  durable_objects: {
4039
4378
  bindings: [
@@ -4066,28 +4405,35 @@ addEventListener('fetch', event => {});`
4066
4405
  ],
4067
4406
  },
4068
4407
  });
4408
+ setMockResponse(
4409
+ "/accounts/:accountId/workers/deployments/by-script/:scriptTag",
4410
+ () => ({
4411
+ latest: { number: "2" },
4412
+ })
4413
+ );
4069
4414
 
4070
4415
  await runWrangler("publish index.js --legacy-env false");
4071
4416
  expect(std).toMatchInlineSnapshot(`
4072
- Object {
4073
- "debug": "",
4074
- "err": "",
4075
- "out": "Your worker has access to the following bindings:
4076
- - Durable Objects:
4077
- - SOMENAME: SomeClass
4078
- - SOMEOTHERNAME: SomeOtherClass
4079
- Total Upload: 0xx KiB / gzip: 0xx KiB
4080
- Uploaded test-name (TIMINGS)
4081
- Published test-name (TIMINGS)
4082
- test-name.test-sub-domain.workers.dev",
4083
- "warn": "▲ [WARNING] Processing wrangler.toml configuration:
4417
+ Object {
4418
+ "debug": "",
4419
+ "err": "",
4420
+ "out": "Total Upload: xx KiB / gzip: xx KiB
4421
+ Your worker has access to the following bindings:
4422
+ - Durable Objects:
4423
+ - SOMENAME: SomeClass
4424
+ - SOMEOTHERNAME: SomeOtherClass
4425
+ Uploaded test-name (TIMINGS)
4426
+ Published test-name (TIMINGS)
4427
+ https://test-name.test-sub-domain.workers.dev
4428
+ Current Deployment ID: undefined",
4429
+ "warn": "▲ [WARNING] Processing wrangler.toml configuration:
4084
4430
 
4085
- - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in
4086
- the future. DO NOT USE IN PRODUCTION.
4431
+ - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in
4432
+ the future. DO NOT USE IN PRODUCTION.
4087
4433
 
4088
- ",
4089
- }
4090
- `);
4434
+ ",
4435
+ }
4436
+ `);
4091
4437
  });
4092
4438
 
4093
4439
  it("should use an environment's current migration tag when publishing migrations", async () => {
@@ -4138,25 +4484,26 @@ addEventListener('fetch', event => {});`
4138
4484
 
4139
4485
  await runWrangler("publish index.js --legacy-env false --env xyz");
4140
4486
  expect(std).toMatchInlineSnapshot(`
4141
- Object {
4142
- "debug": "",
4143
- "err": "",
4144
- "out": "Your worker has access to the following bindings:
4145
- - Durable Objects:
4146
- - SOMENAME: SomeClass
4147
- - SOMEOTHERNAME: SomeOtherClass
4148
- Total Upload: 0xx KiB / gzip: 0xx KiB
4149
- Uploaded test-name (xyz) (TIMINGS)
4150
- Published test-name (xyz) (TIMINGS)
4151
- xyz.test-name.test-sub-domain.workers.dev",
4152
- "warn": "▲ [WARNING] Processing wrangler.toml configuration:
4487
+ Object {
4488
+ "debug": "",
4489
+ "err": "",
4490
+ "out": "Total Upload: xx KiB / gzip: xx KiB
4491
+ Your worker has access to the following bindings:
4492
+ - Durable Objects:
4493
+ - SOMENAME: SomeClass
4494
+ - SOMEOTHERNAME: SomeOtherClass
4495
+ Uploaded test-name (xyz) (TIMINGS)
4496
+ Published test-name (xyz) (TIMINGS)
4497
+ https://xyz.test-name.test-sub-domain.workers.dev
4498
+ Current Deployment ID: undefined",
4499
+ "warn": "▲ [WARNING] Processing wrangler.toml configuration:
4153
4500
 
4154
- - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in
4155
- the future. DO NOT USE IN PRODUCTION.
4501
+ - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in
4502
+ the future. DO NOT USE IN PRODUCTION.
4156
4503
 
4157
- ",
4158
- }
4159
- `);
4504
+ ",
4505
+ }
4506
+ `);
4160
4507
  });
4161
4508
  });
4162
4509
  });
@@ -4193,6 +4540,10 @@ addEventListener('fetch', event => {});`
4193
4540
  { binding: "R2_BUCKET_ONE", bucket_name: "r2-bucket-one-name" },
4194
4541
  { binding: "R2_BUCKET_TWO", bucket_name: "r2-bucket-two-name" },
4195
4542
  ],
4543
+ analytics_engine_datasets: [
4544
+ { binding: "AE_DATASET_ONE", dataset: "ae-dataset-one-name" },
4545
+ { binding: "AE_DATASET_TWO", dataset: "ae-dataset-two-name" },
4546
+ ],
4196
4547
  text_blobs: {
4197
4548
  TEXT_BLOB_ONE: "./my-entire-app-depends-on-this.cfg",
4198
4549
  TEXT_BLOB_TWO: "./the-entirety-of-human-knowledge.txt",
@@ -4223,6 +4574,19 @@ addEventListener('fetch', event => {});`
4223
4574
  DATA_BLOB_ONE: "./some-data-blob.bin",
4224
4575
  DATA_BLOB_TWO: "./more-data-blob.bin",
4225
4576
  },
4577
+ logfwdr: {
4578
+ schema: "./message.capnp.compiled",
4579
+ bindings: [
4580
+ {
4581
+ name: "httplogs",
4582
+ destination: "httplogs",
4583
+ },
4584
+ {
4585
+ name: "trace",
4586
+ destination: "trace",
4587
+ },
4588
+ ],
4589
+ },
4226
4590
  });
4227
4591
 
4228
4592
  writeWorkerSource({ type: "sw" });
@@ -4237,6 +4601,8 @@ addEventListener('fetch', event => {});`
4237
4601
  fs.writeFileSync("./some-data-blob.bin", "some data");
4238
4602
  fs.writeFileSync("./more-data-blob.bin", "more data");
4239
4603
 
4604
+ fs.writeFileSync("./message.capnp.compiled", "compiled capnp messages");
4605
+
4240
4606
  mockUploadWorkerRequest({
4241
4607
  expectedType: "sw",
4242
4608
  expectedBindings: [
@@ -4279,6 +4645,26 @@ addEventListener('fetch', event => {});`
4279
4645
  name: "R2_BUCKET_TWO",
4280
4646
  type: "r2_bucket",
4281
4647
  },
4648
+ {
4649
+ dataset: "ae-dataset-one-name",
4650
+ name: "AE_DATASET_ONE",
4651
+ type: "analytics_engine",
4652
+ },
4653
+ {
4654
+ dataset: "ae-dataset-two-name",
4655
+ name: "AE_DATASET_TWO",
4656
+ type: "analytics_engine",
4657
+ },
4658
+ {
4659
+ name: "httplogs",
4660
+ type: "logfwdr",
4661
+ destination: "httplogs",
4662
+ },
4663
+ {
4664
+ name: "trace",
4665
+ type: "logfwdr",
4666
+ destination: "trace",
4667
+ },
4282
4668
  {
4283
4669
  name: "WASM_MODULE_ONE",
4284
4670
  part: "WASM_MODULE_ONE",
@@ -4310,36 +4696,43 @@ addEventListener('fetch', event => {});`
4310
4696
 
4311
4697
  await expect(runWrangler("publish index.js")).resolves.toBeUndefined();
4312
4698
  expect(std.out).toMatchInlineSnapshot(`
4313
- "Your worker has access to the following bindings:
4314
- - Data Blobs:
4315
- - DATA_BLOB_ONE: some-data-blob.bin
4316
- - DATA_BLOB_TWO: more-data-blob.bin
4317
- - Durable Objects:
4318
- - DURABLE_OBJECT_ONE: SomeDurableObject (defined in some-durable-object-worker)
4319
- - DURABLE_OBJECT_TWO: AnotherDurableObject (defined in another-durable-object-worker) - staging
4320
- - KV Namespaces:
4321
- - KV_NAMESPACE_ONE: kv-ns-one-id
4322
- - KV_NAMESPACE_TWO: kv-ns-two-id
4323
- - R2 Buckets:
4324
- - R2_BUCKET_ONE: r2-bucket-one-name
4325
- - R2_BUCKET_TWO: r2-bucket-two-name
4326
- - Text Blobs:
4327
- - TEXT_BLOB_ONE: my-entire-app-depends-on-this.cfg
4328
- - TEXT_BLOB_TWO: the-entirety-of-human-knowledge.txt
4329
- - Unsafe:
4330
- - some unsafe thing: UNSAFE_BINDING_ONE
4331
- - another unsafe thing: UNSAFE_BINDING_TWO
4332
- - Vars:
4333
- - ENV_VAR_ONE: \\"123\\"
4334
- - ENV_VAR_TWO: \\"Hello, I'm an environment variable\\"
4335
- - Wasm Modules:
4336
- - WASM_MODULE_ONE: some_wasm.wasm
4337
- - WASM_MODULE_TWO: more_wasm.wasm
4338
- Total Upload: 0xx KiB / gzip: 0xx KiB
4339
- Uploaded test-name (TIMINGS)
4340
- Published test-name (TIMINGS)
4341
- test-name.test-sub-domain.workers.dev"
4342
- `);
4699
+ "Total Upload: xx KiB / gzip: xx KiB
4700
+ Your worker has access to the following bindings:
4701
+ - Data Blobs:
4702
+ - DATA_BLOB_ONE: some-data-blob.bin
4703
+ - DATA_BLOB_TWO: more-data-blob.bin
4704
+ - Durable Objects:
4705
+ - DURABLE_OBJECT_ONE: SomeDurableObject (defined in some-durable-object-worker)
4706
+ - DURABLE_OBJECT_TWO: AnotherDurableObject (defined in another-durable-object-worker) - staging
4707
+ - KV Namespaces:
4708
+ - KV_NAMESPACE_ONE: kv-ns-one-id
4709
+ - KV_NAMESPACE_TWO: kv-ns-two-id
4710
+ - R2 Buckets:
4711
+ - R2_BUCKET_ONE: r2-bucket-one-name
4712
+ - R2_BUCKET_TWO: r2-bucket-two-name
4713
+ - logfwdr:
4714
+ - httplogs: httplogs
4715
+ - trace: trace
4716
+ - Analytics Engine Datasets:
4717
+ - AE_DATASET_ONE: ae-dataset-one-name
4718
+ - AE_DATASET_TWO: ae-dataset-two-name
4719
+ - Text Blobs:
4720
+ - TEXT_BLOB_ONE: my-entire-app-depends-on-this.cfg
4721
+ - TEXT_BLOB_TWO: the-entirety-of-human-knowledge.txt
4722
+ - Unsafe:
4723
+ - some unsafe thing: UNSAFE_BINDING_ONE
4724
+ - another unsafe thing: UNSAFE_BINDING_TWO
4725
+ - Vars:
4726
+ - ENV_VAR_ONE: 123
4727
+ - ENV_VAR_TWO: \\"Hello, I'm an environment variable\\"
4728
+ - Wasm Modules:
4729
+ - WASM_MODULE_ONE: some_wasm.wasm
4730
+ - WASM_MODULE_TWO: more_wasm.wasm
4731
+ Uploaded test-name (TIMINGS)
4732
+ Published test-name (TIMINGS)
4733
+ https://test-name.test-sub-domain.workers.dev
4734
+ Current Deployment ID: undefined"
4735
+ `);
4343
4736
  expect(std.err).toMatchInlineSnapshot(`""`);
4344
4737
  expect(std.warn).toMatchInlineSnapshot(`
4345
4738
  "▲ [WARNING] Processing wrangler.toml configuration:
@@ -4380,6 +4773,12 @@ addEventListener('fetch', event => {});`
4380
4773
  bucket_name: "r2-bucket-two-name",
4381
4774
  },
4382
4775
  ],
4776
+ analytics_engine_datasets: [
4777
+ {
4778
+ binding: "CONFLICTING_NAME_FOUR",
4779
+ dataset: "analytics-engine-dataset-name",
4780
+ },
4781
+ ],
4383
4782
  text_blobs: {
4384
4783
  CONFLICTING_NAME_THREE: "./my-entire-app-depends-on-this.cfg",
4385
4784
  CONFLICTING_NAME_FOUR: "./the-entirety-of-human-knowledge.txt",
@@ -4427,7 +4826,7 @@ addEventListener('fetch', event => {});`
4427
4826
  - CONFLICTING_NAME_ONE assigned to Durable Object, KV Namespace, and R2 Bucket bindings.
4428
4827
  - CONFLICTING_NAME_TWO assigned to Durable Object and KV Namespace bindings.
4429
4828
  - CONFLICTING_NAME_THREE assigned to R2 Bucket, Text Blob, Unsafe, Environment Variable, WASM Module, and Data Blob bindings.
4430
- - CONFLICTING_NAME_FOUR assigned to Text Blob and Unsafe bindings.
4829
+ - CONFLICTING_NAME_FOUR assigned to Analytics Engine Dataset, Text Blob, and Unsafe bindings.
4431
4830
  - Bindings must have unique names, so that they can all be referenced in the worker.
4432
4831
  Please change your bindings to have unique names.]
4433
4832
  `);
@@ -4442,7 +4841,7 @@ addEventListener('fetch', event => {});`
4442
4841
  - CONFLICTING_NAME_TWO assigned to Durable Object and KV Namespace bindings.
4443
4842
  - CONFLICTING_NAME_THREE assigned to R2 Bucket, Text Blob, Unsafe, Environment Variable, WASM
4444
4843
  Module, and Data Blob bindings.
4445
- - CONFLICTING_NAME_FOUR assigned to Text Blob and Unsafe bindings.
4844
+ - CONFLICTING_NAME_FOUR assigned to Analytics Engine Dataset, Text Blob, and Unsafe bindings.
4446
4845
  - Bindings must have unique names, so that they can all be referenced in the worker.
4447
4846
  Please change your bindings to have unique names.
4448
4847
 
@@ -4487,6 +4886,16 @@ addEventListener('fetch', event => {});`
4487
4886
  bucket_name: "r2-bucket-two-name",
4488
4887
  },
4489
4888
  ],
4889
+ analytics_engine_datasets: [
4890
+ {
4891
+ binding: "CONFLICTING_AE_DATASET_NAME",
4892
+ dataset: "ae-dataset-one-name",
4893
+ },
4894
+ {
4895
+ binding: "CONFLICTING_AE_DATASET_NAME",
4896
+ dataset: "ae-dataset-two-name",
4897
+ },
4898
+ ],
4490
4899
  unsafe: {
4491
4900
  bindings: [
4492
4901
  {
@@ -4526,6 +4935,7 @@ addEventListener('fetch', event => {});`
4526
4935
  - CONFLICTING_DURABLE_OBJECT_NAME assigned to multiple Durable Object bindings.
4527
4936
  - CONFLICTING_KV_NAMESPACE_NAME assigned to multiple KV Namespace bindings.
4528
4937
  - CONFLICTING_R2_BUCKET_NAME assigned to multiple R2 Bucket bindings.
4938
+ - CONFLICTING_AE_DATASET_NAME assigned to multiple Analytics Engine Dataset bindings.
4529
4939
  - CONFLICTING_UNSAFE_NAME assigned to multiple Unsafe bindings.
4530
4940
  - Bindings must have unique names, so that they can all be referenced in the worker.
4531
4941
  Please change your bindings to have unique names.]
@@ -4540,6 +4950,7 @@ addEventListener('fetch', event => {});`
4540
4950
  - CONFLICTING_DURABLE_OBJECT_NAME assigned to multiple Durable Object bindings.
4541
4951
  - CONFLICTING_KV_NAMESPACE_NAME assigned to multiple KV Namespace bindings.
4542
4952
  - CONFLICTING_R2_BUCKET_NAME assigned to multiple R2 Bucket bindings.
4953
+ - CONFLICTING_AE_DATASET_NAME assigned to multiple Analytics Engine Dataset bindings.
4543
4954
  - CONFLICTING_UNSAFE_NAME assigned to multiple Unsafe bindings.
4544
4955
  - Bindings must have unique names, so that they can all be referenced in the worker.
4545
4956
  Please change your bindings to have unique names.
@@ -4601,6 +5012,24 @@ addEventListener('fetch', event => {});`
4601
5012
  bucket_name: "r2-bucket-four-name",
4602
5013
  },
4603
5014
  ],
5015
+ analytics_engine_datasets: [
5016
+ {
5017
+ binding: "CONFLICTING_AE_DATASET_NAME",
5018
+ dataset: "ae-dataset-one-name",
5019
+ },
5020
+ {
5021
+ binding: "CONFLICTING_AE_DATASET_NAME",
5022
+ dataset: "ae-dataset-two-name",
5023
+ },
5024
+ {
5025
+ binding: "CONFLICTING_NAME_THREE",
5026
+ dataset: "ae-dataset-three-name",
5027
+ },
5028
+ {
5029
+ binding: "CONFLICTING_NAME_FOUR",
5030
+ dataset: "ae-dataset-four-name",
5031
+ },
5032
+ ],
4604
5033
  text_blobs: {
4605
5034
  CONFLICTING_NAME_THREE: "./my-entire-app-depends-on-this.cfg",
4606
5035
  CONFLICTING_NAME_FOUR: "./the-entirety-of-human-knowledge.txt",
@@ -4658,8 +5087,9 @@ addEventListener('fetch', event => {});`
4658
5087
  - CONFLICTING_DURABLE_OBJECT_NAME assigned to multiple Durable Object bindings.
4659
5088
  - CONFLICTING_KV_NAMESPACE_NAME assigned to multiple KV Namespace bindings.
4660
5089
  - CONFLICTING_R2_BUCKET_NAME assigned to multiple R2 Bucket bindings.
4661
- - CONFLICTING_NAME_THREE assigned to R2 Bucket, Text Blob, Unsafe, Environment Variable, WASM Module, and Data Blob bindings.
4662
- - CONFLICTING_NAME_FOUR assigned to R2 Bucket, Text Blob, and Unsafe bindings.
5090
+ - CONFLICTING_NAME_THREE assigned to R2 Bucket, Analytics Engine Dataset, Text Blob, Unsafe, Environment Variable, WASM Module, and Data Blob bindings.
5091
+ - CONFLICTING_NAME_FOUR assigned to R2 Bucket, Analytics Engine Dataset, Text Blob, and Unsafe bindings.
5092
+ - CONFLICTING_AE_DATASET_NAME assigned to multiple Analytics Engine Dataset bindings.
4663
5093
  - CONFLICTING_UNSAFE_NAME assigned to multiple Unsafe bindings.
4664
5094
  - Bindings must have unique names, so that they can all be referenced in the worker.
4665
5095
  Please change your bindings to have unique names.]
@@ -4674,9 +5104,11 @@ addEventListener('fetch', event => {});`
4674
5104
  - CONFLICTING_DURABLE_OBJECT_NAME assigned to multiple Durable Object bindings.
4675
5105
  - CONFLICTING_KV_NAMESPACE_NAME assigned to multiple KV Namespace bindings.
4676
5106
  - CONFLICTING_R2_BUCKET_NAME assigned to multiple R2 Bucket bindings.
4677
- - CONFLICTING_NAME_THREE assigned to R2 Bucket, Text Blob, Unsafe, Environment Variable, WASM
4678
- Module, and Data Blob bindings.
4679
- - CONFLICTING_NAME_FOUR assigned to R2 Bucket, Text Blob, and Unsafe bindings.
5107
+ - CONFLICTING_NAME_THREE assigned to R2 Bucket, Analytics Engine Dataset, Text Blob, Unsafe,
5108
+ Environment Variable, WASM Module, and Data Blob bindings.
5109
+ - CONFLICTING_NAME_FOUR assigned to R2 Bucket, Analytics Engine Dataset, Text Blob, and Unsafe
5110
+ bindings.
5111
+ - CONFLICTING_AE_DATASET_NAME assigned to multiple Analytics Engine Dataset bindings.
4680
5112
  - CONFLICTING_UNSAFE_NAME assigned to multiple Unsafe bindings.
4681
5113
  - Bindings must have unique names, so that they can all be referenced in the worker.
4682
5114
  Please change your bindings to have unique names.
@@ -4712,14 +5144,15 @@ addEventListener('fetch', event => {});`
4712
5144
  mockSubDomainRequest();
4713
5145
  await runWrangler("publish index.js");
4714
5146
  expect(std.out).toMatchInlineSnapshot(`
4715
- "Your worker has access to the following bindings:
4716
- - Wasm Modules:
4717
- - TESTWASMNAME: path/to/test.wasm
4718
- Total Upload: 0xx KiB / gzip: 0xx KiB
4719
- Uploaded test-name (TIMINGS)
4720
- Published test-name (TIMINGS)
4721
- test-name.test-sub-domain.workers.dev"
4722
- `);
5147
+ "Total Upload: xx KiB / gzip: xx KiB
5148
+ Your worker has access to the following bindings:
5149
+ - Wasm Modules:
5150
+ - TESTWASMNAME: path/to/test.wasm
5151
+ Uploaded test-name (TIMINGS)
5152
+ Published test-name (TIMINGS)
5153
+ https://test-name.test-sub-domain.workers.dev
5154
+ Current Deployment ID: undefined"
5155
+ `);
4723
5156
  expect(std.err).toMatchInlineSnapshot(`""`);
4724
5157
  expect(std.warn).toMatchInlineSnapshot(`""`);
4725
5158
  });
@@ -4782,14 +5215,15 @@ addEventListener('fetch', event => {});`
4782
5215
  mockSubDomainRequest();
4783
5216
  await runWrangler("publish index.js --config ./path/to/wrangler.toml");
4784
5217
  expect(std.out).toMatchInlineSnapshot(`
4785
- "Your worker has access to the following bindings:
4786
- - Wasm Modules:
4787
- - TESTWASMNAME: path/to/and/the/path/to/test.wasm
4788
- Total Upload: 0xx KiB / gzip: 0xx KiB
4789
- Uploaded test-name (TIMINGS)
4790
- Published test-name (TIMINGS)
4791
- test-name.test-sub-domain.workers.dev"
4792
- `);
5218
+ "Total Upload: xx KiB / gzip: xx KiB
5219
+ Your worker has access to the following bindings:
5220
+ - Wasm Modules:
5221
+ - TESTWASMNAME: path/to/and/the/path/to/test.wasm
5222
+ Uploaded test-name (TIMINGS)
5223
+ Published test-name (TIMINGS)
5224
+ https://test-name.test-sub-domain.workers.dev
5225
+ Current Deployment ID: undefined"
5226
+ `);
4793
5227
  expect(std.err).toMatchInlineSnapshot(`""`);
4794
5228
  expect(std.warn).toMatchInlineSnapshot(`""`);
4795
5229
  });
@@ -4818,11 +5252,12 @@ addEventListener('fetch', event => {});`
4818
5252
  mockSubDomainRequest();
4819
5253
  await runWrangler("publish index.js");
4820
5254
  expect(std.out).toMatchInlineSnapshot(`
4821
- "Total Upload: 0xx KiB / gzip: 0xx KiB
4822
- Uploaded test-name (TIMINGS)
4823
- Published test-name (TIMINGS)
4824
- test-name.test-sub-domain.workers.dev"
4825
- `);
5255
+ "Total Upload: xx KiB / gzip: xx KiB
5256
+ Uploaded test-name (TIMINGS)
5257
+ Published test-name (TIMINGS)
5258
+ https://test-name.test-sub-domain.workers.dev
5259
+ Current Deployment ID: undefined"
5260
+ `);
4826
5261
  expect(std.err).toMatchInlineSnapshot(`""`);
4827
5262
  expect(std.warn).toMatchInlineSnapshot(`""`);
4828
5263
  });
@@ -4852,14 +5287,15 @@ addEventListener('fetch', event => {});`
4852
5287
  mockSubDomainRequest();
4853
5288
  await runWrangler("publish index.js");
4854
5289
  expect(std.out).toMatchInlineSnapshot(`
4855
- "Your worker has access to the following bindings:
4856
- - Text Blobs:
4857
- - TESTTEXTBLOBNAME: path/to/text.file
4858
- Total Upload: 0xx KiB / gzip: 0xx KiB
4859
- Uploaded test-name (TIMINGS)
4860
- Published test-name (TIMINGS)
4861
- test-name.test-sub-domain.workers.dev"
4862
- `);
5290
+ "Total Upload: xx KiB / gzip: xx KiB
5291
+ Your worker has access to the following bindings:
5292
+ - Text Blobs:
5293
+ - TESTTEXTBLOBNAME: path/to/text.file
5294
+ Uploaded test-name (TIMINGS)
5295
+ Published test-name (TIMINGS)
5296
+ https://test-name.test-sub-domain.workers.dev
5297
+ Current Deployment ID: undefined"
5298
+ `);
4863
5299
  expect(std.err).toMatchInlineSnapshot(`""`);
4864
5300
  expect(std.warn).toMatchInlineSnapshot(`""`);
4865
5301
  });
@@ -4926,14 +5362,15 @@ addEventListener('fetch', event => {});`
4926
5362
  mockSubDomainRequest();
4927
5363
  await runWrangler("publish index.js --config ./path/to/wrangler.toml");
4928
5364
  expect(std.out).toMatchInlineSnapshot(`
4929
- "Your worker has access to the following bindings:
4930
- - Text Blobs:
4931
- - TESTTEXTBLOBNAME: path/to/and/the/path/to/text.file
4932
- Total Upload: 0xx KiB / gzip: 0xx KiB
4933
- Uploaded test-name (TIMINGS)
4934
- Published test-name (TIMINGS)
4935
- test-name.test-sub-domain.workers.dev"
4936
- `);
5365
+ "Total Upload: xx KiB / gzip: xx KiB
5366
+ Your worker has access to the following bindings:
5367
+ - Text Blobs:
5368
+ - TESTTEXTBLOBNAME: path/to/and/the/path/to/text.file
5369
+ Uploaded test-name (TIMINGS)
5370
+ Published test-name (TIMINGS)
5371
+ https://test-name.test-sub-domain.workers.dev
5372
+ Current Deployment ID: undefined"
5373
+ `);
4937
5374
  expect(std.err).toMatchInlineSnapshot(`""`);
4938
5375
  expect(std.warn).toMatchInlineSnapshot(`""`);
4939
5376
  });
@@ -4963,14 +5400,15 @@ addEventListener('fetch', event => {});`
4963
5400
  mockSubDomainRequest();
4964
5401
  await runWrangler("publish index.js");
4965
5402
  expect(std.out).toMatchInlineSnapshot(`
4966
- "Your worker has access to the following bindings:
4967
- - Data Blobs:
4968
- - TESTDATABLOBNAME: path/to/data.bin
4969
- Total Upload: 0xx KiB / gzip: 0xx KiB
4970
- Uploaded test-name (TIMINGS)
4971
- Published test-name (TIMINGS)
4972
- test-name.test-sub-domain.workers.dev"
4973
- `);
5403
+ "Total Upload: xx KiB / gzip: xx KiB
5404
+ Your worker has access to the following bindings:
5405
+ - Data Blobs:
5406
+ - TESTDATABLOBNAME: path/to/data.bin
5407
+ Uploaded test-name (TIMINGS)
5408
+ Published test-name (TIMINGS)
5409
+ https://test-name.test-sub-domain.workers.dev
5410
+ Current Deployment ID: undefined"
5411
+ `);
4974
5412
  expect(std.err).toMatchInlineSnapshot(`""`);
4975
5413
  expect(std.warn).toMatchInlineSnapshot(`""`);
4976
5414
  });
@@ -5037,14 +5475,15 @@ addEventListener('fetch', event => {});`
5037
5475
  mockSubDomainRequest();
5038
5476
  await runWrangler("publish index.js --config ./path/to/wrangler.toml");
5039
5477
  expect(std.out).toMatchInlineSnapshot(`
5040
- "Your worker has access to the following bindings:
5041
- - Data Blobs:
5042
- - TESTDATABLOBNAME: path/to/and/the/path/to/data.bin
5043
- Total Upload: 0xx KiB / gzip: 0xx KiB
5044
- Uploaded test-name (TIMINGS)
5045
- Published test-name (TIMINGS)
5046
- test-name.test-sub-domain.workers.dev"
5047
- `);
5478
+ "Total Upload: xx KiB / gzip: xx KiB
5479
+ Your worker has access to the following bindings:
5480
+ - Data Blobs:
5481
+ - TESTDATABLOBNAME: path/to/and/the/path/to/data.bin
5482
+ Uploaded test-name (TIMINGS)
5483
+ Published test-name (TIMINGS)
5484
+ https://test-name.test-sub-domain.workers.dev
5485
+ Current Deployment ID: undefined"
5486
+ `);
5048
5487
  expect(std.err).toMatchInlineSnapshot(`""`);
5049
5488
  expect(std.warn).toMatchInlineSnapshot(`""`);
5050
5489
  });
@@ -5075,19 +5514,47 @@ addEventListener('fetch', event => {});`
5075
5514
 
5076
5515
  await runWrangler("publish index.js");
5077
5516
  expect(std.out).toMatchInlineSnapshot(`
5078
- "Your worker has access to the following bindings:
5079
- - Vars:
5080
- - text: \\"plain ol' string\\"
5081
- - count: \\"1\\"
5082
- - complex: \\"[object Object]\\"
5083
- Total Upload: 0xx KiB / gzip: 0xx KiB
5084
- Uploaded test-name (TIMINGS)
5085
- Published test-name (TIMINGS)
5086
- test-name.test-sub-domain.workers.dev"
5087
- `);
5517
+ "Total Upload: xx KiB / gzip: xx KiB
5518
+ Your worker has access to the following bindings:
5519
+ - Vars:
5520
+ - text: \\"plain ol' string\\"
5521
+ - count: 1
5522
+ - complex: {
5523
+ \\"enabled\\": true,
5524
+ \\"id\\": 123
5525
+ }
5526
+ Uploaded test-name (TIMINGS)
5527
+ Published test-name (TIMINGS)
5528
+ https://test-name.test-sub-domain.workers.dev
5529
+ Current Deployment ID: undefined"
5530
+ `);
5088
5531
  expect(std.err).toMatchInlineSnapshot(`""`);
5089
5532
  expect(std.warn).toMatchInlineSnapshot(`""`);
5090
5533
  });
5534
+
5535
+ it("should read vars passed as cli arguments", async () => {
5536
+ writeWranglerToml();
5537
+ writeWorkerSource();
5538
+ mockSubDomainRequest();
5539
+ mockUploadWorkerRequest();
5540
+ await runWrangler("publish index.js --var TEXT:sometext --var COUNT:1");
5541
+ expect(std).toMatchInlineSnapshot(`
5542
+ Object {
5543
+ "debug": "",
5544
+ "err": "",
5545
+ "out": "Total Upload: xx KiB / gzip: xx KiB
5546
+ Your worker has access to the following bindings:
5547
+ - Vars:
5548
+ - TEXT: \\"(hidden)\\"
5549
+ - COUNT: \\"(hidden)\\"
5550
+ Uploaded test-name (TIMINGS)
5551
+ Published test-name (TIMINGS)
5552
+ https://test-name.test-sub-domain.workers.dev
5553
+ Current Deployment ID: undefined",
5554
+ "warn": "",
5555
+ }
5556
+ `);
5557
+ });
5091
5558
  });
5092
5559
 
5093
5560
  describe("[r2_buckets]", () => {
@@ -5105,14 +5572,68 @@ addEventListener('fetch', event => {});`
5105
5572
 
5106
5573
  await runWrangler("publish index.js");
5107
5574
  expect(std.out).toMatchInlineSnapshot(`
5108
- "Your worker has access to the following bindings:
5109
- - R2 Buckets:
5110
- - FOO: foo-bucket
5111
- Total Upload: 0xx KiB / gzip: 0xx KiB
5112
- Uploaded test-name (TIMINGS)
5113
- Published test-name (TIMINGS)
5114
- test-name.test-sub-domain.workers.dev"
5115
- `);
5575
+ "Total Upload: xx KiB / gzip: xx KiB
5576
+ Your worker has access to the following bindings:
5577
+ - R2 Buckets:
5578
+ - FOO: foo-bucket
5579
+ Uploaded test-name (TIMINGS)
5580
+ Published test-name (TIMINGS)
5581
+ https://test-name.test-sub-domain.workers.dev
5582
+ Current Deployment ID: undefined"
5583
+ `);
5584
+ expect(std.err).toMatchInlineSnapshot(`""`);
5585
+ expect(std.warn).toMatchInlineSnapshot(`""`);
5586
+ });
5587
+ });
5588
+
5589
+ describe("[logfwdr]", () => {
5590
+ it("should support logfwdr bindings", async () => {
5591
+ fs.writeFileSync("./message.capnp.compiled", "compiled capnp messages");
5592
+
5593
+ writeWranglerToml({
5594
+ logfwdr: {
5595
+ schema: "./message.capnp.compiled",
5596
+ bindings: [
5597
+ {
5598
+ name: "httplogs",
5599
+ destination: "httplogs",
5600
+ },
5601
+ {
5602
+ name: "trace",
5603
+ destination: "trace",
5604
+ },
5605
+ ],
5606
+ },
5607
+ });
5608
+ writeWorkerSource();
5609
+ mockSubDomainRequest();
5610
+ mockUploadWorkerRequest({
5611
+ expectedBindings: [
5612
+ {
5613
+ name: "httplogs",
5614
+ type: "logfwdr",
5615
+ destination: "httplogs",
5616
+ },
5617
+ {
5618
+ name: "trace",
5619
+ type: "logfwdr",
5620
+ destination: "trace",
5621
+ },
5622
+ ],
5623
+ });
5624
+
5625
+ await runWrangler("publish index.js");
5626
+ expect(std.out).toMatchInlineSnapshot(`
5627
+ "Total Upload: xx KiB / gzip: xx KiB
5628
+ Your worker has access to the following bindings:
5629
+ - logfwdr:
5630
+ - httplogs: httplogs
5631
+ - trace: trace
5632
+ Uploaded test-name (TIMINGS)
5633
+ Published test-name (TIMINGS)
5634
+ https://test-name.test-sub-domain.workers.dev
5635
+ Current Deployment ID: undefined"
5636
+ `);
5116
5637
  expect(std.err).toMatchInlineSnapshot(`""`);
5117
5638
  expect(std.warn).toMatchInlineSnapshot(`""`);
5118
5639
  });
@@ -5151,14 +5672,15 @@ addEventListener('fetch', event => {});`
5151
5672
 
5152
5673
  await runWrangler("publish index.js");
5153
5674
  expect(std.out).toMatchInlineSnapshot(`
5154
- "Your worker has access to the following bindings:
5155
- - Durable Objects:
5156
- - EXAMPLE_DO_BINDING: ExampleDurableObject
5157
- Total Upload: 0xx KiB / gzip: 0xx KiB
5158
- Uploaded test-name (TIMINGS)
5159
- Published test-name (TIMINGS)
5160
- test-name.test-sub-domain.workers.dev"
5161
- `);
5675
+ "Total Upload: xx KiB / gzip: xx KiB
5676
+ Your worker has access to the following bindings:
5677
+ - Durable Objects:
5678
+ - EXAMPLE_DO_BINDING: ExampleDurableObject
5679
+ Uploaded test-name (TIMINGS)
5680
+ Published test-name (TIMINGS)
5681
+ https://test-name.test-sub-domain.workers.dev
5682
+ Current Deployment ID: undefined"
5683
+ `);
5162
5684
  expect(std.err).toMatchInlineSnapshot(`""`);
5163
5685
  expect(std.warn).toMatchInlineSnapshot(`""`);
5164
5686
  });
@@ -5191,14 +5713,15 @@ addEventListener('fetch', event => {});`
5191
5713
 
5192
5714
  await runWrangler("publish index.js");
5193
5715
  expect(std.out).toMatchInlineSnapshot(`
5194
- "Your worker has access to the following bindings:
5195
- - Durable Objects:
5196
- - EXAMPLE_DO_BINDING: ExampleDurableObject (defined in example-do-binding-worker)
5197
- Total Upload: 0xx KiB / gzip: 0xx KiB
5198
- Uploaded test-name (TIMINGS)
5199
- Published test-name (TIMINGS)
5200
- test-name.test-sub-domain.workers.dev"
5201
- `);
5716
+ "Total Upload: xx KiB / gzip: xx KiB
5717
+ Your worker has access to the following bindings:
5718
+ - Durable Objects:
5719
+ - EXAMPLE_DO_BINDING: ExampleDurableObject (defined in example-do-binding-worker)
5720
+ Uploaded test-name (TIMINGS)
5721
+ Published test-name (TIMINGS)
5722
+ https://test-name.test-sub-domain.workers.dev
5723
+ Current Deployment ID: undefined"
5724
+ `);
5202
5725
  expect(std.err).toMatchInlineSnapshot(`""`);
5203
5726
  expect(std.warn).toMatchInlineSnapshot(`""`);
5204
5727
  });
@@ -5236,14 +5759,15 @@ addEventListener('fetch', event => {});`
5236
5759
 
5237
5760
  await runWrangler("publish index.js");
5238
5761
  expect(std.out).toMatchInlineSnapshot(`
5239
- "Your worker has access to the following bindings:
5240
- - Durable Objects:
5241
- - EXAMPLE_DO_BINDING: ExampleDurableObject
5242
- Total Upload: 0xx KiB / gzip: 0xx KiB
5243
- Uploaded test-name (TIMINGS)
5244
- Published test-name (TIMINGS)
5245
- test-name.test-sub-domain.workers.dev"
5246
- `);
5762
+ "Total Upload: xx KiB / gzip: xx KiB
5763
+ Your worker has access to the following bindings:
5764
+ - Durable Objects:
5765
+ - EXAMPLE_DO_BINDING: ExampleDurableObject
5766
+ Uploaded test-name (TIMINGS)
5767
+ Published test-name (TIMINGS)
5768
+ https://test-name.test-sub-domain.workers.dev
5769
+ Current Deployment ID: undefined"
5770
+ `);
5247
5771
  expect(std.err).toMatchInlineSnapshot(`""`);
5248
5772
  expect(std.warn).toMatchInlineSnapshot(`""`);
5249
5773
  });
@@ -5264,12 +5788,12 @@ addEventListener('fetch', event => {});`
5264
5788
 
5265
5789
  await expect(runWrangler("publish index.js")).rejects
5266
5790
  .toThrowErrorMatchingInlineSnapshot(`
5267
- "You seem to be trying to use Durable Objects in a Worker written as a service-worker.
5268
- You can use Durable Objects defined in other Workers by specifying a \`script_name\` in your wrangler.toml, where \`script_name\` is the name of the Worker that implements that Durable Object. For example:
5269
- { name = EXAMPLE_DO_BINDING, class_name = ExampleDurableObject } ==> { name = EXAMPLE_DO_BINDING, class_name = ExampleDurableObject, script_name = example-do-binding-worker }
5270
- Alternatively, migrate your worker to ES Module syntax to implement a Durable Object in this Worker:
5271
- https://developers.cloudflare.com/workers/learning/migrating-to-module-workers/"
5272
- `);
5791
+ "You seem to be trying to use Durable Objects in a Worker written as a service-worker.
5792
+ You can use Durable Objects defined in other Workers by specifying a \`script_name\` in your wrangler.toml, where \`script_name\` is the name of the Worker that implements that Durable Object. For example:
5793
+ { name = EXAMPLE_DO_BINDING, class_name = ExampleDurableObject } ==> { name = EXAMPLE_DO_BINDING, class_name = ExampleDurableObject, script_name = example-do-binding-worker }
5794
+ Alternatively, migrate your worker to ES Module syntax to implement a Durable Object in this Worker:
5795
+ https://developers.cloudflare.com/workers/learning/migrating-to-module-workers/"
5796
+ `);
5273
5797
  });
5274
5798
  });
5275
5799
 
@@ -5299,14 +5823,15 @@ addEventListener('fetch', event => {});`
5299
5823
 
5300
5824
  await runWrangler("publish index.js");
5301
5825
  expect(std.out).toMatchInlineSnapshot(`
5302
- "Your worker has access to the following bindings:
5303
- - Services:
5304
- - FOO: foo-service - production
5305
- Total Upload: 0xx KiB / gzip: 0xx KiB
5306
- Uploaded test-name (TIMINGS)
5307
- Published test-name (TIMINGS)
5308
- test-name.test-sub-domain.workers.dev"
5309
- `);
5826
+ "Total Upload: xx KiB / gzip: xx KiB
5827
+ Your worker has access to the following bindings:
5828
+ - Services:
5829
+ - FOO: foo-service - production
5830
+ Uploaded test-name (TIMINGS)
5831
+ Published test-name (TIMINGS)
5832
+ https://test-name.test-sub-domain.workers.dev
5833
+ Current Deployment ID: undefined"
5834
+ `);
5310
5835
  expect(std.err).toMatchInlineSnapshot(`""`);
5311
5836
  expect(std.warn).toMatchInlineSnapshot(`
5312
5837
  "▲ [WARNING] Processing wrangler.toml configuration:
@@ -5318,10 +5843,41 @@ addEventListener('fetch', event => {});`
5318
5843
  });
5319
5844
  });
5320
5845
 
5321
- describe("[worker_namespaces]", () => {
5322
- it("should support bindings to a worker namespace", async () => {
5846
+ describe("[analytics_engine_datasets]", () => {
5847
+ it("should support analytics engine bindings", async () => {
5848
+ writeWranglerToml({
5849
+ analytics_engine_datasets: [
5850
+ { binding: "FOO", dataset: "foo-dataset" },
5851
+ ],
5852
+ });
5853
+ writeWorkerSource();
5854
+ mockSubDomainRequest();
5855
+ mockUploadWorkerRequest({
5856
+ expectedBindings: [
5857
+ { dataset: "foo-dataset", name: "FOO", type: "analytics_engine" },
5858
+ ],
5859
+ });
5860
+
5861
+ await runWrangler("publish index.js");
5862
+ expect(std.out).toMatchInlineSnapshot(`
5863
+ "Total Upload: xx KiB / gzip: xx KiB
5864
+ Your worker has access to the following bindings:
5865
+ - Analytics Engine Datasets:
5866
+ - FOO: foo-dataset
5867
+ Uploaded test-name (TIMINGS)
5868
+ Published test-name (TIMINGS)
5869
+ https://test-name.test-sub-domain.workers.dev
5870
+ Current Deployment ID: undefined"
5871
+ `);
5872
+ expect(std.err).toMatchInlineSnapshot(`""`);
5873
+ expect(std.warn).toMatchInlineSnapshot(`""`);
5874
+ });
5875
+ });
5876
+
5877
+ describe("[dispatch_namespaces]", () => {
5878
+ it("should support bindings to a dispatch namespace", async () => {
5323
5879
  writeWranglerToml({
5324
- worker_namespaces: [
5880
+ dispatch_namespaces: [
5325
5881
  {
5326
5882
  binding: "foo",
5327
5883
  namespace: "Foo",
@@ -5333,7 +5889,7 @@ addEventListener('fetch', event => {});`
5333
5889
  mockUploadWorkerRequest({
5334
5890
  expectedBindings: [
5335
5891
  {
5336
- type: "namespace",
5892
+ type: "dispatch_namespace",
5337
5893
  name: "foo",
5338
5894
  namespace: "Foo",
5339
5895
  },
@@ -5341,24 +5897,19 @@ addEventListener('fetch', event => {});`
5341
5897
  });
5342
5898
  await runWrangler("publish index.js");
5343
5899
  expect(std.out).toMatchInlineSnapshot(`
5344
- "Your worker has access to the following bindings:
5345
- - Worker Namespaces:
5346
- - foo: Foo
5347
- Total Upload: 0xx KiB / gzip: 0xx KiB
5348
- Uploaded test-name (TIMINGS)
5349
- Published test-name (TIMINGS)
5350
- test-name.test-sub-domain.workers.dev"
5351
- `);
5900
+ "Total Upload: xx KiB / gzip: xx KiB
5901
+ Your worker has access to the following bindings:
5902
+ - dispatch namespaces:
5903
+ - foo: Foo
5904
+ Uploaded test-name (TIMINGS)
5905
+ Published test-name (TIMINGS)
5906
+ https://test-name.test-sub-domain.workers.dev
5907
+ Current Deployment ID: undefined"
5908
+ `);
5352
5909
  expect(std.err).toMatchInlineSnapshot(`""`);
5353
- expect(std.warn).toMatchInlineSnapshot(`
5354
- "▲ [WARNING] Processing wrangler.toml configuration:
5355
-
5356
- - \\"worker_namespaces\\" fields are experimental and may change or break at any time.
5357
-
5358
- "
5359
- `);
5360
- });
5361
- });
5910
+ expect(std.warn).toMatchInlineSnapshot(`""`);
5911
+ });
5912
+ });
5362
5913
 
5363
5914
  describe("[unsafe]", () => {
5364
5915
  it("should warn if using unsafe bindings", async () => {
@@ -5387,14 +5938,15 @@ addEventListener('fetch', event => {});`
5387
5938
 
5388
5939
  await runWrangler("publish index.js");
5389
5940
  expect(std.out).toMatchInlineSnapshot(`
5390
- "Your worker has access to the following bindings:
5391
- - Unsafe:
5392
- - binding-type: my-binding
5393
- Total Upload: 0xx KiB / gzip: 0xx KiB
5394
- Uploaded test-name (TIMINGS)
5395
- Published test-name (TIMINGS)
5396
- test-name.test-sub-domain.workers.dev"
5397
- `);
5941
+ "Total Upload: xx KiB / gzip: xx KiB
5942
+ Your worker has access to the following bindings:
5943
+ - Unsafe:
5944
+ - binding-type: my-binding
5945
+ Uploaded test-name (TIMINGS)
5946
+ Published test-name (TIMINGS)
5947
+ https://test-name.test-sub-domain.workers.dev
5948
+ Current Deployment ID: undefined"
5949
+ `);
5398
5950
  expect(std.err).toMatchInlineSnapshot(`""`);
5399
5951
  expect(std.warn).toMatchInlineSnapshot(`
5400
5952
  "▲ [WARNING] Processing wrangler.toml configuration:
@@ -5430,14 +5982,15 @@ addEventListener('fetch', event => {});`
5430
5982
 
5431
5983
  await runWrangler("publish index.js");
5432
5984
  expect(std.out).toMatchInlineSnapshot(`
5433
- "Your worker has access to the following bindings:
5434
- - Unsafe:
5435
- - plain_text: my-binding
5436
- Total Upload: 0xx KiB / gzip: 0xx KiB
5437
- Uploaded test-name (TIMINGS)
5438
- Published test-name (TIMINGS)
5439
- test-name.test-sub-domain.workers.dev"
5440
- `);
5985
+ "Total Upload: xx KiB / gzip: xx KiB
5986
+ Your worker has access to the following bindings:
5987
+ - Unsafe:
5988
+ - plain_text: my-binding
5989
+ Uploaded test-name (TIMINGS)
5990
+ Published test-name (TIMINGS)
5991
+ https://test-name.test-sub-domain.workers.dev
5992
+ Current Deployment ID: undefined"
5993
+ `);
5441
5994
  expect(std.err).toMatchInlineSnapshot(`""`);
5442
5995
  expect(std.warn).toMatchInlineSnapshot(`
5443
5996
  "▲ [WARNING] Processing wrangler.toml configuration:
@@ -5479,11 +6032,12 @@ addEventListener('fetch', event => {});`
5479
6032
  });
5480
6033
  await runWrangler("publish index.js");
5481
6034
  expect(std.out).toMatchInlineSnapshot(`
5482
- "Total Upload: 0xx KiB / gzip: 0xx KiB
5483
- Uploaded test-name (TIMINGS)
5484
- Published test-name (TIMINGS)
5485
- test-name.test-sub-domain.workers.dev"
5486
- `);
6035
+ "Total Upload: xx KiB / gzip: xx KiB
6036
+ Uploaded test-name (TIMINGS)
6037
+ Published test-name (TIMINGS)
6038
+ https://test-name.test-sub-domain.workers.dev
6039
+ Current Deployment ID: undefined"
6040
+ `);
5487
6041
  expect(std.err).toMatchInlineSnapshot(`""`);
5488
6042
  expect(std.warn).toMatchInlineSnapshot(`""`);
5489
6043
  });
@@ -5508,11 +6062,12 @@ addEventListener('fetch', event => {});`
5508
6062
  });
5509
6063
  await runWrangler("publish index.js");
5510
6064
  expect(std.out).toMatchInlineSnapshot(`
5511
- "Total Upload: 0xx KiB / gzip: 0xx KiB
5512
- Uploaded test-name (TIMINGS)
5513
- Published test-name (TIMINGS)
5514
- test-name.test-sub-domain.workers.dev"
5515
- `);
6065
+ "Total Upload: xx KiB / gzip: xx KiB
6066
+ Uploaded test-name (TIMINGS)
6067
+ Published test-name (TIMINGS)
6068
+ https://test-name.test-sub-domain.workers.dev
6069
+ Current Deployment ID: undefined"
6070
+ `);
5516
6071
  expect(std.err).toMatchInlineSnapshot(`""`);
5517
6072
  expect(std.warn).toMatchInlineSnapshot(`""`);
5518
6073
  });
@@ -5541,11 +6096,12 @@ addEventListener('fetch', event => {});`
5541
6096
  });
5542
6097
  await runWrangler("publish index.js");
5543
6098
  expect(std.out).toMatchInlineSnapshot(`
5544
- "Total Upload: 0xx KiB / gzip: 0xx KiB
5545
- Uploaded test-name (TIMINGS)
5546
- Published test-name (TIMINGS)
5547
- test-name.test-sub-domain.workers.dev"
5548
- `);
6099
+ "Total Upload: xx KiB / gzip: xx KiB
6100
+ Uploaded test-name (TIMINGS)
6101
+ Published test-name (TIMINGS)
6102
+ https://test-name.test-sub-domain.workers.dev
6103
+ Current Deployment ID: undefined"
6104
+ `);
5549
6105
  expect(std.err).toMatchInlineSnapshot(`""`);
5550
6106
  expect(std.warn).toMatchInlineSnapshot(`
5551
6107
  "▲ [WARNING] Processing wrangler.toml configuration:
@@ -5590,11 +6146,12 @@ addEventListener('fetch', event => {});`
5590
6146
  });
5591
6147
  await runWrangler("publish index.js");
5592
6148
  expect(std.out).toMatchInlineSnapshot(`
5593
- "Total Upload: 0xx KiB / gzip: 0xx KiB
5594
- Uploaded test-name (TIMINGS)
5595
- Published test-name (TIMINGS)
5596
- test-name.test-sub-domain.workers.dev"
5597
- `);
6149
+ "Total Upload: xx KiB / gzip: xx KiB
6150
+ Uploaded test-name (TIMINGS)
6151
+ Published test-name (TIMINGS)
6152
+ https://test-name.test-sub-domain.workers.dev
6153
+ Current Deployment ID: undefined"
6154
+ `);
5598
6155
  expect(std.err).toMatchInlineSnapshot(`""`);
5599
6156
  expect(std.warn).toMatchInlineSnapshot(`""`);
5600
6157
  });
@@ -5687,11 +6244,12 @@ addEventListener('fetch', event => {});`
5687
6244
  });
5688
6245
  await runWrangler("publish index.js");
5689
6246
  expect(std.out).toMatchInlineSnapshot(`
5690
- "Total Upload: 0xx KiB / gzip: 0xx KiB
5691
- Uploaded test-name (TIMINGS)
5692
- Published test-name (TIMINGS)
5693
- test-name.test-sub-domain.workers.dev"
5694
- `);
6247
+ "Total Upload: xx KiB / gzip: xx KiB
6248
+ Uploaded test-name (TIMINGS)
6249
+ Published test-name (TIMINGS)
6250
+ https://test-name.test-sub-domain.workers.dev
6251
+ Current Deployment ID: undefined"
6252
+ `);
5695
6253
  expect(std.err).toMatchInlineSnapshot(`""`);
5696
6254
  expect(std.warn).toMatchInlineSnapshot(`""`);
5697
6255
  });
@@ -5717,11 +6275,12 @@ addEventListener('fetch', event => {});`
5717
6275
  });
5718
6276
  await runWrangler("publish index.js");
5719
6277
  expect(std.out).toMatchInlineSnapshot(`
5720
- "Total Upload: 0xx KiB / gzip: 0xx KiB
5721
- Uploaded test-name (TIMINGS)
5722
- Published test-name (TIMINGS)
5723
- test-name.test-sub-domain.workers.dev"
5724
- `);
6278
+ "Total Upload: xx KiB / gzip: xx KiB
6279
+ Uploaded test-name (TIMINGS)
6280
+ Published test-name (TIMINGS)
6281
+ https://test-name.test-sub-domain.workers.dev
6282
+ Current Deployment ID: undefined"
6283
+ `);
5725
6284
  expect(std.err).toMatchInlineSnapshot(`""`);
5726
6285
  expect(std.warn).toMatchInlineSnapshot(`
5727
6286
  "▲ [WARNING] Deprecation: detected a legacy module import in \\"./index.js\\". This will stop working in the future. Replace references to \\"text.file\\" with \\"./text.file\\";
@@ -5746,11 +6305,12 @@ addEventListener('fetch', event => {});`
5746
6305
  });
5747
6306
  await runWrangler("publish index.js");
5748
6307
  expect(std.out).toMatchInlineSnapshot(`
5749
- "Total Upload: 0xx KiB / gzip: 0xx KiB
5750
- Uploaded test-name (TIMINGS)
5751
- Published test-name (TIMINGS)
5752
- test-name.test-sub-domain.workers.dev"
5753
- `);
6308
+ "Total Upload: xx KiB / gzip: xx KiB
6309
+ Uploaded test-name (TIMINGS)
6310
+ Published test-name (TIMINGS)
6311
+ https://test-name.test-sub-domain.workers.dev
6312
+ Current Deployment ID: undefined"
6313
+ `);
5754
6314
  expect(std.err).toMatchInlineSnapshot(`""`);
5755
6315
  expect(std.warn).toMatchInlineSnapshot(`
5756
6316
  "▲ [WARNING] Deprecation: detected a legacy module import in \\"./index.js\\". This will stop working in the future. Replace references to \\"index.wasm\\" with \\"./index.wasm\\";
@@ -5759,6 +6319,38 @@ addEventListener('fetch', event => {});`
5759
6319
  `);
5760
6320
  });
5761
6321
 
6322
+ it("should work with legacy module specifiers, with a deprecation warning (3)", async () => {
6323
+ writeWranglerToml({
6324
+ rules: [{ type: "Text", globs: ["**/*.file"], fallthrough: false }],
6325
+ });
6326
+ fs.writeFileSync(
6327
+ "./index.js",
6328
+ `import TEXT from 'text+name.file'; export default {};`
6329
+ );
6330
+ fs.writeFileSync("./text+name.file", "SOME TEXT CONTENT");
6331
+ mockSubDomainRequest();
6332
+ mockUploadWorkerRequest({
6333
+ expectedModules: {
6334
+ "./2d91d1c4dd6e57d4f5432187ab7c25f45a8973f0-text+name.file":
6335
+ "SOME TEXT CONTENT",
6336
+ },
6337
+ });
6338
+ await runWrangler("publish index.js");
6339
+ expect(std.out).toMatchInlineSnapshot(`
6340
+ "Total Upload: xx KiB / gzip: xx KiB
6341
+ Uploaded test-name (TIMINGS)
6342
+ Published test-name (TIMINGS)
6343
+ https://test-name.test-sub-domain.workers.dev
6344
+ Current Deployment ID: undefined"
6345
+ `);
6346
+ expect(std.err).toMatchInlineSnapshot(`""`);
6347
+ expect(std.warn).toMatchInlineSnapshot(`
6348
+ "▲ [WARNING] Deprecation: detected a legacy module import in \\"./index.js\\". This will stop working in the future. Replace references to \\"text+name.file\\" with \\"./text+name.file\\";
6349
+
6350
+ "
6351
+ `);
6352
+ });
6353
+
5762
6354
  it("should not match regular module specifiers when there aren't any possible legacy module matches", async () => {
5763
6355
  // see https://github.com/cloudflare/wrangler2/issues/655 for bug details
5764
6356
 
@@ -5775,11 +6367,12 @@ addEventListener('fetch', event => {});`
5775
6367
  "publish index.js --compatibility-date 2022-03-17 --name test-name"
5776
6368
  );
5777
6369
  expect(std.out).toMatchInlineSnapshot(`
5778
- "Total Upload: 0xx KiB / gzip: 0xx KiB
5779
- Uploaded test-name (TIMINGS)
5780
- Published test-name (TIMINGS)
5781
- test-name.test-sub-domain.workers.dev"
5782
- `);
6370
+ "Total Upload: xx KiB / gzip: xx KiB
6371
+ Uploaded test-name (TIMINGS)
6372
+ Published test-name (TIMINGS)
6373
+ https://test-name.test-sub-domain.workers.dev
6374
+ Current Deployment ID: undefined"
6375
+ `);
5783
6376
  expect(std.err).toMatchInlineSnapshot(`""`);
5784
6377
  expect(std.warn).toMatchInlineSnapshot(`""`);
5785
6378
  });
@@ -5813,16 +6406,17 @@ addEventListener('fetch', event => {});`
5813
6406
  });
5814
6407
  await runWrangler("publish index.ts");
5815
6408
  expect(std).toMatchInlineSnapshot(`
5816
- Object {
5817
- "debug": "",
5818
- "err": "",
5819
- "out": "Total Upload: 0xx KiB / gzip: 0xx KiB
5820
- Uploaded test-name (TIMINGS)
5821
- Published test-name (TIMINGS)
5822
- test-name.test-sub-domain.workers.dev",
5823
- "warn": "",
5824
- }
5825
- `);
6409
+ Object {
6410
+ "debug": "",
6411
+ "err": "",
6412
+ "out": "Total Upload: xx KiB / gzip: xx KiB
6413
+ Uploaded test-name (TIMINGS)
6414
+ Published test-name (TIMINGS)
6415
+ https://test-name.test-sub-domain.workers.dev
6416
+ Current Deployment ID: undefined",
6417
+ "warn": "",
6418
+ }
6419
+ `);
5826
6420
  });
5827
6421
 
5828
6422
  it("should output to target es2020 even if tsconfig says otherwise", async () => {
@@ -5843,16 +6437,17 @@ addEventListener('fetch', event => {});`
5843
6437
  });
5844
6438
  await runWrangler("publish index.js"); // this would throw if we tried to compile with es5
5845
6439
  expect(std).toMatchInlineSnapshot(`
5846
- Object {
5847
- "debug": "",
5848
- "err": "",
5849
- "out": "Total Upload: 0xx KiB / gzip: 0xx KiB
5850
- Uploaded test-name (TIMINGS)
5851
- Published test-name (TIMINGS)
5852
- test-name.test-sub-domain.workers.dev",
5853
- "warn": "",
5854
- }
5855
- `);
6440
+ Object {
6441
+ "debug": "",
6442
+ "err": "",
6443
+ "out": "Total Upload: xx KiB / gzip: xx KiB
6444
+ Uploaded test-name (TIMINGS)
6445
+ Published test-name (TIMINGS)
6446
+ https://test-name.test-sub-domain.workers.dev
6447
+ Current Deployment ID: undefined",
6448
+ "warn": "",
6449
+ }
6450
+ `);
5856
6451
  });
5857
6452
  });
5858
6453
 
@@ -5866,16 +6461,17 @@ addEventListener('fetch', event => {});`
5866
6461
  expect(fs.existsSync("some-dir/index.js")).toBe(true);
5867
6462
  expect(fs.existsSync("some-dir/index.js.map")).toBe(true);
5868
6463
  expect(std).toMatchInlineSnapshot(`
5869
- Object {
5870
- "debug": "",
5871
- "err": "",
5872
- "out": "Total Upload: 0xx KiB / gzip: 0xx KiB
5873
- Uploaded test-name (TIMINGS)
5874
- Published test-name (TIMINGS)
5875
- test-name.test-sub-domain.workers.dev",
5876
- "warn": "",
5877
- }
5878
- `);
6464
+ Object {
6465
+ "debug": "",
6466
+ "err": "",
6467
+ "out": "Total Upload: xx KiB / gzip: xx KiB
6468
+ Uploaded test-name (TIMINGS)
6469
+ Published test-name (TIMINGS)
6470
+ https://test-name.test-sub-domain.workers.dev
6471
+ Current Deployment ID: undefined",
6472
+ "warn": "",
6473
+ }
6474
+ `);
5879
6475
  });
5880
6476
  });
5881
6477
 
@@ -5893,17 +6489,17 @@ addEventListener('fetch', event => {});`
5893
6489
  process.env.CLOUDFLARE_ACCOUNT_ID = "";
5894
6490
  await runWrangler("publish index.js --dry-run");
5895
6491
  expect(std).toMatchInlineSnapshot(`
5896
- Object {
5897
- "debug": "",
5898
- "err": "",
5899
- "out": "Your worker has access to the following bindings:
5900
- - Durable Objects:
5901
- - NAME: SomeClass
5902
- Total Upload: 0xx KiB / gzip: 0xx KiB
5903
- --dry-run: exiting now.",
5904
- "warn": "",
5905
- }
5906
- `);
6492
+ Object {
6493
+ "debug": "",
6494
+ "err": "",
6495
+ "out": "Total Upload: xx KiB / gzip: xx KiB
6496
+ Your worker has access to the following bindings:
6497
+ - Durable Objects:
6498
+ - NAME: SomeClass
6499
+ --dry-run: exiting now.",
6500
+ "warn": "",
6501
+ }
6502
+ `);
5907
6503
  });
5908
6504
  });
5909
6505
 
@@ -5916,7 +6512,7 @@ addEventListener('fetch', event => {});`
5916
6512
  Object {
5917
6513
  "debug": "",
5918
6514
  "err": "",
5919
- "out": "Total Upload: 0xx KiB / gzip: 0xx KiB
6515
+ "out": "Total Upload: xx KiB / gzip: xx KiB
5920
6516
  --dry-run: exiting now.",
5921
6517
  "warn": "▲ [WARNING] Enabling node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.
5922
6518
 
@@ -5935,14 +6531,16 @@ addEventListener('fetch', event => {});`
5935
6531
  export default {}
5936
6532
  `
5937
6533
  );
5938
- let err: Error | undefined;
6534
+ let err: esbuild.BuildFailure | undefined;
5939
6535
  try {
5940
6536
  await runWrangler("publish index.js --dry-run"); // expecting this to throw, as node compatibility isn't enabled
5941
6537
  } catch (e) {
5942
- err = e as Error;
6538
+ err = e as esbuild.BuildFailure;
5943
6539
  }
5944
- expect(err?.message).toMatch(
5945
- `Detected a Node builtin module import while Node compatibility is disabled.\nAdd node_compat = true to your wrangler.toml file to enable Node compatibility.`
6540
+ expect(
6541
+ esbuild.formatMessagesSync(err?.errors ?? [], { kind: "error" }).join()
6542
+ ).toMatch(
6543
+ /The package "path" wasn't found on the file system but is built into node\.\s+Add "node_compat = true" to your wrangler\.toml file to enable Node compatibility\./
5946
6544
  );
5947
6545
  });
5948
6546
 
@@ -5961,7 +6559,7 @@ addEventListener('fetch', event => {});`
5961
6559
  Object {
5962
6560
  "debug": "",
5963
6561
  "err": "",
5964
- "out": "Total Upload: 4xx KiB / gzip: 1xx KiB
6562
+ "out": "Total Upload: xx KiB / gzip: xx KiB
5965
6563
  --dry-run: exiting now.",
5966
6564
  "warn": "▲ [WARNING] Enabling node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.
5967
6565
 
@@ -6008,16 +6606,17 @@ addEventListener('fetch', event => {});`
6008
6606
  mockUploadWorkerRequest();
6009
6607
  await runWrangler("publish");
6010
6608
  expect(std).toMatchInlineSnapshot(`
6011
- Object {
6012
- "debug": "",
6013
- "err": "",
6014
- "out": "Total Upload: 4xx KiB / gzip: 0xx KiB
6015
- Uploaded test-name (TIMINGS)
6016
- Published test-name (TIMINGS)
6017
- test-name.test-sub-domain.workers.dev",
6018
- "warn": "",
6019
- }
6020
- `);
6609
+ Object {
6610
+ "debug": "",
6611
+ "err": "",
6612
+ "out": "Total Upload: xx KiB / gzip: xx KiB
6613
+ Uploaded test-name (TIMINGS)
6614
+ Published test-name (TIMINGS)
6615
+ https://test-name.test-sub-domain.workers.dev
6616
+ Current Deployment ID: undefined",
6617
+ "warn": "",
6618
+ }
6619
+ `);
6021
6620
  });
6022
6621
 
6023
6622
  it("should print the bundle size, with API errors", async () => {
@@ -6066,7 +6665,7 @@ addEventListener('fetch', event => {});`
6066
6665
  Object {
6067
6666
  "debug": "",
6068
6667
  "err": "",
6069
- "out": "Total Upload: 0xx KiB / gzip: 0xx KiB
6668
+ "out": "Total Upload: xx KiB / gzip: xx KiB
6070
6669
 
6071
6670
  X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name) failed.
6072
6671
 
@@ -6081,6 +6680,200 @@ addEventListener('fetch', event => {});`
6081
6680
  }
6082
6681
  `);
6083
6682
  });
6683
+
6684
+ test("should check biggest dependencies when upload fails with script size error", async () => {
6685
+ fs.writeFileSync("dependency.js", `export const thing = "a string dep";`);
6686
+
6687
+ fs.writeFileSync(
6688
+ "index.js",
6689
+ `import { thing } from "./dependency";
6690
+
6691
+ export default {
6692
+ async fetch() {
6693
+ return new Response('response plus ' + thing);
6694
+ }
6695
+ }`
6696
+ );
6697
+ setMockRawResponse(
6698
+ "/accounts/:accountId/workers/scripts/:scriptName",
6699
+ "PUT",
6700
+ () => {
6701
+ return createFetchResult({}, false, [
6702
+ { code: 10027, message: "workers.api.error.script_too_large" },
6703
+ ]);
6704
+ }
6705
+ );
6706
+ writeWranglerToml({
6707
+ main: "index.js",
6708
+ });
6709
+ mockSubDomainRequest();
6710
+ mockUploadWorkerRequest();
6711
+ await expect(runWrangler("publish")).rejects.toMatchInlineSnapshot(
6712
+ `[ParseError: A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name) failed.]`
6713
+ );
6714
+ expect(std).toMatchInlineSnapshot(`
6715
+ Object {
6716
+ "debug": "",
6717
+ "err": "",
6718
+ "out": "Total Upload: xx KiB / gzip: xx KiB
6719
+
6720
+ X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name) failed.
6721
+
6722
+ workers.api.error.script_too_large [code: 10027]
6723
+
6724
+ If you think this is a bug, please open an issue at:
6725
+ https://github.com/cloudflare/wrangler2/issues/new/choose
6726
+
6727
+ ",
6728
+ "warn": "▲ [WARNING] Here are the 2 largest dependencies included in your script:
6729
+
6730
+ - index.js - xx KiB
6731
+ - dependency.js - xx KiB
6732
+ If these are unnecessary, consider removing them
6733
+
6734
+ ",
6735
+ }
6736
+ `);
6737
+ });
6738
+
6739
+ test("should check biggest dependencies when upload fails with script startup error", async () => {
6740
+ fs.writeFileSync("dependency.js", `export const thing = "a string dep";`);
6741
+
6742
+ fs.writeFileSync(
6743
+ "index.js",
6744
+ `import { thing } from "./dependency";
6745
+
6746
+ export default {
6747
+ async fetch() {
6748
+ return new Response('response plus ' + thing);
6749
+ }
6750
+ }`
6751
+ );
6752
+ setMockRawResponse(
6753
+ "/accounts/:accountId/workers/scripts/:scriptName",
6754
+ "PUT",
6755
+ () => {
6756
+ return createFetchResult({}, false, [
6757
+ {
6758
+ code: 10021,
6759
+ message: "Error: Script startup exceeded CPU time limit.",
6760
+ },
6761
+ ]);
6762
+ }
6763
+ );
6764
+ writeWranglerToml({
6765
+ main: "index.js",
6766
+ });
6767
+ mockSubDomainRequest();
6768
+ mockUploadWorkerRequest();
6769
+ await expect(runWrangler("publish")).rejects.toMatchInlineSnapshot(
6770
+ `[ParseError: A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name) failed.]`
6771
+ );
6772
+ expect(std).toMatchInlineSnapshot(`
6773
+ Object {
6774
+ "debug": "",
6775
+ "err": "",
6776
+ "out": "Total Upload: xx KiB / gzip: xx KiB
6777
+
6778
+ X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name) failed.
6779
+
6780
+ Error: Script startup exceeded CPU time limit. [code: 10021]
6781
+
6782
+ If you think this is a bug, please open an issue at:
6783
+ https://github.com/cloudflare/wrangler2/issues/new/choose
6784
+
6785
+ ",
6786
+ "warn": "▲ [WARNING] Here are the 2 largest dependencies included in your script:
6787
+
6788
+ - index.js - xx KiB
6789
+ - dependency.js - xx KiB
6790
+ If these are unnecessary, consider removing them
6791
+
6792
+ ",
6793
+ }
6794
+ `);
6795
+ });
6796
+
6797
+ describe("unit tests", () => {
6798
+ // keeping these as unit tests to try and keep them snappy, as they often deal with
6799
+ // big files that would take a while to deal with in a full wrangler test
6800
+
6801
+ test("should print the bundle size and warn about large scripts when > 1MiB", async () => {
6802
+ const bigModule = Buffer.alloc(10_000_000);
6803
+ randomFillSync(bigModule);
6804
+ await printBundleSize({ name: "index.js", content: "" }, [
6805
+ { name: "index.js", content: bigModule, type: "buffer" },
6806
+ ]);
6807
+
6808
+ expect(std).toMatchInlineSnapshot(`
6809
+ Object {
6810
+ "debug": "",
6811
+ "err": "",
6812
+ "out": "Total Upload: xx KiB / gzip: xx KiB",
6813
+ "warn": "▲ [WARNING] We recommend keeping your script less than 1MiB (1024 KiB) after gzip. Exceeding past this can affect cold start time
6814
+
6815
+ ",
6816
+ }
6817
+ `);
6818
+ });
6819
+
6820
+ test("should not warn about bundle sizes when NO_SCRIPT_SIZE_WARNING is set", async () => {
6821
+ const previousValue = process.env.NO_SCRIPT_SIZE_WARNING;
6822
+ process.env.NO_SCRIPT_SIZE_WARNING = "true";
6823
+
6824
+ const bigModule = Buffer.alloc(10_000_000);
6825
+ randomFillSync(bigModule);
6826
+ await printBundleSize({ name: "index.js", content: "" }, [
6827
+ { name: "index.js", content: bigModule, type: "buffer" },
6828
+ ]);
6829
+
6830
+ expect(std).toMatchInlineSnapshot(`
6831
+ Object {
6832
+ "debug": "",
6833
+ "err": "",
6834
+ "out": "Total Upload: xx KiB / gzip: xx KiB",
6835
+ "warn": "",
6836
+ }
6837
+ `);
6838
+
6839
+ process.env.NO_SCRIPT_SIZE_WARNING = previousValue;
6840
+ });
6841
+
6842
+ test("should print the top biggest dependencies in the bundle when upload fails", () => {
6843
+ const deps = {
6844
+ "node_modules/a-mod/module.js": { bytesInOutput: 450 },
6845
+ "node_modules/b-mod/module.js": { bytesInOutput: 10 },
6846
+ "node_modules/c-mod/module.js": { bytesInOutput: 200 },
6847
+ "node_modules/d-mod/module.js": { bytesInOutput: 2111200 }, // 1
6848
+ "node_modules/e-mod/module.js": { bytesInOutput: 8209 }, // 3
6849
+ "node_modules/f-mod/module.js": { bytesInOutput: 770 },
6850
+ "node_modules/g-mod/module.js": { bytesInOutput: 78902 }, // 2
6851
+ "node_modules/h-mod/module.js": { bytesInOutput: 899 },
6852
+ "node_modules/i-mod/module.js": { bytesInOutput: 2001 }, // 4
6853
+ "node_modules/j-mod/module.js": { bytesInOutput: 900 }, // 5
6854
+ "node_modules/k-mod/module.js": { bytesInOutput: 79 },
6855
+ };
6856
+
6857
+ printOffendingDependencies(deps);
6858
+ expect(std).toMatchInlineSnapshot(`
6859
+ Object {
6860
+ "debug": "",
6861
+ "err": "",
6862
+ "out": "",
6863
+ "warn": "▲ [WARNING] Here are the 5 largest dependencies included in your script:
6864
+
6865
+ - node_modules/d-mod/module.js - xx KiB
6866
+ - node_modules/g-mod/module.js - xx KiB
6867
+ - node_modules/e-mod/module.js - xx KiB
6868
+ - node_modules/i-mod/module.js - xx KiB
6869
+ - node_modules/j-mod/module.js - xx KiB
6870
+ If these are unnecessary, consider removing them
6871
+
6872
+ ",
6873
+ }
6874
+ `);
6875
+ });
6876
+ });
6084
6877
  });
6085
6878
 
6086
6879
  describe("--no-bundle", () => {
@@ -6184,6 +6977,240 @@ addEventListener('fetch', event => {});`
6184
6977
  `);
6185
6978
  });
6186
6979
  });
6980
+
6981
+ it("should publish if the last deployed source check fails", async () => {
6982
+ unsetAllMocks();
6983
+ writeWorkerSource();
6984
+ writeWranglerToml();
6985
+ mockSubDomainRequest();
6986
+ mockUploadWorkerRequest();
6987
+ setMockResponse(
6988
+ "/accounts/:accountId/workers/deployments/by-script/:scriptTag",
6989
+ () => ({
6990
+ latest: { number: "2" },
6991
+ })
6992
+ );
6993
+ setMockRawResponse(
6994
+ "/accounts/:accountId/workers/services/:scriptName",
6995
+ "GET",
6996
+ () => {
6997
+ return createFetchResult(null, false, [
6998
+ { code: 10090, message: "workers.api.error.service_not_found" },
6999
+ ]);
7000
+ }
7001
+ );
7002
+
7003
+ await runWrangler("publish index.js");
7004
+ expect(std).toMatchInlineSnapshot(`
7005
+ Object {
7006
+ "debug": "",
7007
+ "err": "",
7008
+ "out": "Total Upload: xx KiB / gzip: xx KiB
7009
+ Uploaded test-name (TIMINGS)
7010
+ Published test-name (TIMINGS)
7011
+ https://test-name.test-sub-domain.workers.dev
7012
+ Current Deployment ID: undefined",
7013
+ "warn": "",
7014
+ }
7015
+ `);
7016
+ });
7017
+
7018
+ it("should not publish if there's any other kind of error when checking deployment source", async () => {
7019
+ unsetAllMocks();
7020
+ writeWorkerSource();
7021
+ writeWranglerToml();
7022
+ mockSubDomainRequest();
7023
+ mockUploadWorkerRequest();
7024
+ setMockRawResponse(
7025
+ "/accounts/:accountId/workers/services/:scriptName",
7026
+ "GET",
7027
+ () => {
7028
+ return createFetchResult(null, false, [
7029
+ { code: 10000, message: "Authentication error" },
7030
+ ]);
7031
+ }
7032
+ );
7033
+ setMockResponse(
7034
+ "/accounts/:accountId/workers/deployments/by-script/:scriptTag",
7035
+ () => ({
7036
+ latest: { number: "2" },
7037
+ })
7038
+ );
7039
+
7040
+ await runWrangler("publish index.js");
7041
+ expect(std.err).toContain(
7042
+ `A request to the Cloudflare API (/accounts/some-account-id/workers/services/test-name) failed`
7043
+ );
7044
+ });
7045
+
7046
+ describe("queues", () => {
7047
+ it("should upload producer bindings", async () => {
7048
+ writeWranglerToml({
7049
+ queues: {
7050
+ producers: [{ binding: "QUEUE_ONE", queue: "queue1" }],
7051
+ },
7052
+ });
7053
+ await fs.promises.writeFile("index.js", `export default {};`);
7054
+ mockSubDomainRequest();
7055
+ mockUploadWorkerRequest({
7056
+ expectedBindings: [
7057
+ {
7058
+ type: "queue",
7059
+ name: "QUEUE_ONE",
7060
+ queue_name: "queue1",
7061
+ },
7062
+ ],
7063
+ });
7064
+ mockGetQueue("queue1");
7065
+
7066
+ await runWrangler("publish index.js");
7067
+ expect(std.out).toMatchInlineSnapshot(`
7068
+ "Total Upload: xx KiB / gzip: xx KiB
7069
+ Your worker has access to the following bindings:
7070
+ - Queues:
7071
+ - QUEUE_ONE: queue1
7072
+ Uploaded test-name (TIMINGS)
7073
+ Published test-name (TIMINGS)
7074
+ https://test-name.test-sub-domain.workers.dev
7075
+ Current Deployment ID: undefined"
7076
+ `);
7077
+ });
7078
+
7079
+ it("should update queue consumers on publish", async () => {
7080
+ writeWranglerToml({
7081
+ queues: {
7082
+ consumers: [
7083
+ {
7084
+ queue: "queue1",
7085
+ dead_letter_queue: "myDLQ",
7086
+ max_batch_size: 5,
7087
+ max_batch_timeout: 3,
7088
+ max_retries: 10,
7089
+ },
7090
+ ],
7091
+ },
7092
+ });
7093
+ await fs.promises.writeFile("index.js", `export default {};`);
7094
+ mockSubDomainRequest();
7095
+ mockUploadWorkerRequest();
7096
+ mockGetQueue("queue1");
7097
+ mockPutQueueConsumer("queue1", "test-name", {
7098
+ dead_letter_queue: "myDLQ",
7099
+ settings: {
7100
+ batch_size: 5,
7101
+ max_retries: 10,
7102
+ max_wait_time_ms: 3000,
7103
+ },
7104
+ });
7105
+ await runWrangler("publish index.js");
7106
+ expect(std.out).toMatchInlineSnapshot(`
7107
+ "Total Upload: xx KiB / gzip: xx KiB
7108
+ Uploaded test-name (TIMINGS)
7109
+ Published test-name (TIMINGS)
7110
+ https://test-name.test-sub-domain.workers.dev
7111
+ Consumer for queue1
7112
+ Current Deployment ID: undefined"
7113
+ `);
7114
+ });
7115
+
7116
+ it("consumer should error when a queue doesn't exist", async () => {
7117
+ writeWranglerToml({
7118
+ queues: {
7119
+ producers: [],
7120
+ consumers: [
7121
+ {
7122
+ queue: "queue1",
7123
+ dead_letter_queue: "myDLQ",
7124
+ max_batch_size: 5,
7125
+ max_batch_timeout: 3,
7126
+ max_retries: 10,
7127
+ },
7128
+ ],
7129
+ },
7130
+ });
7131
+ await fs.promises.writeFile("index.js", `export default {};`);
7132
+ mockSubDomainRequest();
7133
+ mockUploadWorkerRequest();
7134
+ mockGetQueueMissing("queue1");
7135
+
7136
+ await expect(
7137
+ runWrangler("publish index.js")
7138
+ ).rejects.toMatchInlineSnapshot(
7139
+ `[Error: Queue "queue1" does not exist. To create it, run: wrangler queues create queue1]`
7140
+ );
7141
+ });
7142
+
7143
+ it("producer should error when a queue doesn't exist", async () => {
7144
+ writeWranglerToml({
7145
+ queues: {
7146
+ producers: [{ queue: "queue1", binding: "QUEUE_ONE" }],
7147
+ consumers: [],
7148
+ },
7149
+ });
7150
+ await fs.promises.writeFile("index.js", `export default {};`);
7151
+ mockSubDomainRequest();
7152
+ mockUploadWorkerRequest();
7153
+ mockGetQueueMissing("queue1");
7154
+
7155
+ await expect(
7156
+ runWrangler("publish index.js")
7157
+ ).rejects.toMatchInlineSnapshot(
7158
+ `[Error: Queue "queue1" does not exist. To create it, run: wrangler queues create queue1]`
7159
+ );
7160
+ });
7161
+ });
7162
+
7163
+ describe("--keep-vars", () => {
7164
+ it("should send keepVars when keep-vars is passed in", async () => {
7165
+ process.env = {
7166
+ CLOUDFLARE_API_TOKEN: "hunter2",
7167
+ CLOUDFLARE_ACCOUNT_ID: "some-account-id",
7168
+ };
7169
+ setIsTTY(false);
7170
+ writeWranglerToml();
7171
+ writeWorkerSource();
7172
+ mockSubDomainRequest();
7173
+ mockUploadWorkerRequest({ keepVars: true });
7174
+ mockOAuthServerCallback();
7175
+ mockGetMemberships([]);
7176
+
7177
+ await runWrangler("publish index.js --keep-vars");
7178
+
7179
+ expect(std.out).toMatchInlineSnapshot(`
7180
+ "Total Upload: xx KiB / gzip: xx KiB
7181
+ Uploaded test-name (TIMINGS)
7182
+ Published test-name (TIMINGS)
7183
+ https://test-name.test-sub-domain.workers.dev
7184
+ Current Deployment ID: undefined"
7185
+ `);
7186
+ expect(std.err).toMatchInlineSnapshot(`""`);
7187
+ });
7188
+
7189
+ it("should not send keepVars by default", async () => {
7190
+ process.env = {
7191
+ CLOUDFLARE_API_TOKEN: "hunter2",
7192
+ CLOUDFLARE_ACCOUNT_ID: "some-account-id",
7193
+ };
7194
+ setIsTTY(false);
7195
+ writeWranglerToml();
7196
+ writeWorkerSource();
7197
+ mockSubDomainRequest();
7198
+ mockUploadWorkerRequest();
7199
+ mockOAuthServerCallback();
7200
+ mockGetMemberships([]);
7201
+
7202
+ await runWrangler("publish index.js");
7203
+
7204
+ expect(std.out).toMatchInlineSnapshot(`
7205
+ "Total Upload: xx KiB / gzip: xx KiB
7206
+ Uploaded test-name (TIMINGS)
7207
+ Published test-name (TIMINGS)
7208
+ https://test-name.test-sub-domain.workers.dev
7209
+ Current Deployment ID: undefined"
7210
+ `);
7211
+ expect(std.err).toMatchInlineSnapshot(`""`);
7212
+ });
7213
+ });
6187
7214
  });
6188
7215
 
6189
7216
  /** Write mock assets to the file system so they can be uploaded. */
@@ -6215,6 +7242,8 @@ function mockUploadWorkerRequest(
6215
7242
  env?: string;
6216
7243
  legacyEnv?: boolean;
6217
7244
  sendScriptIds?: boolean;
7245
+ keepVars?: boolean;
7246
+ tag?: string;
6218
7247
  } = {}
6219
7248
  ) {
6220
7249
  const {
@@ -6230,6 +7259,7 @@ function mockUploadWorkerRequest(
6230
7259
  legacyEnv = false,
6231
7260
  expectedMigrations,
6232
7261
  sendScriptIds,
7262
+ keepVars,
6233
7263
  } = options;
6234
7264
  setMockResponse(
6235
7265
  env && !legacyEnv
@@ -6260,6 +7290,13 @@ function mockUploadWorkerRequest(
6260
7290
  } else {
6261
7291
  expect(metadata.body_part).toEqual("index.js");
6262
7292
  }
7293
+
7294
+ if (keepVars) {
7295
+ expect(metadata.keep_bindings).toEqual(["plain_text", "json"]);
7296
+ } else {
7297
+ expect(metadata.keep_bindings).toBeFalsy();
7298
+ }
7299
+
6263
7300
  if ("expectedBindings" in options) {
6264
7301
  expect(metadata.bindings).toEqual(expectedBindings);
6265
7302
  }
@@ -6285,6 +7322,7 @@ function mockUploadWorkerRequest(
6285
7322
  id: "abc12345",
6286
7323
  etag: "etag98765",
6287
7324
  pipeline_hash: "hash9999",
7325
+ tag: "sample-tag",
6288
7326
  }
6289
7327
  : {}),
6290
7328
  };
@@ -6395,19 +7433,6 @@ function mockUnauthorizedPublishRoutesRequest({
6395
7433
  );
6396
7434
  }
6397
7435
 
6398
- function mockCollectKnownRoutesRequest(
6399
- routes: { pattern: string; script: string }[]
6400
- ) {
6401
- setMockResponse(`/zones/:zoneId/workers/routes`, "GET", () => routes);
6402
- }
6403
-
6404
- function mockGetZoneFromHostRequest(host: string, zone: string) {
6405
- setMockResponse("/zones", (_uri, _init, queryParams) => {
6406
- expect(queryParams.get("name")).toEqual(host);
6407
- return [{ id: zone }];
6408
- });
6409
- }
6410
-
6411
7436
  function mockPublishRoutesFallbackRequest(route: {
6412
7437
  pattern: string;
6413
7438
  script: string;
@@ -6418,20 +7443,27 @@ function mockPublishRoutesFallbackRequest(route: {
6418
7443
  });
6419
7444
  }
6420
7445
 
6421
- function mockPublishCustomDomainsRequest({
6422
- publishFlags,
6423
- domains = [],
7446
+ function mockCustomDomainLookup(origin: CustomDomain) {
7447
+ setMockResponse(
7448
+ `/accounts/:accountId/workers/domains/records/:domainTag`,
7449
+ "GET",
7450
+ ([_url, accountId, domainTag]) => {
7451
+ expect(accountId).toEqual("some-account-id");
7452
+ expect(domainTag).toEqual(origin.id);
7453
+
7454
+ return origin;
7455
+ }
7456
+ );
7457
+ }
7458
+
7459
+ function mockCustomDomainsChangesetRequest({
7460
+ originConflicts = [],
7461
+ dnsRecordConflicts = [],
6424
7462
  env = undefined,
6425
7463
  legacyEnv = false,
6426
7464
  }: {
6427
- publishFlags: {
6428
- override_scope: boolean;
6429
- override_existing_origin: boolean;
6430
- override_existing_dns_record: boolean;
6431
- };
6432
- domains: Array<
6433
- { hostname: string } & ({ zone_id?: string } | { zone_name?: string })
6434
- >;
7465
+ originConflicts?: Array<CustomDomain>;
7466
+ dnsRecordConflicts?: Array<CustomDomain>;
6435
7467
  env?: string | undefined;
6436
7468
  legacyEnv?: boolean | undefined;
6437
7469
  }) {
@@ -6439,8 +7471,8 @@ function mockPublishCustomDomainsRequest({
6439
7471
  const environment = env && !legacyEnv ? "/environments/:envName" : "";
6440
7472
 
6441
7473
  setMockResponse(
6442
- `/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/domains`,
6443
- "PUT",
7474
+ `/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/domains/changeset`,
7475
+ "POST",
6444
7476
  ([_url, accountId, scriptName, envName], { body }) => {
6445
7477
  expect(accountId).toEqual("some-account-id");
6446
7478
  expect(scriptName).toEqual(
@@ -6450,25 +7482,48 @@ function mockPublishCustomDomainsRequest({
6450
7482
  expect(envName).toEqual(env);
6451
7483
  }
6452
7484
 
6453
- expect(JSON.parse(body as string)).toEqual({
6454
- ...publishFlags,
6455
- origins: domains,
6456
- });
7485
+ const domains: Array<
7486
+ { hostname: string } & ({ zone_id?: string } | { zone_name?: string })
7487
+ > = JSON.parse(body as string);
7488
+
7489
+ const changeset: CustomDomainChangeset = {
7490
+ added: domains.map((domain) => {
7491
+ return {
7492
+ ...domain,
7493
+ id: "",
7494
+ service: scriptName,
7495
+ environment: envName,
7496
+ zone_name: "",
7497
+ zone_id: "",
7498
+ };
7499
+ }),
7500
+ removed: [],
7501
+ updated:
7502
+ originConflicts?.map((domain) => {
7503
+ return {
7504
+ ...domain,
7505
+ modified: true,
7506
+ };
7507
+ }) ?? [],
7508
+ conflicting: dnsRecordConflicts,
7509
+ };
6457
7510
 
6458
- return null;
7511
+ return changeset;
6459
7512
  }
6460
7513
  );
6461
7514
  }
6462
7515
 
6463
- function mockPublishCustomDomainsRequestConflictWithoutOverride({
7516
+ function mockPublishCustomDomainsRequest({
7517
+ publishFlags,
6464
7518
  domains = [],
6465
- originConflicts = false,
6466
- dnsRecordConflicts = false,
6467
7519
  env = undefined,
6468
7520
  legacyEnv = false,
6469
7521
  }: {
6470
- originConflicts?: boolean;
6471
- dnsRecordConflicts?: boolean;
7522
+ publishFlags: {
7523
+ override_scope: boolean;
7524
+ override_existing_origin: boolean;
7525
+ override_existing_dns_record: boolean;
7526
+ };
6472
7527
  domains: Array<
6473
7528
  { hostname: string } & ({ zone_id?: string } | { zone_name?: string })
6474
7529
  >;
@@ -6478,8 +7533,8 @@ function mockPublishCustomDomainsRequestConflictWithoutOverride({
6478
7533
  const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
6479
7534
  const environment = env && !legacyEnv ? "/environments/:envName" : "";
6480
7535
 
6481
- setMockRawResponse(
6482
- `/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/domains`,
7536
+ setMockResponse(
7537
+ `/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/domains/records`,
6483
7538
  "PUT",
6484
7539
  ([_url, accountId, scriptName, envName], { body }) => {
6485
7540
  expect(accountId).toEqual("some-account-id");
@@ -6490,26 +7545,12 @@ function mockPublishCustomDomainsRequestConflictWithoutOverride({
6490
7545
  expect(envName).toEqual(env);
6491
7546
  }
6492
7547
 
6493
- const parsed = JSON.parse(body as string);
6494
- expect(parsed.origins).toEqual(domains);
7548
+ expect(JSON.parse(body as string)).toEqual({
7549
+ ...publishFlags,
7550
+ origins: domains,
7551
+ });
6495
7552
 
6496
- if (originConflicts && !parsed.override_existing_origin) {
6497
- return createFetchResult(null, false, [
6498
- {
6499
- code: 100116,
6500
- message: `Cannot create Custom Domain "${domains[0].hostname}": Custom Domain already exists and points to a different script; retry and use option "override_existing_origin" to override`,
6501
- },
6502
- ]);
6503
- }
6504
- if (dnsRecordConflicts && !parsed.override_existing_dns_record) {
6505
- return createFetchResult(null, false, [
6506
- {
6507
- code: 100117,
6508
- message: `Cannot create Custom Domain "${domains[0].hostname}": a DNS record already exists for this origin; retry and use option "override_existing_dns_record" to override`,
6509
- },
6510
- ]);
6511
- }
6512
- return createFetchResult(null, true);
7553
+ return null;
6513
7554
  }
6514
7555
  );
6515
7556
  }
@@ -6669,3 +7710,48 @@ function mockServiceScriptData(options: {
6669
7710
  );
6670
7711
  }
6671
7712
  }
7713
+
7714
+ function mockGetQueue(expectedQueueName: string) {
7715
+ const requests = { count: 0 };
7716
+ setMockResponse(
7717
+ `/accounts/:accountId/workers/queues/${expectedQueueName}`,
7718
+ "GET",
7719
+ ([_url, accountId]) => {
7720
+ expect(accountId).toEqual("some-account-id");
7721
+ requests.count += 1;
7722
+ return { queue: expectedQueueName };
7723
+ }
7724
+ );
7725
+ return requests;
7726
+ }
7727
+
7728
+ function mockGetQueueMissing(expectedQueueName: string) {
7729
+ const requests = { count: 0 };
7730
+ setMockResponse(
7731
+ `/accounts/:accountId/workers/queues/${expectedQueueName}`,
7732
+ "GET",
7733
+ ([_url, _accountId]) => {
7734
+ throw { code: 11000 };
7735
+ }
7736
+ );
7737
+ return requests;
7738
+ }
7739
+
7740
+ function mockPutQueueConsumer(
7741
+ expectedQueueName: string,
7742
+ expectedConsumerName: string,
7743
+ expectedBody: PutConsumerBody
7744
+ ) {
7745
+ const requests = { count: 0 };
7746
+ setMockResponse(
7747
+ `/accounts/:accountId/workers/queues/${expectedQueueName}/consumers/${expectedConsumerName}`,
7748
+ "PUT",
7749
+ ([_url, accountId], { body }) => {
7750
+ expect(accountId).toEqual("some-account-id");
7751
+ expect(JSON.parse(body as string)).toEqual(expectedBody);
7752
+ requests.count += 1;
7753
+ return { queue: expectedQueueName };
7754
+ }
7755
+ );
7756
+ return requests;
7757
+ }