wrangler 0.0.0-e30d1013 → 0.0.0-e311bbbf

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 (236) hide show
  1. package/README.md +3 -3
  2. package/bin/wrangler.js +30 -10
  3. package/miniflare-dist/index.mjs +126 -74
  4. package/package.json +26 -19
  5. package/src/__tests__/api-dev.test.ts +65 -36
  6. package/src/__tests__/api-devregistry.test.ts +121 -0
  7. package/src/__tests__/api.test.ts +27 -5
  8. package/src/__tests__/configuration.test.ts +567 -39
  9. package/src/__tests__/d1/d1.test.ts +82 -0
  10. package/src/__tests__/d1/execute.test.ts +66 -0
  11. package/src/__tests__/d1/migrate.test.ts +157 -0
  12. package/src/__tests__/d1/splitter.test.ts +255 -0
  13. package/src/__tests__/delete.test.ts +91 -49
  14. package/src/__tests__/deployments.test.ts +330 -52
  15. package/src/__tests__/dev.test.tsx +198 -90
  16. package/src/__tests__/generate.test.ts +8 -5
  17. package/src/__tests__/guess-worker-format.test.ts +35 -0
  18. package/src/__tests__/helpers/end-event-loop.ts +6 -0
  19. package/src/__tests__/helpers/mock-auth-domain.ts +20 -0
  20. package/src/__tests__/helpers/mock-console.ts +6 -0
  21. package/src/__tests__/helpers/mock-dialogs.ts +71 -85
  22. package/src/__tests__/helpers/mock-get-pages-upload-token.ts +25 -0
  23. package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -5
  24. package/src/__tests__/helpers/mock-known-routes.ts +7 -2
  25. package/src/__tests__/helpers/mock-kv.ts +29 -16
  26. package/src/__tests__/helpers/mock-oauth-flow.ts +103 -92
  27. package/src/__tests__/helpers/mock-process.ts +8 -13
  28. package/src/__tests__/helpers/mock-set-timeout.ts +16 -0
  29. package/src/__tests__/helpers/msw/blob-worker.cjs +19 -0
  30. package/src/__tests__/helpers/msw/handlers/deployments.ts +127 -26
  31. package/src/__tests__/helpers/msw/handlers/namespaces.ts +18 -41
  32. package/src/__tests__/helpers/msw/handlers/oauth.ts +13 -18
  33. package/src/__tests__/helpers/msw/handlers/r2.ts +14 -34
  34. package/src/__tests__/helpers/msw/handlers/script.ts +9 -28
  35. package/src/__tests__/helpers/msw/handlers/user.ts +13 -24
  36. package/src/__tests__/helpers/msw/handlers/zones.ts +6 -8
  37. package/src/__tests__/helpers/msw/index.ts +32 -1
  38. package/src/__tests__/helpers/msw/read-file-sync.js +61 -0
  39. package/src/__tests__/helpers/string-dynamic-values-matcher.ts +28 -0
  40. package/src/__tests__/helpers/worker-scripts/parent-worker.js +4 -1
  41. package/src/__tests__/index.test.ts +90 -72
  42. package/src/__tests__/init.test.ts +927 -631
  43. package/src/__tests__/jest.setup.ts +19 -42
  44. package/src/__tests__/kv.test.ts +355 -231
  45. package/src/__tests__/logger.test.ts +68 -2
  46. package/src/__tests__/logout.test.ts +47 -0
  47. package/src/__tests__/metrics.test.ts +94 -51
  48. package/src/__tests__/middleware.scheduled.test.ts +42 -32
  49. package/src/__tests__/middleware.test.ts +212 -122
  50. package/src/__tests__/mtls-certificates.test.ts +588 -0
  51. package/src/__tests__/pages/deployment-list.test.ts +80 -0
  52. package/src/__tests__/pages/functions-build.test.ts +452 -0
  53. package/src/__tests__/pages/pages.test.ts +81 -0
  54. package/src/__tests__/pages/project-create.test.ts +63 -0
  55. package/src/__tests__/pages/project-list.test.ts +110 -0
  56. package/src/__tests__/pages/project-upload.test.ts +500 -0
  57. package/src/__tests__/pages/publish.test.ts +2864 -0
  58. package/src/__tests__/pages-deployment-tail.test.ts +955 -0
  59. package/src/__tests__/parse.test.ts +106 -0
  60. package/src/__tests__/publish.test.ts +1620 -830
  61. package/src/__tests__/pubsub.test.ts +226 -100
  62. package/src/__tests__/queues.test.ts +237 -76
  63. package/src/__tests__/r2.test.ts +37 -56
  64. package/src/__tests__/secret.test.ts +179 -130
  65. package/src/__tests__/tail.test.ts +267 -109
  66. package/src/__tests__/test-old-node-version.js +3 -3
  67. package/src/__tests__/traverse-module-graph.test.ts +220 -0
  68. package/src/__tests__/tsconfig-sanity.ts +12 -0
  69. package/src/__tests__/tsconfig.json +8 -0
  70. package/src/__tests__/tsconfig.tsbuildinfo +1 -0
  71. package/src/__tests__/type-generation.test.ts +11 -2
  72. package/src/__tests__/user.test.ts +35 -72
  73. package/src/__tests__/whoami.test.tsx +8 -114
  74. package/src/__tests__/worker-namespace.test.ts +83 -69
  75. package/src/api/dev.ts +168 -60
  76. package/src/api/index.ts +10 -1
  77. package/src/api/mtls-certificate.ts +148 -0
  78. package/src/api/pages/create-worker-bundle-contents.ts +76 -0
  79. package/src/api/pages/index.ts +5 -0
  80. package/src/api/pages/publish.tsx +355 -0
  81. package/src/bundle.ts +221 -128
  82. package/src/cfetch/index.ts +0 -2
  83. package/src/cfetch/internal.ts +16 -21
  84. package/src/cli.ts +4 -4
  85. package/src/config/config.ts +14 -7
  86. package/src/config/environment.ts +73 -16
  87. package/src/config/index.ts +99 -30
  88. package/src/config/validation-helpers.ts +1 -1
  89. package/src/config/validation.ts +248 -9
  90. package/src/create-worker-preview.ts +19 -8
  91. package/src/create-worker-upload-form.ts +48 -5
  92. package/src/d1/backups.tsx +43 -42
  93. package/src/d1/create.tsx +26 -21
  94. package/src/d1/{delete.tsx → delete.ts} +11 -14
  95. package/src/d1/execute.tsx +183 -170
  96. package/src/d1/index.ts +7 -6
  97. package/src/d1/list.tsx +22 -10
  98. package/src/d1/migrations/apply.tsx +212 -0
  99. package/src/d1/migrations/create.tsx +79 -0
  100. package/src/d1/migrations/helpers.ts +172 -0
  101. package/src/d1/migrations/index.ts +3 -0
  102. package/src/d1/migrations/list.tsx +95 -0
  103. package/src/d1/migrations/options.ts +23 -0
  104. package/src/d1/options.ts +3 -3
  105. package/src/d1/splitter.ts +161 -0
  106. package/src/d1/{types.tsx → types.ts} +1 -0
  107. package/src/d1/utils.ts +2 -1
  108. package/src/delete.ts +8 -16
  109. package/src/deployments.ts +333 -42
  110. package/src/deprecated/index.ts +8 -302
  111. package/src/dev/dev.tsx +57 -44
  112. package/src/dev/local.tsx +248 -74
  113. package/src/dev/remote.tsx +32 -3
  114. package/src/dev/start-server.ts +81 -66
  115. package/src/dev/use-esbuild.ts +17 -18
  116. package/src/dev/validate-dev-props.ts +9 -0
  117. package/src/{dev-registry.tsx → dev-registry.ts} +2 -1
  118. package/src/dev.tsx +178 -117
  119. package/src/dialogs.ts +136 -0
  120. package/src/dispatch-namespace.ts +21 -17
  121. package/src/docs/index.ts +97 -0
  122. package/src/entry.ts +19 -11
  123. package/src/environment-variables/factory.ts +88 -0
  124. package/src/environment-variables/misc-variables.ts +30 -0
  125. package/src/generate/index.ts +298 -0
  126. package/src/git-client.ts +15 -4
  127. package/src/{index.tsx → index.ts} +134 -59
  128. package/src/init.ts +249 -187
  129. package/src/inspect.ts +16 -1
  130. package/src/jest.d.ts +4 -0
  131. package/src/kv/index.ts +15 -17
  132. package/src/logger.ts +32 -5
  133. package/src/metrics/metrics-config.ts +3 -3
  134. package/src/metrics/send-event.ts +6 -1
  135. package/src/miniflare-cli/assets.ts +64 -28
  136. package/src/miniflare-cli/index.ts +4 -7
  137. package/src/miniflare-cli/tsconfig.json +9 -0
  138. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -0
  139. package/src/miniflare-cli/types.ts +11 -0
  140. package/src/module-collection.ts +91 -25
  141. package/src/mtls-certificate/cli.ts +155 -0
  142. package/src/pages/build.ts +410 -0
  143. package/src/pages/buildFunctions.ts +140 -0
  144. package/src/pages/deployment-tails.ts +281 -0
  145. package/src/pages/deployments.tsx +11 -33
  146. package/src/pages/{dev.tsx → dev.ts} +147 -139
  147. package/src/pages/errors.ts +1 -0
  148. package/src/pages/functions/buildPlugin.ts +61 -54
  149. package/src/pages/functions/buildWorker.ts +159 -33
  150. package/src/pages/functions/tsconfig.json +8 -0
  151. package/src/pages/functions/tsconfig.tsbuildinfo +1 -0
  152. package/src/pages/{functions.tsx → functions.ts} +8 -4
  153. package/src/pages/{index.tsx → index.ts} +11 -3
  154. package/src/pages/projects.tsx +12 -22
  155. package/src/pages/prompt-select-project.tsx +31 -0
  156. package/src/pages/publish.tsx +46 -225
  157. package/src/pages/types.ts +6 -9
  158. package/src/pages/upload.tsx +58 -14
  159. package/src/pages/utils.ts +12 -1
  160. package/src/parse.ts +23 -1
  161. package/src/paths.ts +1 -1
  162. package/src/proxy.ts +5 -0
  163. package/src/publish/index.ts +20 -16
  164. package/src/publish/publish.ts +71 -46
  165. package/src/pubsub/{pubsub-commands.tsx → pubsub-commands.ts} +19 -20
  166. package/src/queues/cli/commands/consumer/add.ts +24 -24
  167. package/src/queues/cli/commands/consumer/index.ts +3 -6
  168. package/src/queues/cli/commands/consumer/remove.ts +11 -18
  169. package/src/queues/cli/commands/create.ts +8 -8
  170. package/src/queues/cli/commands/delete.ts +8 -8
  171. package/src/queues/cli/commands/index.ts +6 -4
  172. package/src/queues/cli/commands/list.ts +8 -8
  173. package/src/queues/client.ts +1 -0
  174. package/src/queues/utils.ts +18 -0
  175. package/src/r2/helpers.ts +1 -0
  176. package/src/r2/index.ts +28 -28
  177. package/src/secret/index.ts +14 -16
  178. package/src/{sites.tsx → sites.ts} +1 -1
  179. package/src/tail/createTail.ts +94 -3
  180. package/src/tail/filters.ts +1 -1
  181. package/src/tail/index.ts +8 -11
  182. package/src/tail/printing.ts +15 -0
  183. package/src/traverse-module-graph.ts +53 -0
  184. package/src/tsconfig-sanity.ts +16 -0
  185. package/src/type-generation.ts +28 -20
  186. package/src/user/access.ts +0 -1
  187. package/src/user/auth-variables.ts +113 -0
  188. package/src/user/choose-account.tsx +1 -31
  189. package/src/user/index.ts +0 -1
  190. package/src/user/{user.tsx → user.ts} +123 -82
  191. package/src/utils/render.ts +93 -0
  192. package/src/{whoami.tsx → whoami.ts} +37 -71
  193. package/src/worker.ts +30 -1
  194. package/src/yargs-types.ts +22 -5
  195. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  196. package/templates/__tests__/tsconfig.json +8 -0
  197. package/templates/__tests__/tsconfig.tsbuildinfo +1 -0
  198. package/templates/checked-fetch.js +9 -3
  199. package/templates/d1-beta-facade.js +51 -3
  200. package/templates/facade.d.ts +14 -0
  201. package/templates/first-party-worker-module-facade.ts +4 -3
  202. package/templates/format-dev-errors.ts +8 -6
  203. package/templates/gitignore +1 -0
  204. package/templates/init-tests/test-jest-new-worker.js +3 -5
  205. package/templates/init-tests/test-vitest-new-worker.js +3 -5
  206. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  207. package/templates/middleware/loader-modules.ts +2 -2
  208. package/templates/middleware/loader-sw.ts +51 -31
  209. package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
  210. package/templates/new-worker.ts +3 -0
  211. package/templates/pages-dev-pipeline.ts +4 -1
  212. package/templates/pages-shim.ts +4 -1
  213. package/templates/pages-template-plugin.ts +19 -10
  214. package/templates/serve-static-assets.ts +17 -14
  215. package/templates/service-bindings-module-facade.js +1 -0
  216. package/templates/tsconfig-sanity.ts +11 -0
  217. package/templates/tsconfig.init.json +105 -0
  218. package/templates/tsconfig.json +5 -103
  219. package/templates/tsconfig.tsbuildinfo +1 -0
  220. package/wrangler-dist/cli.d.ts +820 -70
  221. package/wrangler-dist/cli.js +68161 -78780
  222. package/wrangler-dist/wasm-sync.wasm +0 -0
  223. package/src/__tests__/api-devregistry.test.js +0 -56
  224. package/src/__tests__/d1.test.ts +0 -74
  225. package/src/__tests__/dialogs.test.tsx +0 -40
  226. package/src/__tests__/helpers/mock-cfetch.ts +0 -333
  227. package/src/__tests__/pages.test.ts +0 -2387
  228. package/src/d1/migrations.tsx +0 -446
  229. package/src/dialogs.tsx +0 -169
  230. package/src/environment-variables.ts +0 -50
  231. package/src/pages/build.tsx +0 -270
  232. package/src/user/env-vars.ts +0 -46
  233. package/templates/experimental-local-cache-stubs.js +0 -27
  234. /package/src/{bundle-reporter.tsx → bundle-reporter.ts} +0 -0
  235. /package/src/dev/{get-local-persistence-path.tsx → get-local-persistence-path.ts} +0 -0
  236. /package/src/pages/{hash.tsx → hash.ts} +0 -0
@@ -1,44 +1,52 @@
1
- import { Buffer } from "node:buffer";
1
+ import { Blob, Buffer } from "node:buffer";
2
2
  import { randomFillSync } from "node:crypto";
3
3
  import * as fs from "node:fs";
4
4
  import * as path from "node:path";
5
5
  import * as TOML from "@iarna/toml";
6
6
  import * as esbuild from "esbuild";
7
+ import { MockedRequest, rest } from "msw";
8
+ import { FormData } from "undici";
7
9
  import {
8
10
  printBundleSize,
9
11
  printOffendingDependencies,
10
12
  } from "../bundle-reporter";
11
13
  import { writeAuthConfigFile } from "../user";
12
14
  import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
13
- import {
14
- createFetchResult,
15
- setMockRawResponse,
16
- setMockResponse,
17
- unsetAllMocks,
18
- unsetSpecialMockFns,
19
- } from "./helpers/mock-cfetch";
15
+ import { mockAuthDomain } from "./helpers/mock-auth-domain";
20
16
  import {
21
17
  mockConsoleMethods,
22
18
  normalizeSlashes,
23
19
  normalizeTempDirs,
24
20
  } from "./helpers/mock-console";
25
- import { mockConfirm } from "./helpers/mock-dialogs";
21
+ import { clearDialogs, mockConfirm } from "./helpers/mock-dialogs";
26
22
  import { mockGetZoneFromHostRequest } from "./helpers/mock-get-zone-from-host";
27
23
  import { useMockIsTTY } from "./helpers/mock-istty";
28
24
  import { mockCollectKnownRoutesRequest } from "./helpers/mock-known-routes";
29
25
  import { mockKeyListRequest } from "./helpers/mock-kv";
30
- import { mockGetMemberships, mockOAuthFlow } from "./helpers/mock-oauth-flow";
26
+ import {
27
+ mockExchangeRefreshTokenForAccessToken,
28
+ mockGetMemberships,
29
+ mockOAuthFlow,
30
+ } from "./helpers/mock-oauth-flow";
31
+ import {
32
+ createFetchResult,
33
+ msw,
34
+ mswSuccessDeployments,
35
+ mswSuccessDeploymentScriptMetadata,
36
+ } from "./helpers/msw";
37
+ import { FileReaderSync } from "./helpers/msw/read-file-sync";
31
38
  import { runInTempDir } from "./helpers/run-in-tmp";
32
39
  import { runWrangler } from "./helpers/run-wrangler";
33
40
  import { writeWorkerSource } from "./helpers/write-worker-source";
34
41
  import writeWranglerToml from "./helpers/write-wrangler-toml";
42
+
35
43
  import type { Config } from "../config";
36
44
  import type { WorkerMetadata } from "../create-worker-upload-form";
37
45
  import type { KVNamespaceInfo } from "../kv/helpers";
38
- import type { CustomDomainChangeset, CustomDomain } from "../publish/publish";
46
+ import type { CustomDomain, CustomDomainChangeset } from "../publish/publish";
39
47
  import type { PutConsumerBody } from "../queues/client";
40
48
  import type { CfWorkerInit } from "../worker";
41
- import type { FormData, File } from "undici";
49
+ import type { ResponseComposition, RestContext, RestRequest } from "msw";
42
50
 
43
51
  describe("publish", () => {
44
52
  mockAccountId();
@@ -49,7 +57,7 @@ describe("publish", () => {
49
57
  const {
50
58
  mockOAuthServerCallback,
51
59
  mockGrantAccessToken,
52
- mockGrantAuthorization,
60
+ mockDomainUsesAccess,
53
61
  } = mockOAuthFlow();
54
62
 
55
63
  beforeEach(() => {
@@ -58,28 +66,15 @@ describe("publish", () => {
58
66
  setImmediate(fn);
59
67
  });
60
68
  setIsTTY(true);
61
- setMockResponse(
62
- "/accounts/:accountId/workers/services/:scriptName",
63
- () => ({
64
- default_environment: { script: { last_deployed_from: "dash" } },
65
- })
66
- );
67
- setMockResponse(
68
- "/accounts/:accountId/workers/deployments/by-script/:scriptTag",
69
- () => ({
70
- latest: { number: "2" },
71
- })
72
- );
69
+ mockLastDeploymentRequest();
70
+ mockDeploymentsListRequest();
73
71
  });
74
72
 
75
73
  afterEach(() => {
76
- unsetAllMocks();
77
- unsetSpecialMockFns();
74
+ clearDialogs();
78
75
  });
79
76
 
80
77
  describe("output additional script information", () => {
81
- mockApiToken();
82
-
83
78
  it("for first party workers, it should print worker information at log level", async () => {
84
79
  setIsTTY(false);
85
80
  fs.writeFileSync(
@@ -94,26 +89,33 @@ describe("publish", () => {
94
89
  );
95
90
  writeWorkerSource();
96
91
  mockSubDomainRequest();
97
- mockUploadWorkerRequest({ expectedType: "esm", sendScriptIds: true });
92
+ mockUploadWorkerRequest({ expectedType: "esm" });
98
93
  mockOAuthServerCallback();
99
94
 
100
95
  await runWrangler("publish ./index");
101
96
 
102
- expect(std.out).toMatchInlineSnapshot(`
103
- "Total Upload: xx KiB / gzip: xx KiB
97
+ expect(std).toMatchInlineSnapshot(`
98
+ Object {
99
+ "debug": "",
100
+ "err": "",
101
+ "info": "",
102
+ "out": "Total Upload: xx KiB / gzip: xx KiB
104
103
  Worker ID: abc12345
105
104
  Worker ETag: etag98765
106
105
  Worker PipelineHash: hash9999
107
106
  Uploaded test-name (TIMINGS)
108
107
  Published test-name (TIMINGS)
109
108
  https://test-name.test-sub-domain.workers.dev
110
- Current Deployment ID: undefined"
109
+ Current Deployment ID: Galaxy-Class",
110
+ "warn": "",
111
+ }
111
112
  `);
112
113
  });
113
114
  });
114
115
 
115
116
  describe("authentication", () => {
116
117
  mockApiToken({ apiToken: null });
118
+
117
119
  beforeEach(() => {
118
120
  // @ts-expect-error disable the mock we'd setup earlier
119
121
  // or else our server won't bother listening for oauth requests
@@ -122,34 +124,73 @@ describe("publish", () => {
122
124
  });
123
125
 
124
126
  it("drops a user into the login flow if they're unauthenticated", async () => {
127
+ setIsTTY(true);
125
128
  writeWranglerToml();
126
129
  writeWorkerSource();
130
+ mockDomainUsesAccess({ usesAccess: false });
127
131
  mockSubDomainRequest();
128
132
  mockUploadWorkerRequest();
129
- mockOAuthServerCallback();
130
- const accessTokenRequest = mockGrantAccessToken({ respondWith: "ok" });
131
- mockGrantAuthorization({ respondWith: "success" });
133
+ mockExchangeRefreshTokenForAccessToken({ respondWith: "refreshSuccess" });
134
+ mockOAuthServerCallback("success");
135
+ mockDeploymentsListRequest();
132
136
 
133
137
  await expect(runWrangler("publish index.js")).resolves.toBeUndefined();
134
138
 
135
- expect(accessTokenRequest.actual.url).toEqual(
136
- accessTokenRequest.expected.url
137
- );
138
-
139
139
  expect(std.out).toMatchInlineSnapshot(`
140
140
  "Attempting to login via OAuth...
141
- 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
141
+ 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%20ssl_certs%3Awrite%20offline_access&state=MOCK_STATE_PARAM&code_challenge=MOCK_CODE_CHALLENGE&code_challenge_method=S256
142
142
  Successfully logged in.
143
143
  Total Upload: xx KiB / gzip: xx KiB
144
144
  Uploaded test-name (TIMINGS)
145
145
  Published test-name (TIMINGS)
146
146
  https://test-name.test-sub-domain.workers.dev
147
- Current Deployment ID: undefined"
147
+ Current Deployment ID: Galaxy-Class"
148
148
  `);
149
149
  expect(std.warn).toMatchInlineSnapshot(`""`);
150
150
  expect(std.err).toMatchInlineSnapshot(`""`);
151
151
  });
152
152
 
153
+ describe("with an alternative auth domain", () => {
154
+ mockAuthDomain({ domain: "dash.staging.cloudflare.com" });
155
+
156
+ it("drops a user into the login flow if they're unauthenticated", async () => {
157
+ writeWranglerToml();
158
+ writeWorkerSource();
159
+ mockDomainUsesAccess({
160
+ usesAccess: false,
161
+ domain: "dash.staging.cloudflare.com",
162
+ });
163
+ mockSubDomainRequest();
164
+ mockUploadWorkerRequest();
165
+ mockExchangeRefreshTokenForAccessToken({
166
+ respondWith: "refreshSuccess",
167
+ });
168
+ const accessTokenRequest = mockGrantAccessToken({
169
+ respondWith: "ok",
170
+ domain: "dash.staging.cloudflare.com",
171
+ });
172
+ mockOAuthServerCallback("success");
173
+ mockDeploymentsListRequest();
174
+
175
+ await expect(runWrangler("publish index.js")).resolves.toBeUndefined();
176
+
177
+ expect(accessTokenRequest.actual).toEqual(accessTokenRequest.expected);
178
+
179
+ expect(std.out).toMatchInlineSnapshot(`
180
+ "Attempting to login via OAuth...
181
+ 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%20ssl_certs%3Awrite%20offline_access&state=MOCK_STATE_PARAM&code_challenge=MOCK_CODE_CHALLENGE&code_challenge_method=S256
182
+ Successfully logged in.
183
+ Total Upload: xx KiB / gzip: xx KiB
184
+ Uploaded test-name (TIMINGS)
185
+ Published test-name (TIMINGS)
186
+ https://test-name.test-sub-domain.workers.dev
187
+ Current Deployment ID: Galaxy-Class"
188
+ `);
189
+ expect(std.warn).toMatchInlineSnapshot(`""`);
190
+ expect(std.err).toMatchInlineSnapshot(`""`);
191
+ });
192
+ });
193
+
153
194
  it("warns a user when they're authenticated with an API token in wrangler config file", async () => {
154
195
  writeWranglerToml();
155
196
  writeWorkerSource();
@@ -166,10 +207,10 @@ describe("publish", () => {
166
207
  Uploaded test-name (TIMINGS)
167
208
  Published test-name (TIMINGS)
168
209
  https://test-name.test-sub-domain.workers.dev
169
- Current Deployment ID: undefined"
210
+ Current Deployment ID: Galaxy-Class"
170
211
  `);
171
212
  expect(std.warn).toMatchInlineSnapshot(`
172
- "▲ [WARNING] It looks like you have used Wrangler 1's \`config\` command to login with an API token.
213
+ "▲ [WARNING] It looks like you have used Wrangler v1's \`config\` command to login with an API token.
173
214
 
174
215
  This is no longer supported in the current version of Wrangler.
175
216
  If you wish to authenticate via an API token then please set the \`CLOUDFLARE_API_TOKEN\`
@@ -207,7 +248,7 @@ describe("publish", () => {
207
248
  Uploaded test-name (TIMINGS)
208
249
  Published test-name (TIMINGS)
209
250
  https://test-name.test-sub-domain.workers.dev
210
- Current Deployment ID: undefined"
251
+ Current Deployment ID: Galaxy-Class"
211
252
  `);
212
253
  expect(std.err).toMatchInlineSnapshot(`""`);
213
254
  });
@@ -232,7 +273,7 @@ describe("publish", () => {
232
273
  Uploaded test-name (TIMINGS)
233
274
  Published test-name (TIMINGS)
234
275
  https://test-name.test-sub-domain.workers.dev
235
- Current Deployment ID: undefined"
276
+ Current Deployment ID: Galaxy-Class"
236
277
  `);
237
278
  expect(std.err).toMatchInlineSnapshot(`""`);
238
279
  });
@@ -257,12 +298,12 @@ describe("publish", () => {
257
298
 
258
299
  await expect(runWrangler("publish index.js")).rejects
259
300
  .toMatchInlineSnapshot(`
260
- [Error: More than one account available but unable to select one in non-interactive mode.
261
- Please set the appropriate \`account_id\` in your \`wrangler.toml\` file.
262
- Available accounts are ("<name>" - "<id>"):
263
- "enterprise" - "1701")
264
- "enterprise-nx" - "nx01")]
265
- `);
301
+ [Error: More than one account available but unable to select one in non-interactive mode.
302
+ Please set the appropriate \`account_id\` in your \`wrangler.toml\` file.
303
+ Available accounts are (\`<name>\`: \`<account_id>\`):
304
+ \`enterprise\`: \`1701\`
305
+ \`enterprise-nx\`: \`nx01\`]
306
+ `);
266
307
  });
267
308
 
268
309
  it("should throw error in non-TTY if 'CLOUDFLARE_API_TOKEN' is missing", async () => {
@@ -286,7 +327,7 @@ describe("publish", () => {
286
327
  await expect(runWrangler("publish index.js")).rejects.toThrowError();
287
328
 
288
329
  expect(std.err).toMatchInlineSnapshot(`
289
- "X [ERROR] In a non-interactive environment, it's necessary to set a CLOUDFLARE_API_TOKEN environment variable for wrangler to work. Please go to https://developers.cloudflare.com/api/tokens/create/ for instructions on how to create an api token, and assign its value to CLOUDFLARE_API_TOKEN.
330
+ "X [ERROR] In a non-interactive environment, it's necessary to set a CLOUDFLARE_API_TOKEN environment variable for wrangler to work. Please go to https://developers.cloudflare.com/fundamentals/api/get-started/create-token/ for instructions on how to create an api token, and assign its value to CLOUDFLARE_API_TOKEN.
290
331
 
291
332
  "
292
333
  `);
@@ -329,13 +370,14 @@ describe("publish", () => {
329
370
  env: "some-env",
330
371
  legacyEnv: true,
331
372
  });
373
+
332
374
  await runWrangler("publish index.js --env some-env");
333
375
  expect(std.out).toMatchInlineSnapshot(`
334
376
  "Total Upload: xx KiB / gzip: xx KiB
335
377
  Uploaded test-name-some-env (TIMINGS)
336
378
  Published test-name-some-env (TIMINGS)
337
379
  https://test-name-some-env.test-sub-domain.workers.dev
338
- Current Deployment ID: undefined"
380
+ Current Deployment ID: Galaxy-Class"
339
381
  `);
340
382
  expect(std.err).toMatchInlineSnapshot(`""`);
341
383
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -349,13 +391,14 @@ describe("publish", () => {
349
391
  mockUploadWorkerRequest({
350
392
  legacyEnv: true,
351
393
  });
394
+
352
395
  await runWrangler("publish index.js --legacy-env true");
353
396
  expect(std.out).toMatchInlineSnapshot(`
354
397
  "Total Upload: xx KiB / gzip: xx KiB
355
398
  Uploaded test-name (TIMINGS)
356
399
  Published test-name (TIMINGS)
357
400
  https://test-name.test-sub-domain.workers.dev
358
- Current Deployment ID: undefined"
401
+ Current Deployment ID: Galaxy-Class"
359
402
  `);
360
403
  expect(std.err).toMatchInlineSnapshot(`""`);
361
404
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -369,13 +412,14 @@ describe("publish", () => {
369
412
  env: "some-env",
370
413
  legacyEnv: true,
371
414
  });
415
+
372
416
  await runWrangler("publish index.js --env some-env --legacy-env true");
373
417
  expect(std.out).toMatchInlineSnapshot(`
374
418
  "Total Upload: xx KiB / gzip: xx KiB
375
419
  Uploaded test-name-some-env (TIMINGS)
376
420
  Published test-name-some-env (TIMINGS)
377
421
  https://test-name-some-env.test-sub-domain.workers.dev
378
- Current Deployment ID: undefined"
422
+ Current Deployment ID: Galaxy-Class"
379
423
  `);
380
424
  expect(std.err).toMatchInlineSnapshot(`""`);
381
425
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -389,13 +433,14 @@ describe("publish", () => {
389
433
  env: "some-env",
390
434
  legacyEnv: true,
391
435
  });
436
+
392
437
  await runWrangler("publish index.js --env some-env --legacy-env true");
393
438
  expect(std.out).toMatchInlineSnapshot(`
394
439
  "Total Upload: xx KiB / gzip: xx KiB
395
440
  Uploaded test-name-some-env (TIMINGS)
396
441
  Published test-name-some-env (TIMINGS)
397
442
  https://test-name-some-env.test-sub-domain.workers.dev
398
- Current Deployment ID: undefined"
443
+ Current Deployment ID: Galaxy-Class"
399
444
  `);
400
445
  expect(std.err).toMatchInlineSnapshot(`""`);
401
446
  expect(std.warn).toMatchInlineSnapshot(`
@@ -460,13 +505,14 @@ describe("publish", () => {
460
505
  mockUploadWorkerRequest({
461
506
  legacyEnv: false,
462
507
  });
508
+
463
509
  await runWrangler("publish index.js --legacy-env false");
464
510
  expect(std.out).toMatchInlineSnapshot(`
465
511
  "Total Upload: xx KiB / gzip: xx KiB
466
512
  Uploaded test-name (TIMINGS)
467
513
  Published test-name (TIMINGS)
468
514
  https://test-name.test-sub-domain.workers.dev
469
- Current Deployment ID: undefined"
515
+ Current Deployment ID: Galaxy-Class"
470
516
  `);
471
517
  expect(std.err).toMatchInlineSnapshot(`""`);
472
518
  expect(std.warn).toMatchInlineSnapshot(`
@@ -487,13 +533,14 @@ describe("publish", () => {
487
533
  env: "some-env",
488
534
  legacyEnv: false,
489
535
  });
536
+
490
537
  await runWrangler("publish index.js --env some-env --legacy-env false");
491
538
  expect(std.out).toMatchInlineSnapshot(`
492
539
  "Total Upload: xx KiB / gzip: xx KiB
493
540
  Uploaded test-name (some-env) (TIMINGS)
494
541
  Published test-name (some-env) (TIMINGS)
495
542
  https://some-env.test-name.test-sub-domain.workers.dev
496
- Current Deployment ID: undefined"
543
+ Current Deployment ID: Galaxy-Class"
497
544
  `);
498
545
  expect(std.err).toMatchInlineSnapshot(`""`);
499
546
  expect(std.warn).toMatchInlineSnapshot(`
@@ -540,7 +587,7 @@ describe("publish", () => {
540
587
  Uploaded test-name (TIMINGS)
541
588
  Published test-name (TIMINGS)
542
589
  https://test-name.test-sub-domain.workers.dev
543
- Current Deployment ID: undefined"
590
+ Current Deployment ID: Galaxy-Class"
544
591
  `);
545
592
  expect(std.err).toMatchInlineSnapshot(`""`);
546
593
  });
@@ -571,11 +618,12 @@ describe("publish", () => {
571
618
  Object {
572
619
  "debug": "",
573
620
  "err": "",
621
+ "info": "",
574
622
  "out": "Total Upload: xx KiB / gzip: xx KiB
575
623
  Uploaded test-name (TIMINGS)
576
624
  Published test-name (TIMINGS)
577
625
  https://test-name.test-sub-domain.workers.dev
578
- Current Deployment ID: undefined",
626
+ Current Deployment ID: Galaxy-Class",
579
627
  "warn": "▲ [WARNING] Processing wrangler.toml configuration:
580
628
 
581
629
  - The \\"route\\" field in your configuration is an empty string and will be ignored.
@@ -618,6 +666,7 @@ describe("publish", () => {
618
666
  Object {
619
667
  "debug": "",
620
668
  "err": "",
669
+ "info": "",
621
670
  "out": "Total Upload: xx KiB / gzip: xx KiB
622
671
  Uploaded test-name (TIMINGS)
623
672
  Published test-name (TIMINGS)
@@ -626,7 +675,7 @@ describe("publish", () => {
626
675
  *another-boring-website.com (zone name: some-zone.com)
627
676
  example.com/some-route/* (zone id: JGHFHG654gjcj)
628
677
  more-examples.com/*
629
- Current Deployment ID: undefined",
678
+ Current Deployment ID: Galaxy-Class",
630
679
  "warn": "",
631
680
  }
632
681
  `);
@@ -680,6 +729,7 @@ describe("publish", () => {
680
729
  Object {
681
730
  "debug": "",
682
731
  "err": "",
732
+ "info": "",
683
733
  "out": "Total Upload: xx KiB / gzip: xx KiB
684
734
  Uploaded test-name (staging) (TIMINGS)
685
735
  Published test-name (staging) (TIMINGS)
@@ -688,7 +738,7 @@ describe("publish", () => {
688
738
  *another-boring-website.com (zone name: some-zone.com)
689
739
  example.com/some-route/* (zone id: JGHFHG654gjcj)
690
740
  more-examples.com/*
691
- Current Deployment ID: undefined",
741
+ Current Deployment ID: Galaxy-Class",
692
742
  "warn": "▲ [WARNING] Processing wrangler.toml configuration:
693
743
 
694
744
  - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in
@@ -745,7 +795,7 @@ describe("publish", () => {
745
795
  await runWrangler("publish ./index --env dev --legacy-env false");
746
796
  });
747
797
 
748
- it("should fallback to the Wrangler 1 zone-based API if the bulk-routes API fails", async () => {
798
+ it("should fallback to the Wrangler v1 zone-based API if the bulk-routes API fails", async () => {
749
799
  writeWranglerToml({
750
800
  routes: ["example.com/some-route/*"],
751
801
  });
@@ -770,28 +820,28 @@ describe("publish", () => {
770
820
 
771
821
  expect(std.err).toMatchInlineSnapshot(`""`);
772
822
  expect(std.warn).toMatchInlineSnapshot(`
773
- "▲ [WARNING] The current authentication token does not have 'All Zones' permissions.
823
+ "▲ [WARNING] The current authentication token does not have 'All Zones' permissions.
774
824
 
775
- Falling back to using the zone-based API endpoint to update each route individually.
776
- Note that there is no access to routes associated with zones that the API token does not have
777
- permission for.
778
- Existing routes for this Worker in such zones will not be deleted.
825
+ Falling back to using the zone-based API endpoint to update each route individually.
826
+ Note that there is no access to routes associated with zones that the API token does not have
827
+ permission for.
828
+ Existing routes for this Worker in such zones will not be deleted.
779
829
 
780
830
 
781
- ▲ [WARNING] Previously deployed routes:
831
+ ▲ [WARNING] Previously deployed routes:
782
832
 
783
- The following routes were already associated with this worker, and have not been deleted:
784
- - \\"foo.example.com/other-route\\"
785
- If these routes are not wanted then you can remove them in the dashboard.
833
+ The following routes were already associated with this worker, and have not been deleted:
834
+ - \\"foo.example.com/other-route\\"
835
+ If these routes are not wanted then you can remove them in the dashboard.
786
836
 
787
- "
788
- `);
837
+ "
838
+ `);
789
839
  expect(std.out).toMatchInlineSnapshot(`
790
840
  "Total Upload: xx KiB / gzip: xx KiB
791
841
  Uploaded test-name (TIMINGS)
792
842
  Published test-name (TIMINGS)
793
843
  example.com/some-route/*
794
- Current Deployment ID: undefined"
844
+ Current Deployment ID: Galaxy-Class"
795
845
  `);
796
846
  });
797
847
 
@@ -1072,7 +1122,7 @@ Update them to point to this script instead?`,
1072
1122
  Uploaded test-name (TIMINGS)
1073
1123
  Published test-name (TIMINGS)
1074
1124
  https://test-name.test-sub-domain.workers.dev
1075
- Current Deployment ID: undefined"
1125
+ Current Deployment ID: Galaxy-Class"
1076
1126
  `);
1077
1127
  expect(std.err).toMatchInlineSnapshot(`""`);
1078
1128
  });
@@ -1090,7 +1140,7 @@ Update them to point to this script instead?`,
1090
1140
  Uploaded test-name (TIMINGS)
1091
1141
  Published test-name (TIMINGS)
1092
1142
  https://test-name.test-sub-domain.workers.dev
1093
- Current Deployment ID: undefined"
1143
+ Current Deployment ID: Galaxy-Class"
1094
1144
  `);
1095
1145
  expect(std.err).toMatchInlineSnapshot(`""`);
1096
1146
  });
@@ -1108,7 +1158,7 @@ Update them to point to this script instead?`,
1108
1158
  Uploaded test-name (TIMINGS)
1109
1159
  Published test-name (TIMINGS)
1110
1160
  https://test-name.test-sub-domain.workers.dev
1111
- Current Deployment ID: undefined"
1161
+ Current Deployment ID: Galaxy-Class"
1112
1162
  `);
1113
1163
  expect(std.err).toMatchInlineSnapshot(`""`);
1114
1164
  });
@@ -1128,7 +1178,7 @@ Update them to point to this script instead?`,
1128
1178
  Uploaded test-name (TIMINGS)
1129
1179
  Published test-name (TIMINGS)
1130
1180
  https://test-name.test-sub-domain.workers.dev
1131
- Current Deployment ID: undefined"
1181
+ Current Deployment ID: Galaxy-Class"
1132
1182
  `);
1133
1183
  expect(std.err).toMatchInlineSnapshot(`""`);
1134
1184
  });
@@ -1146,21 +1196,21 @@ Update them to point to this script instead?`,
1146
1196
  Uploaded test-name (TIMINGS)
1147
1197
  Published test-name (TIMINGS)
1148
1198
  https://test-name.test-sub-domain.workers.dev
1149
- Current Deployment ID: undefined"
1199
+ Current Deployment ID: Galaxy-Class"
1150
1200
  `);
1151
1201
  expect(std.err).toMatchInlineSnapshot(`""`);
1152
1202
  expect(std.warn).toMatchInlineSnapshot(`
1153
- "▲ [WARNING] Processing wrangler.toml configuration:
1203
+ "▲ [WARNING] Processing wrangler.toml configuration:
1154
1204
 
1155
- - Deprecation: \\"build.upload.main\\":
1156
- Delete the \`build.upload.main\` and \`build.upload.dir\` fields.
1157
- Then add the top level \`main\` field to your configuration file:
1158
- \`\`\`
1159
- main = \\"dist/index.js\\"
1160
- \`\`\`
1205
+ - Deprecation: \\"build.upload.main\\":
1206
+ Delete the \`build.upload.main\` and \`build.upload.dir\` fields.
1207
+ Then add the top level \`main\` field to your configuration file:
1208
+ \`\`\`
1209
+ main = \\"dist/index.js\\"
1210
+ \`\`\`
1161
1211
 
1162
- "
1163
- `);
1212
+ "
1213
+ `);
1164
1214
  });
1165
1215
 
1166
1216
  it("should use `build.upload.main` relative to `build.upload.dir`", async () => {
@@ -1183,24 +1233,24 @@ Update them to point to this script instead?`,
1183
1233
  Uploaded test-name (TIMINGS)
1184
1234
  Published test-name (TIMINGS)
1185
1235
  https://test-name.test-sub-domain.workers.dev
1186
- Current Deployment ID: undefined"
1236
+ Current Deployment ID: Galaxy-Class"
1187
1237
  `);
1188
1238
  expect(std.err).toMatchInlineSnapshot(`""`);
1189
1239
  expect(std.warn).toMatchInlineSnapshot(`
1190
- "▲ [WARNING] Processing ../wrangler.toml configuration:
1240
+ "▲ [WARNING] Processing ../wrangler.toml configuration:
1191
1241
 
1192
- - Deprecation: \\"build.upload.main\\":
1193
- Delete the \`build.upload.main\` and \`build.upload.dir\` fields.
1194
- Then add the top level \`main\` field to your configuration file:
1195
- \`\`\`
1196
- main = \\"foo/index.js\\"
1197
- \`\`\`
1198
- - Deprecation: \\"build.upload.dir\\":
1199
- Use the top level \\"main\\" field or a command-line argument to specify the entry-point for the
1200
- Worker.
1242
+ - Deprecation: \\"build.upload.main\\":
1243
+ Delete the \`build.upload.main\` and \`build.upload.dir\` fields.
1244
+ Then add the top level \`main\` field to your configuration file:
1245
+ \`\`\`
1246
+ main = \\"foo/index.js\\"
1247
+ \`\`\`
1248
+ - Deprecation: \\"build.upload.dir\\":
1249
+ Use the top level \\"main\\" field or a command-line argument to specify the entry-point for the
1250
+ Worker.
1201
1251
 
1202
- "
1203
- `);
1252
+ "
1253
+ `);
1204
1254
  });
1205
1255
 
1206
1256
  it("should error when both `main` and `build.upload.main` are used", async () => {
@@ -1234,7 +1284,7 @@ Update them to point to this script instead?`,
1234
1284
  Uploaded test-name (TIMINGS)
1235
1285
  Published test-name (TIMINGS)
1236
1286
  https://test-name.test-sub-domain.workers.dev
1237
- Current Deployment ID: undefined"
1287
+ Current Deployment ID: Galaxy-Class"
1238
1288
  `);
1239
1289
  expect(std.err).toMatchInlineSnapshot(`""`);
1240
1290
  });
@@ -1254,7 +1304,7 @@ Update them to point to this script instead?`,
1254
1304
  Uploaded test-name (TIMINGS)
1255
1305
  Published test-name (TIMINGS)
1256
1306
  https://test-name.test-sub-domain.workers.dev
1257
- Current Deployment ID: undefined"
1307
+ Current Deployment ID: Galaxy-Class"
1258
1308
  `);
1259
1309
  expect(std.err).toMatchInlineSnapshot(`""`);
1260
1310
  });
@@ -1286,7 +1336,33 @@ export default{
1286
1336
  Uploaded test-name (TIMINGS)
1287
1337
  Published test-name (TIMINGS)
1288
1338
  https://test-name.test-sub-domain.workers.dev
1289
- Current Deployment ID: undefined"
1339
+ Current Deployment ID: Galaxy-Class"
1340
+ `);
1341
+ expect(std.err).toMatchInlineSnapshot(`""`);
1342
+ });
1343
+
1344
+ it("should allow cloudflare module import", async () => {
1345
+ writeWranglerToml();
1346
+ fs.writeFileSync(
1347
+ "./index.js",
1348
+ `
1349
+ import { EmailMessage } from "cloudflare:email";
1350
+ export default{
1351
+ fetch(){
1352
+ return new Response("all done");
1353
+ }
1354
+ }
1355
+ `
1356
+ );
1357
+ mockUploadWorkerRequest();
1358
+ mockSubDomainRequest();
1359
+ await runWrangler("publish index.js");
1360
+ expect(std.out).toMatchInlineSnapshot(`
1361
+ "Total Upload: xx KiB / gzip: xx KiB
1362
+ Uploaded test-name (TIMINGS)
1363
+ Published test-name (TIMINGS)
1364
+ https://test-name.test-sub-domain.workers.dev
1365
+ Current Deployment ID: Galaxy-Class"
1290
1366
  `);
1291
1367
  expect(std.err).toMatchInlineSnapshot(`""`);
1292
1368
  });
@@ -1304,7 +1380,7 @@ export default{
1304
1380
  Uploaded test-name (TIMINGS)
1305
1381
  Published test-name (TIMINGS)
1306
1382
  https://test-name.test-sub-domain.workers.dev
1307
- Current Deployment ID: undefined"
1383
+ Current Deployment ID: Galaxy-Class"
1308
1384
  `);
1309
1385
  expect(std.err).toMatchInlineSnapshot(`""`);
1310
1386
  });
@@ -1341,6 +1417,7 @@ export default {};`
1341
1417
  Object {
1342
1418
  "debug": "",
1343
1419
  "err": "",
1420
+ "info": "",
1344
1421
  "out": "Total Upload: xx KiB / gzip: xx KiB
1345
1422
  --dry-run: exiting now.",
1346
1423
  "warn": "",
@@ -1374,6 +1451,7 @@ addEventListener('fetch', event => {});`
1374
1451
  Object {
1375
1452
  "debug": "",
1376
1453
  "err": "",
1454
+ "info": "",
1377
1455
  "out": "Total Upload: xx KiB / gzip: xx KiB
1378
1456
  --dry-run: exiting now.",
1379
1457
  "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...
@@ -1399,7 +1477,7 @@ addEventListener('fetch', event => {});`
1399
1477
  Uploaded test-name (TIMINGS)
1400
1478
  Published test-name (TIMINGS)
1401
1479
  https://test-name.test-sub-domain.workers.dev
1402
- Current Deployment ID: undefined"
1480
+ Current Deployment ID: Galaxy-Class"
1403
1481
  `);
1404
1482
  expect(std.err).toMatchInlineSnapshot(`""`);
1405
1483
  });
@@ -1421,7 +1499,7 @@ addEventListener('fetch', event => {});`
1421
1499
 
1422
1500
  expect(std.out).toMatchInlineSnapshot(`
1423
1501
  "
1424
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
1502
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
1425
1503
  `);
1426
1504
  expect(std.err).toMatchInlineSnapshot(`
1427
1505
  "X [ERROR] Processing wrangler.toml configuration:
@@ -1473,6 +1551,7 @@ addEventListener('fetch', event => {});`
1473
1551
  Object {
1474
1552
  "debug": "",
1475
1553
  "err": "",
1554
+ "info": "",
1476
1555
  "out": "Reading file-1.txt...
1477
1556
  Uploading as file-1.2ca234f380.txt...
1478
1557
  Reading file-2.txt...
@@ -1482,7 +1561,7 @@ addEventListener('fetch', event => {});`
1482
1561
  Uploaded test-name (TIMINGS)
1483
1562
  Published test-name (TIMINGS)
1484
1563
  https://test-name.test-sub-domain.workers.dev
1485
- Current Deployment ID: undefined",
1564
+ Current Deployment ID: Galaxy-Class",
1486
1565
  "warn": "▲ [WARNING] Processing wrangler.toml configuration:
1487
1566
 
1488
1567
  - Deprecation: \\"site.entry-point\\":
@@ -1535,21 +1614,21 @@ addEventListener('fetch', event => {});`
1535
1614
  Uploaded test-name (TIMINGS)
1536
1615
  Published test-name (TIMINGS)
1537
1616
  https://test-name.test-sub-domain.workers.dev
1538
- Current Deployment ID: undefined"
1617
+ Current Deployment ID: Galaxy-Class"
1539
1618
  `);
1540
1619
  expect(std.err).toMatchInlineSnapshot(`""`);
1541
1620
  expect(normalizeSlashes(std.warn)).toMatchInlineSnapshot(`
1542
- "▲ [WARNING] Processing my-site/wrangler.toml configuration:
1621
+ "▲ [WARNING] Processing my-site/wrangler.toml configuration:
1543
1622
 
1544
- - Deprecation: \\"site.entry-point\\":
1545
- Delete the \`site.entry-point\` field, then add the top level \`main\` field to your configuration
1546
- file:
1547
- \`\`\`
1548
- main = \\"my-entry/index.js\\"
1549
- \`\`\`
1623
+ - Deprecation: \\"site.entry-point\\":
1624
+ Delete the \`site.entry-point\` field, then add the top level \`main\` field to your configuration
1625
+ file:
1626
+ \`\`\`
1627
+ main = \\"my-entry/index.js\\"
1628
+ \`\`\`
1550
1629
 
1551
- "
1552
- `);
1630
+ "
1631
+ `);
1553
1632
  });
1554
1633
 
1555
1634
  it("should error if both main and site.entry-point are specified", async () => {
@@ -1583,7 +1662,7 @@ addEventListener('fetch', event => {});`
1583
1662
 
1584
1663
  expect(std.out).toMatchInlineSnapshot(`
1585
1664
  "
1586
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
1665
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
1587
1666
  `);
1588
1667
  expect(std.err).toMatchInlineSnapshot(`
1589
1668
  "X [ERROR] Missing entry-point: The entry-point should be specified via the command line (e.g. \`wrangler publish path/to/script\`) or the \`main\` config field.
@@ -1603,7 +1682,7 @@ addEventListener('fetch', event => {});`
1603
1682
  };
1604
1683
  writeAssets(assets);
1605
1684
  mockUploadWorkerRequest({
1606
- expectedMainModule: "serve-static-assets.entry.js",
1685
+ expectedMainModule: "no-op-worker.js",
1607
1686
  });
1608
1687
  mockSubDomainRequest();
1609
1688
  mockListKVNamespacesRequest(kvNamespace);
@@ -1616,6 +1695,7 @@ addEventListener('fetch', event => {});`
1616
1695
  Object {
1617
1696
  "debug": "",
1618
1697
  "err": "",
1698
+ "info": "",
1619
1699
  "out": "Reading file-1.txt...
1620
1700
  Uploading as file-1.2ca234f380.txt...
1621
1701
  Reading file-2.txt...
@@ -1625,7 +1705,7 @@ addEventListener('fetch', event => {});`
1625
1705
  Uploaded test-name (TIMINGS)
1626
1706
  Published test-name (TIMINGS)
1627
1707
  https://test-name.test-sub-domain.workers.dev
1628
- Current Deployment ID: undefined",
1708
+ Current Deployment ID: Galaxy-Class",
1629
1709
  "warn": "▲ [WARNING] The --assets argument is experimental and may change or break at any time
1630
1710
 
1631
1711
 
@@ -1674,7 +1754,7 @@ addEventListener('fetch', event => {});`
1674
1754
  Uploaded test-name (TIMINGS)
1675
1755
  Published test-name (TIMINGS)
1676
1756
  https://test-name.test-sub-domain.workers.dev
1677
- Current Deployment ID: undefined"
1757
+ Current Deployment ID: Galaxy-Class"
1678
1758
  `);
1679
1759
  expect(std.err).toMatchInlineSnapshot(`""`);
1680
1760
  });
@@ -1694,7 +1774,7 @@ addEventListener('fetch', event => {});`
1694
1774
  writeWorkerSource();
1695
1775
  writeAssets(assets);
1696
1776
  mockUploadWorkerRequest({
1697
- expectedMainModule: "serve-static-assets.entry.js",
1777
+ expectedMainModule: "index.js",
1698
1778
  });
1699
1779
  mockSubDomainRequest();
1700
1780
  mockListKVNamespacesRequest(kvNamespace);
@@ -1706,6 +1786,7 @@ addEventListener('fetch', event => {});`
1706
1786
  Object {
1707
1787
  "debug": "",
1708
1788
  "err": "",
1789
+ "info": "",
1709
1790
  "out": "Reading file-1.txt...
1710
1791
  Uploading as file-1.2ca234f380.txt...
1711
1792
  Reading file-2.txt...
@@ -1715,7 +1796,7 @@ addEventListener('fetch', event => {});`
1715
1796
  Uploaded test-name (TIMINGS)
1716
1797
  Published test-name (TIMINGS)
1717
1798
  https://test-name.test-sub-domain.workers.dev
1718
- Current Deployment ID: undefined",
1799
+ Current Deployment ID: Galaxy-Class",
1719
1800
  "warn": "▲ [WARNING] The --assets argument is experimental and may change or break at any time
1720
1801
 
1721
1802
  ",
@@ -1735,18 +1816,19 @@ addEventListener('fetch', event => {});`
1735
1816
  );
1736
1817
 
1737
1818
  expect(std).toMatchInlineSnapshot(`
1738
- Object {
1739
- "debug": "",
1740
- "err": "X [ERROR] You cannot use the service-worker format with an \`assets\` directory yet. For information on how to migrate to the module-worker format, see: https://developers.cloudflare.com/workers/learning/migrating-to-module-workers/
1819
+ Object {
1820
+ "debug": "",
1821
+ "err": "X [ERROR] You cannot use the service-worker format with an \`assets\` directory yet. For information on how to migrate to the module-worker format, see: https://developers.cloudflare.com/workers/learning/migrating-to-module-workers/
1741
1822
 
1742
- ",
1743
- "out": "
1744
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose",
1745
- "warn": "▲ [WARNING] The --assets argument is experimental and may change or break at any time
1823
+ ",
1824
+ "info": "",
1825
+ "out": "
1826
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose",
1827
+ "warn": "▲ [WARNING] The --assets argument is experimental and may change or break at any time
1746
1828
 
1747
- ",
1748
- }
1749
- `);
1829
+ ",
1830
+ }
1831
+ `);
1750
1832
  });
1751
1833
 
1752
1834
  it("should error if --assets and --site are used together", async () => {
@@ -1761,16 +1843,17 @@ addEventListener('fetch', event => {});`
1761
1843
  );
1762
1844
 
1763
1845
  expect(std).toMatchInlineSnapshot(`
1764
- Object {
1765
- "debug": "",
1766
- "err": "X [ERROR] Cannot use Assets and Workers Sites in the same Worker.
1767
-
1768
- ",
1769
- "out": "
1770
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose",
1771
- "warn": "",
1772
- }
1773
- `);
1846
+ Object {
1847
+ "debug": "",
1848
+ "err": "X [ERROR] Cannot use Assets and Workers Sites in the same Worker.
1849
+
1850
+ ",
1851
+ "info": "",
1852
+ "out": "
1853
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose",
1854
+ "warn": "",
1855
+ }
1856
+ `);
1774
1857
  });
1775
1858
 
1776
1859
  it("should error if --assets and config.site are used together", async () => {
@@ -1788,16 +1871,17 @@ addEventListener('fetch', event => {});`
1788
1871
  );
1789
1872
 
1790
1873
  expect(std).toMatchInlineSnapshot(`
1791
- Object {
1792
- "debug": "",
1793
- "err": "X [ERROR] Cannot use Assets and Workers Sites in the same Worker.
1794
-
1795
- ",
1796
- "out": "
1797
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose",
1798
- "warn": "",
1799
- }
1800
- `);
1874
+ Object {
1875
+ "debug": "",
1876
+ "err": "X [ERROR] Cannot use Assets and Workers Sites in the same Worker.
1877
+
1878
+ ",
1879
+ "info": "",
1880
+ "out": "
1881
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose",
1882
+ "warn": "",
1883
+ }
1884
+ `);
1801
1885
  });
1802
1886
 
1803
1887
  it("should error if config.assets and --site are used together", async () => {
@@ -1814,20 +1898,21 @@ addEventListener('fetch', event => {});`
1814
1898
  );
1815
1899
 
1816
1900
  expect(std).toMatchInlineSnapshot(`
1817
- Object {
1818
- "debug": "",
1819
- "err": "X [ERROR] Cannot use Assets and Workers Sites in the same Worker.
1901
+ Object {
1902
+ "debug": "",
1903
+ "err": "X [ERROR] Cannot use Assets and Workers Sites in the same Worker.
1820
1904
 
1821
- ",
1822
- "out": "
1823
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose",
1824
- "warn": "▲ [WARNING] Processing wrangler.toml configuration:
1905
+ ",
1906
+ "info": "",
1907
+ "out": "
1908
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose",
1909
+ "warn": "▲ [WARNING] Processing wrangler.toml configuration:
1825
1910
 
1826
- - \\"assets\\" fields are experimental and may change or break at any time.
1911
+ - \\"assets\\" fields are experimental and may change or break at any time.
1827
1912
 
1828
- ",
1829
- }
1830
- `);
1913
+ ",
1914
+ }
1915
+ `);
1831
1916
  });
1832
1917
 
1833
1918
  it("should error if config.assets and config.site are used together", async () => {
@@ -1847,20 +1932,21 @@ addEventListener('fetch', event => {});`
1847
1932
  );
1848
1933
 
1849
1934
  expect(std).toMatchInlineSnapshot(`
1850
- Object {
1851
- "debug": "",
1852
- "err": "X [ERROR] Cannot use Assets and Workers Sites in the same Worker.
1935
+ Object {
1936
+ "debug": "",
1937
+ "err": "X [ERROR] Cannot use Assets and Workers Sites in the same Worker.
1853
1938
 
1854
- ",
1855
- "out": "
1856
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose",
1857
- "warn": "▲ [WARNING] Processing wrangler.toml configuration:
1939
+ ",
1940
+ "info": "",
1941
+ "out": "
1942
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose",
1943
+ "warn": "▲ [WARNING] Processing wrangler.toml configuration:
1858
1944
 
1859
- - \\"assets\\" fields are experimental and may change or break at any time.
1945
+ - \\"assets\\" fields are experimental and may change or break at any time.
1860
1946
 
1861
- ",
1862
- }
1863
- `);
1947
+ ",
1948
+ }
1949
+ `);
1864
1950
  });
1865
1951
 
1866
1952
  it("should warn if --assets is used", async () => {
@@ -1879,7 +1965,7 @@ addEventListener('fetch', event => {});`
1879
1965
  writeWorkerSource();
1880
1966
  writeAssets(assets);
1881
1967
  mockUploadWorkerRequest({
1882
- expectedMainModule: "serve-static-assets.entry.js",
1968
+ expectedMainModule: "index.js",
1883
1969
  });
1884
1970
  mockSubDomainRequest();
1885
1971
  mockListKVNamespacesRequest(kvNamespace);
@@ -1891,6 +1977,7 @@ addEventListener('fetch', event => {});`
1891
1977
  Object {
1892
1978
  "debug": "",
1893
1979
  "err": "",
1980
+ "info": "",
1894
1981
  "out": "Reading subdir/file-1.txt...
1895
1982
  Uploading as subdir/file-1.2ca234f380.txt...
1896
1983
  Reading subdir/file-2.txt...
@@ -1900,7 +1987,7 @@ addEventListener('fetch', event => {});`
1900
1987
  Uploaded test-name (TIMINGS)
1901
1988
  Published test-name (TIMINGS)
1902
1989
  https://test-name.test-sub-domain.workers.dev
1903
- Current Deployment ID: undefined",
1990
+ Current Deployment ID: Galaxy-Class",
1904
1991
  "warn": "▲ [WARNING] The --assets argument is experimental and may change or break at any time
1905
1992
 
1906
1993
  ",
@@ -1926,7 +2013,7 @@ addEventListener('fetch', event => {});`
1926
2013
  writeWorkerSource();
1927
2014
  writeAssets(assets);
1928
2015
  mockUploadWorkerRequest({
1929
- expectedMainModule: "serve-static-assets.entry.js",
2016
+ expectedMainModule: "index.js",
1930
2017
  });
1931
2018
  mockSubDomainRequest();
1932
2019
  mockListKVNamespacesRequest(kvNamespace);
@@ -1938,6 +2025,7 @@ addEventListener('fetch', event => {});`
1938
2025
  Object {
1939
2026
  "debug": "",
1940
2027
  "err": "",
2028
+ "info": "",
1941
2029
  "out": "Reading subdir/file-1.txt...
1942
2030
  Uploading as subdir/file-1.2ca234f380.txt...
1943
2031
  Reading subdir/file-2.txt...
@@ -1947,7 +2035,7 @@ addEventListener('fetch', event => {});`
1947
2035
  Uploaded test-name (TIMINGS)
1948
2036
  Published test-name (TIMINGS)
1949
2037
  https://test-name.test-sub-domain.workers.dev
1950
- Current Deployment ID: undefined",
2038
+ Current Deployment ID: Galaxy-Class",
1951
2039
  "warn": "▲ [WARNING] Processing wrangler.toml configuration:
1952
2040
 
1953
2041
  - \\"assets\\" fields are experimental and may change or break at any time.
@@ -2004,7 +2092,7 @@ addEventListener('fetch', event => {});`
2004
2092
  Uploaded test-name (TIMINGS)
2005
2093
  Published test-name (TIMINGS)
2006
2094
  https://test-name.test-sub-domain.workers.dev
2007
- Current Deployment ID: undefined"
2095
+ Current Deployment ID: Galaxy-Class"
2008
2096
  `);
2009
2097
  expect(std.err).toMatchInlineSnapshot(`""`);
2010
2098
  });
@@ -2062,7 +2150,7 @@ addEventListener('fetch', event => {});`
2062
2150
  Uploaded test-name (TIMINGS)
2063
2151
  Published test-name (TIMINGS)
2064
2152
  https://test-name.test-sub-domain.workers.dev
2065
- Current Deployment ID: undefined"
2153
+ Current Deployment ID: Galaxy-Class"
2066
2154
  `);
2067
2155
  expect(std.err).toMatchInlineSnapshot(`""`);
2068
2156
  });
@@ -2114,7 +2202,7 @@ addEventListener('fetch', event => {});`
2114
2202
  Uploaded test-name (TIMINGS)
2115
2203
  Published test-name (TIMINGS)
2116
2204
  https://test-name.test-sub-domain.workers.dev
2117
- Current Deployment ID: undefined"
2205
+ Current Deployment ID: Galaxy-Class"
2118
2206
  `);
2119
2207
  expect(std.err).toMatchInlineSnapshot(`""`);
2120
2208
  });
@@ -2164,7 +2252,7 @@ addEventListener('fetch', event => {});`
2164
2252
  Uploaded test-name (some-env) (TIMINGS)
2165
2253
  Published test-name (some-env) (TIMINGS)
2166
2254
  https://some-env.test-name.test-sub-domain.workers.dev
2167
- Current Deployment ID: undefined"
2255
+ Current Deployment ID: Galaxy-Class"
2168
2256
  `);
2169
2257
  expect(std.err).toMatchInlineSnapshot(`""`);
2170
2258
  });
@@ -2215,7 +2303,7 @@ addEventListener('fetch', event => {});`
2215
2303
  Uploaded test-name-some-env (TIMINGS)
2216
2304
  Published test-name-some-env (TIMINGS)
2217
2305
  https://test-name-some-env.test-sub-domain.workers.dev
2218
- Current Deployment ID: undefined"
2306
+ Current Deployment ID: Galaxy-Class"
2219
2307
  `);
2220
2308
  expect(std.err).toMatchInlineSnapshot(`""`);
2221
2309
  });
@@ -2259,7 +2347,7 @@ addEventListener('fetch', event => {});`
2259
2347
  Uploaded test-name (TIMINGS)
2260
2348
  Published test-name (TIMINGS)
2261
2349
  https://test-name.test-sub-domain.workers.dev
2262
- Current Deployment ID: undefined"
2350
+ Current Deployment ID: Galaxy-Class"
2263
2351
  `);
2264
2352
  expect(std.err).toMatchInlineSnapshot(`""`);
2265
2353
  });
@@ -2300,7 +2388,7 @@ addEventListener('fetch', event => {});`
2300
2388
  Uploaded test-name (TIMINGS)
2301
2389
  Published test-name (TIMINGS)
2302
2390
  https://test-name.test-sub-domain.workers.dev
2303
- Current Deployment ID: undefined"
2391
+ Current Deployment ID: Galaxy-Class"
2304
2392
  `);
2305
2393
  expect(std.err).toMatchInlineSnapshot(`""`);
2306
2394
  });
@@ -2341,7 +2429,7 @@ addEventListener('fetch', event => {});`
2341
2429
  Uploaded test-name (TIMINGS)
2342
2430
  Published test-name (TIMINGS)
2343
2431
  https://test-name.test-sub-domain.workers.dev
2344
- Current Deployment ID: undefined"
2432
+ Current Deployment ID: Galaxy-Class"
2345
2433
  `);
2346
2434
  expect(std.err).toMatchInlineSnapshot(`""`);
2347
2435
  });
@@ -2383,7 +2471,7 @@ addEventListener('fetch', event => {});`
2383
2471
  Uploaded test-name (TIMINGS)
2384
2472
  Published test-name (TIMINGS)
2385
2473
  https://test-name.test-sub-domain.workers.dev
2386
- Current Deployment ID: undefined"
2474
+ Current Deployment ID: Galaxy-Class"
2387
2475
  `);
2388
2476
  expect(std.err).toMatchInlineSnapshot(`""`);
2389
2477
  });
@@ -2425,7 +2513,7 @@ addEventListener('fetch', event => {});`
2425
2513
  Uploaded test-name (TIMINGS)
2426
2514
  Published test-name (TIMINGS)
2427
2515
  https://test-name.test-sub-domain.workers.dev
2428
- Current Deployment ID: undefined"
2516
+ Current Deployment ID: Galaxy-Class"
2429
2517
  `);
2430
2518
  expect(std.err).toMatchInlineSnapshot(`""`);
2431
2519
  });
@@ -2467,7 +2555,7 @@ addEventListener('fetch', event => {});`
2467
2555
  Uploaded test-name (TIMINGS)
2468
2556
  Published test-name (TIMINGS)
2469
2557
  https://test-name.test-sub-domain.workers.dev
2470
- Current Deployment ID: undefined"
2558
+ Current Deployment ID: Galaxy-Class"
2471
2559
  `);
2472
2560
  expect(std.err).toMatchInlineSnapshot(`""`);
2473
2561
  });
@@ -2509,7 +2597,7 @@ addEventListener('fetch', event => {});`
2509
2597
  Uploaded test-name (TIMINGS)
2510
2598
  Published test-name (TIMINGS)
2511
2599
  https://test-name.test-sub-domain.workers.dev
2512
- Current Deployment ID: undefined"
2600
+ Current Deployment ID: Galaxy-Class"
2513
2601
  `);
2514
2602
  expect(std.err).toMatchInlineSnapshot(`""`);
2515
2603
  });
@@ -2553,7 +2641,7 @@ addEventListener('fetch', event => {});`
2553
2641
  Uploaded test-name (TIMINGS)
2554
2642
  Published test-name (TIMINGS)
2555
2643
  https://test-name.test-sub-domain.workers.dev
2556
- Current Deployment ID: undefined"
2644
+ Current Deployment ID: Galaxy-Class"
2557
2645
  `);
2558
2646
  expect(std.err).toMatchInlineSnapshot(`""`);
2559
2647
  });
@@ -2601,7 +2689,7 @@ addEventListener('fetch', event => {});`
2601
2689
  Uploaded test-name (TIMINGS)
2602
2690
  Published test-name (TIMINGS)
2603
2691
  https://test-name.test-sub-domain.workers.dev
2604
- Current Deployment ID: undefined"
2692
+ Current Deployment ID: Galaxy-Class"
2605
2693
  `);
2606
2694
  expect(std.err).toMatchInlineSnapshot(`""`);
2607
2695
  });
@@ -2647,7 +2735,7 @@ addEventListener('fetch', event => {});`
2647
2735
  Uploading as large-file.0ea0637a45.txt...
2648
2736
  Reading too-large-file.txt...
2649
2737
 
2650
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
2738
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
2651
2739
  `);
2652
2740
  expect(std.err).toMatchInlineSnapshot(`
2653
2741
  "X [ERROR] File too-large-file.txt is too big, it should be under 25 MiB. See https://developers.cloudflare.com/workers/platform/limits#kv-limits
@@ -2706,6 +2794,7 @@ addEventListener('fetch', event => {});`
2706
2794
  Object {
2707
2795
  "debug": "",
2708
2796
  "err": "",
2797
+ "info": "",
2709
2798
  "out": "Reading file-00.txt...
2710
2799
  Uploading as file-00.be5be5dd26.txt...
2711
2800
  Reading file-01.txt...
@@ -2751,7 +2840,7 @@ addEventListener('fetch', event => {});`
2751
2840
  Uploaded test-name (TIMINGS)
2752
2841
  Published test-name (TIMINGS)
2753
2842
  https://test-name.test-sub-domain.workers.dev
2754
- Current Deployment ID: undefined",
2843
+ Current Deployment ID: Galaxy-Class",
2755
2844
  "warn": "",
2756
2845
  }
2757
2846
  `);
@@ -2788,7 +2877,7 @@ addEventListener('fetch', event => {});`
2788
2877
  expect(std.out).toMatchInlineSnapshot(`
2789
2878
  "Reading folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/file.txt...
2790
2879
 
2791
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
2880
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
2792
2881
  `);
2793
2882
  expect(std.err).toMatchInlineSnapshot(`
2794
2883
  "X [ERROR] The asset path key \\"folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/file.3da0d0cd12.txt\\" exceeds the maximum key size limit of 512. See https://developers.cloudflare.com/workers/platform/limits#kv-limits\\",
@@ -2851,7 +2940,7 @@ addEventListener('fetch', event => {});`
2851
2940
  Uploaded test-name (TIMINGS)
2852
2941
  Published test-name (TIMINGS)
2853
2942
  https://test-name.test-sub-domain.workers.dev
2854
- Current Deployment ID: undefined"
2943
+ Current Deployment ID: Galaxy-Class"
2855
2944
  `);
2856
2945
  expect(std.err).toMatchInlineSnapshot(`""`);
2857
2946
  });
@@ -2906,7 +2995,7 @@ addEventListener('fetch', event => {});`
2906
2995
  Uploaded test-name (TIMINGS)
2907
2996
  Published test-name (TIMINGS)
2908
2997
  https://test-name.test-sub-domain.workers.dev
2909
- Current Deployment ID: undefined"
2998
+ Current Deployment ID: Galaxy-Class"
2910
2999
  `);
2911
3000
  expect(std.err).toMatchInlineSnapshot(`""`);
2912
3001
  });
@@ -2939,6 +3028,7 @@ addEventListener('fetch', event => {});`
2939
3028
  Object {
2940
3029
  "debug": "",
2941
3030
  "err": "",
3031
+ "info": "",
2942
3032
  "out": "Reading file-1.txt...
2943
3033
  Uploading as file-1.2ca234f380.txt...
2944
3034
  Reading file-2.txt...
@@ -2948,7 +3038,7 @@ addEventListener('fetch', event => {});`
2948
3038
  Uploaded test-name (TIMINGS)
2949
3039
  Published test-name (TIMINGS)
2950
3040
  https://test-name.test-sub-domain.workers.dev
2951
- Current Deployment ID: undefined",
3041
+ Current Deployment ID: Galaxy-Class",
2952
3042
  "warn": "",
2953
3043
  }
2954
3044
  `);
@@ -2969,7 +3059,7 @@ addEventListener('fetch', event => {});`
2969
3059
  writeWorkerSource();
2970
3060
  writeAssets(assets, "my-assets");
2971
3061
  mockUploadWorkerRequest({
2972
- expectedMainModule: "serve-static-assets.entry.js",
3062
+ expectedMainModule: "index.js",
2973
3063
  });
2974
3064
  mockSubDomainRequest();
2975
3065
  mockListKVNamespacesRequest(kvNamespace);
@@ -2982,6 +3072,7 @@ addEventListener('fetch', event => {});`
2982
3072
  Object {
2983
3073
  "debug": "",
2984
3074
  "err": "",
3075
+ "info": "",
2985
3076
  "out": "Reading file-1.txt...
2986
3077
  Uploading as file-1.2ca234f380.txt...
2987
3078
  Reading file-2.txt...
@@ -2991,7 +3082,7 @@ addEventListener('fetch', event => {});`
2991
3082
  Uploaded test-name (TIMINGS)
2992
3083
  Published test-name (TIMINGS)
2993
3084
  https://test-name.test-sub-domain.workers.dev
2994
- Current Deployment ID: undefined",
3085
+ Current Deployment ID: Galaxy-Class",
2995
3086
  "warn": "▲ [WARNING] The --assets argument is experimental and may change or break at any time
2996
3087
 
2997
3088
  ",
@@ -3014,7 +3105,7 @@ addEventListener('fetch', event => {});`
3014
3105
  Uploaded test-name (TIMINGS)
3015
3106
  Published test-name (TIMINGS)
3016
3107
  https://test-name.test-sub-domain.workers.dev
3017
- Current Deployment ID: undefined"
3108
+ Current Deployment ID: Galaxy-Class"
3018
3109
  `);
3019
3110
  expect(std.err).toMatchInlineSnapshot(`""`);
3020
3111
  });
@@ -3035,7 +3126,7 @@ addEventListener('fetch', event => {});`
3035
3126
  Uploaded test-name (TIMINGS)
3036
3127
  Published test-name (TIMINGS)
3037
3128
  https://test-name.test-sub-domain.workers.dev
3038
- Current Deployment ID: undefined"
3129
+ Current Deployment ID: Galaxy-Class"
3039
3130
  `);
3040
3131
  expect(std.err).toMatchInlineSnapshot(`""`);
3041
3132
  });
@@ -3055,7 +3146,7 @@ addEventListener('fetch', event => {});`
3055
3146
  Uploaded test-name (TIMINGS)
3056
3147
  Published test-name (TIMINGS)
3057
3148
  https://test-name.test-sub-domain.workers.dev
3058
- Current Deployment ID: undefined"
3149
+ Current Deployment ID: Galaxy-Class"
3059
3150
  `);
3060
3151
  expect(std.err).toMatchInlineSnapshot(`""`);
3061
3152
  });
@@ -3074,7 +3165,7 @@ addEventListener('fetch', event => {});`
3074
3165
  "Total Upload: xx KiB / gzip: xx KiB
3075
3166
  Uploaded test-name (TIMINGS)
3076
3167
  No publish targets for test-name (TIMINGS)
3077
- Current Deployment ID: undefined"
3168
+ Current Deployment ID: Galaxy-Class"
3078
3169
  `);
3079
3170
  expect(std.err).toMatchInlineSnapshot(`""`);
3080
3171
  });
@@ -3095,7 +3186,7 @@ addEventListener('fetch', event => {});`
3095
3186
  "Total Upload: xx KiB / gzip: xx KiB
3096
3187
  Uploaded test-name (TIMINGS)
3097
3188
  No publish targets for test-name (TIMINGS)
3098
- Current Deployment ID: undefined"
3189
+ Current Deployment ID: Galaxy-Class"
3099
3190
  `);
3100
3191
  expect(std.err).toMatchInlineSnapshot(`""`);
3101
3192
  });
@@ -3120,7 +3211,7 @@ addEventListener('fetch', event => {});`
3120
3211
  "Total Upload: xx KiB / gzip: xx KiB
3121
3212
  Uploaded test-name (dev) (TIMINGS)
3122
3213
  No publish targets for test-name (dev) (TIMINGS)
3123
- Current Deployment ID: undefined"
3214
+ Current Deployment ID: Galaxy-Class"
3124
3215
  `);
3125
3216
  expect(std.err).toMatchInlineSnapshot(`""`);
3126
3217
  });
@@ -3146,7 +3237,7 @@ addEventListener('fetch', event => {});`
3146
3237
  "Total Upload: xx KiB / gzip: xx KiB
3147
3238
  Uploaded test-name (dev) (TIMINGS)
3148
3239
  No publish targets for test-name (dev) (TIMINGS)
3149
- Current Deployment ID: undefined"
3240
+ Current Deployment ID: Galaxy-Class"
3150
3241
  `);
3151
3242
  expect(std.err).toMatchInlineSnapshot(`""`);
3152
3243
  });
@@ -3173,7 +3264,7 @@ addEventListener('fetch', event => {});`
3173
3264
  Uploaded test-name (dev) (TIMINGS)
3174
3265
  Published test-name (dev) (TIMINGS)
3175
3266
  https://dev.test-name.test-sub-domain.workers.dev
3176
- Current Deployment ID: undefined"
3267
+ Current Deployment ID: Galaxy-Class"
3177
3268
  `);
3178
3269
  expect(std.err).toMatchInlineSnapshot(`""`);
3179
3270
  });
@@ -3201,7 +3292,7 @@ addEventListener('fetch', event => {});`
3201
3292
  Uploaded test-name (dev) (TIMINGS)
3202
3293
  Published test-name (dev) (TIMINGS)
3203
3294
  https://dev.test-name.test-sub-domain.workers.dev
3204
- Current Deployment ID: undefined"
3295
+ Current Deployment ID: Galaxy-Class"
3205
3296
  `);
3206
3297
  expect(std.err).toMatchInlineSnapshot(`""`);
3207
3298
  });
@@ -3230,7 +3321,7 @@ addEventListener('fetch', event => {});`
3230
3321
  Uploaded test-name (dev) (TIMINGS)
3231
3322
  Published test-name (dev) (TIMINGS)
3232
3323
  https://dev.test-name.test-sub-domain.workers.dev
3233
- Current Deployment ID: undefined"
3324
+ Current Deployment ID: Galaxy-Class"
3234
3325
  `);
3235
3326
  expect(std.err).toMatchInlineSnapshot(`""`);
3236
3327
  });
@@ -3262,7 +3353,7 @@ addEventListener('fetch', event => {});`
3262
3353
  Uploaded test-name (dev) (TIMINGS)
3263
3354
  Published test-name (dev) (TIMINGS)
3264
3355
  https://dev.test-name.test-sub-domain.workers.dev
3265
- Current Deployment ID: undefined"
3356
+ Current Deployment ID: Galaxy-Class"
3266
3357
  `);
3267
3358
  expect(std.err).toMatchInlineSnapshot(`""`);
3268
3359
  });
@@ -3296,7 +3387,7 @@ addEventListener('fetch', event => {});`
3296
3387
  Uploaded test-name (dev) (TIMINGS)
3297
3388
  Published test-name (dev) (TIMINGS)
3298
3389
  https://dev.test-name.test-sub-domain.workers.dev
3299
- Current Deployment ID: undefined"
3390
+ Current Deployment ID: Galaxy-Class"
3300
3391
  `);
3301
3392
  expect(std.err).toMatchInlineSnapshot(`""`);
3302
3393
  });
@@ -3357,7 +3448,7 @@ addEventListener('fetch', event => {});`
3357
3448
  Uploaded test-name (TIMINGS)
3358
3449
  Published test-name (TIMINGS)
3359
3450
  https://test-name.test-sub-domain.workers.dev
3360
- Current Deployment ID: undefined"
3451
+ Current Deployment ID: Galaxy-Class"
3361
3452
  `);
3362
3453
  expect(std.err).toMatchInlineSnapshot(`""`);
3363
3454
  });
@@ -3376,7 +3467,7 @@ addEventListener('fetch', event => {});`
3376
3467
  Uploaded test-name (TIMINGS)
3377
3468
  Published test-name (TIMINGS)
3378
3469
  https://test-name.test-sub-domain.workers.dev
3379
- Current Deployment ID: undefined"
3470
+ Current Deployment ID: Galaxy-Class"
3380
3471
  `);
3381
3472
  expect(std.err).toMatchInlineSnapshot(`""`);
3382
3473
  });
@@ -3390,7 +3481,7 @@ addEventListener('fetch', event => {});`
3390
3481
  mockSubDomainRequest("does-not-exist", false);
3391
3482
 
3392
3483
  mockConfirm({
3393
- text: `Would you like to register a workers.dev subdomain now?`,
3484
+ text: "Would you like to register a workers.dev subdomain now?",
3394
3485
  result: false,
3395
3486
  });
3396
3487
 
@@ -3419,7 +3510,7 @@ addEventListener('fetch', event => {});`
3419
3510
  Uploaded test-name (TIMINGS)
3420
3511
  Published test-name (TIMINGS)
3421
3512
  http://example.com/*
3422
- Current Deployment ID: undefined"
3513
+ Current Deployment ID: Galaxy-Class"
3423
3514
  `);
3424
3515
  expect(std.err).toMatchInlineSnapshot(`""`);
3425
3516
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -3454,7 +3545,7 @@ addEventListener('fetch', event => {});`
3454
3545
  Uploaded test-name-production (TIMINGS)
3455
3546
  Published test-name-production (TIMINGS)
3456
3547
  http://production.example.com/*
3457
- Current Deployment ID: undefined"
3548
+ Current Deployment ID: Galaxy-Class"
3458
3549
  `);
3459
3550
  expect(std.err).toMatchInlineSnapshot(`""`);
3460
3551
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -3488,7 +3579,7 @@ addEventListener('fetch', event => {});`
3488
3579
  Uploaded test-name-production (TIMINGS)
3489
3580
  Published test-name-production (TIMINGS)
3490
3581
  http://production.example.com/*
3491
- Current Deployment ID: undefined"
3582
+ Current Deployment ID: Galaxy-Class"
3492
3583
  `);
3493
3584
  expect(std.err).toMatchInlineSnapshot(`""`);
3494
3585
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -3516,7 +3607,7 @@ addEventListener('fetch', event => {});`
3516
3607
  Published test-name (TIMINGS)
3517
3608
  https://test-name.test-sub-domain.workers.dev
3518
3609
  http://example.com/*
3519
- Current Deployment ID: undefined"
3610
+ Current Deployment ID: Galaxy-Class"
3520
3611
  `);
3521
3612
  expect(std.err).toMatchInlineSnapshot(`""`);
3522
3613
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -3552,7 +3643,7 @@ addEventListener('fetch', event => {});`
3552
3643
  Published test-name-production (TIMINGS)
3553
3644
  https://test-name-production.test-sub-domain.workers.dev
3554
3645
  http://production.example.com/*
3555
- Current Deployment ID: undefined"
3646
+ Current Deployment ID: Galaxy-Class"
3556
3647
  `);
3557
3648
  expect(std.err).toMatchInlineSnapshot(`""`);
3558
3649
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -3588,7 +3679,7 @@ addEventListener('fetch', event => {});`
3588
3679
  Published test-name-production (TIMINGS)
3589
3680
  https://test-name-production.test-sub-domain.workers.dev
3590
3681
  http://production.example.com/*
3591
- Current Deployment ID: undefined"
3682
+ Current Deployment ID: Galaxy-Class"
3592
3683
  `);
3593
3684
  expect(std.err).toMatchInlineSnapshot(`""`);
3594
3685
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -3623,7 +3714,7 @@ addEventListener('fetch', event => {});`
3623
3714
  Uploaded test-name-production (TIMINGS)
3624
3715
  Published test-name-production (TIMINGS)
3625
3716
  http://production.example.com/*
3626
- Current Deployment ID: undefined"
3717
+ Current Deployment ID: Galaxy-Class"
3627
3718
  `);
3628
3719
  expect(std.err).toMatchInlineSnapshot(`""`);
3629
3720
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -3658,7 +3749,7 @@ addEventListener('fetch', event => {});`
3658
3749
  Uploaded test-name-production (TIMINGS)
3659
3750
  Published test-name-production (TIMINGS)
3660
3751
  http://production.example.com/*
3661
- Current Deployment ID: undefined"
3752
+ Current Deployment ID: Galaxy-Class"
3662
3753
  `);
3663
3754
  expect(std.err).toMatchInlineSnapshot(`""`);
3664
3755
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -3794,7 +3885,7 @@ addEventListener('fetch', event => {});`
3794
3885
  it("should run a custom build before publishing", async () => {
3795
3886
  writeWranglerToml({
3796
3887
  build: {
3797
- command: `node -e "console.log('custom build'); require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')"`,
3888
+ command: `node -e "4+4; require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')"`,
3798
3889
  },
3799
3890
  });
3800
3891
 
@@ -3805,12 +3896,12 @@ addEventListener('fetch', event => {});`
3805
3896
 
3806
3897
  await runWrangler("publish index.js");
3807
3898
  expect(std.out).toMatchInlineSnapshot(`
3808
- "Running custom build: node -e \\"console.log('custom build'); require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')\\"
3899
+ "Running custom build: node -e \\"4+4; require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')\\"
3809
3900
  Total Upload: xx KiB / gzip: xx KiB
3810
3901
  Uploaded test-name (TIMINGS)
3811
3902
  Published test-name (TIMINGS)
3812
3903
  https://test-name.test-sub-domain.workers.dev
3813
- Current Deployment ID: undefined"
3904
+ Current Deployment ID: Galaxy-Class"
3814
3905
  `);
3815
3906
  expect(std.err).toMatchInlineSnapshot(`""`);
3816
3907
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -3820,7 +3911,7 @@ addEventListener('fetch', event => {});`
3820
3911
  it("should run a custom build of multiple steps combined by && before publishing", async () => {
3821
3912
  writeWranglerToml({
3822
3913
  build: {
3823
- command: `echo "custom build" && echo "export default { fetch(){ return new Response(123) } }" > index.js`,
3914
+ command: `echo "export default { fetch(){ return new Response(123) } }" > index.js`,
3824
3915
  },
3825
3916
  });
3826
3917
 
@@ -3831,12 +3922,12 @@ addEventListener('fetch', event => {});`
3831
3922
 
3832
3923
  await runWrangler("publish index.js");
3833
3924
  expect(std.out).toMatchInlineSnapshot(`
3834
- "Running custom build: echo \\"custom build\\" && echo \\"export default { fetch(){ return new Response(123) } }\\" > index.js
3925
+ "Running custom build: echo \\"export default { fetch(){ return new Response(123) } }\\" > index.js
3835
3926
  Total Upload: xx KiB / gzip: xx KiB
3836
3927
  Uploaded test-name (TIMINGS)
3837
3928
  Published test-name (TIMINGS)
3838
3929
  https://test-name.test-sub-domain.workers.dev
3839
- Current Deployment ID: undefined"
3930
+ Current Deployment ID: Galaxy-Class"
3840
3931
  `);
3841
3932
  expect(std.err).toMatchInlineSnapshot(`""`);
3842
3933
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -3847,22 +3938,22 @@ addEventListener('fetch', event => {});`
3847
3938
  writeWranglerToml({
3848
3939
  main: "index.js",
3849
3940
  build: {
3850
- command: `node -e "console.log('custom build');"`,
3941
+ command: `node -e "4+4;"`,
3851
3942
  },
3852
3943
  });
3853
3944
 
3854
3945
  await expect(runWrangler("publish index.js")).rejects
3855
3946
  .toThrowErrorMatchingInlineSnapshot(`
3856
- "The expected output file at \\"index.js\\" was not found after running custom build: node -e \\"console.log('custom build');\\".
3947
+ "The expected output file at \\"index.js\\" was not found after running custom build: node -e \\"4+4;\\".
3857
3948
  The \`main\` property in wrangler.toml should point to the file generated by the custom build."
3858
3949
  `);
3859
3950
  expect(std.out).toMatchInlineSnapshot(`
3860
- "Running custom build: node -e \\"console.log('custom build');\\"
3951
+ "Running custom build: node -e \\"4+4;\\"
3861
3952
 
3862
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
3953
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
3863
3954
  `);
3864
3955
  expect(std.err).toMatchInlineSnapshot(`
3865
- "X [ERROR] The expected output file at \\"index.js\\" was not found after running custom build: node -e \\"console.log('custom build');\\".
3956
+ "X [ERROR] The expected output file at \\"index.js\\" was not found after running custom build: node -e \\"4+4;\\".
3866
3957
 
3867
3958
  The \`main\` property in wrangler.toml should point to the file generated by the custom build.
3868
3959
 
@@ -3875,7 +3966,7 @@ addEventListener('fetch', event => {});`
3875
3966
  writeWranglerToml({
3876
3967
  main: "./",
3877
3968
  build: {
3878
- command: `node -e "console.log('custom build');"`,
3969
+ command: `node -e "4+4;"`,
3879
3970
  },
3880
3971
  });
3881
3972
 
@@ -3885,7 +3976,7 @@ addEventListener('fetch', event => {});`
3885
3976
 
3886
3977
  await expect(runWrangler("publish")).rejects
3887
3978
  .toThrowErrorMatchingInlineSnapshot(`
3888
- "The expected output file at \\".\\" was not found after running custom build: node -e \\"console.log('custom build');\\".
3979
+ "The expected output file at \\".\\" was not found after running custom build: node -e \\"4+4;\\".
3889
3980
  The \`main\` property in wrangler.toml should point to the file generated by the custom build.
3890
3981
  The provided entry-point path, \\".\\", points to a directory, rather than a file.
3891
3982
 
@@ -3896,12 +3987,12 @@ addEventListener('fetch', event => {});`
3896
3987
  \`\`\`"
3897
3988
  `);
3898
3989
  expect(std.out).toMatchInlineSnapshot(`
3899
- "Running custom build: node -e \\"console.log('custom build');\\"
3990
+ "Running custom build: node -e \\"4+4;\\"
3900
3991
 
3901
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
3992
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
3902
3993
  `);
3903
3994
  expect(std.err).toMatchInlineSnapshot(`
3904
- "X [ERROR] The expected output file at \\".\\" was not found after running custom build: node -e \\"console.log('custom build');\\".
3995
+ "X [ERROR] The expected output file at \\".\\" was not found after running custom build: node -e \\"4+4;\\".
3905
3996
 
3906
3997
  The \`main\` property in wrangler.toml should point to the file generated by the custom build.
3907
3998
  The provided entry-point path, \\".\\", points to a directory, rather than a file.
@@ -3943,7 +4034,7 @@ addEventListener('fetch', event => {});`
3943
4034
  Uploaded test-name (TIMINGS)
3944
4035
  Published test-name (TIMINGS)
3945
4036
  https://test-name.test-sub-domain.workers.dev
3946
- Current Deployment ID: undefined"
4037
+ Current Deployment ID: Galaxy-Class"
3947
4038
  `);
3948
4039
  expect(std.err).toMatchInlineSnapshot(`""`);
3949
4040
  });
@@ -3983,7 +4074,7 @@ addEventListener('fetch', event => {});`
3983
4074
  Uploaded test-name (testEnv) (TIMINGS)
3984
4075
  Published test-name (testEnv) (TIMINGS)
3985
4076
  https://testEnv.test-name.test-sub-domain.workers.dev
3986
- Current Deployment ID: undefined"
4077
+ Current Deployment ID: Galaxy-Class"
3987
4078
  `);
3988
4079
  expect(std.err).toMatchInlineSnapshot(`""`);
3989
4080
  });
@@ -4011,28 +4102,28 @@ addEventListener('fetch', event => {});`
4011
4102
  Uploaded test-name (TIMINGS)
4012
4103
  Published test-name (TIMINGS)
4013
4104
  https://test-name.test-sub-domain.workers.dev
4014
- Current Deployment ID: undefined"
4105
+ Current Deployment ID: Galaxy-Class"
4015
4106
  `);
4016
4107
  expect(std.err).toMatchInlineSnapshot(`""`);
4017
4108
  expect(std.warn).toMatchInlineSnapshot(`
4018
- "▲ [WARNING] Processing wrangler.toml configuration:
4109
+ "▲ [WARNING] Processing wrangler.toml configuration:
4019
4110
 
4020
- - In wrangler.toml, you have configured [durable_objects] exported by this Worker (SomeClass),
4021
- but no [migrations] for them. This may not work as expected until you add a [migrations] section
4022
- to your wrangler.toml. Add this configuration to your wrangler.toml:
4111
+ - In wrangler.toml, you have configured [durable_objects] exported by this Worker (SomeClass),
4112
+ but no [migrations] for them. This may not work as expected until you add a [migrations] section
4113
+ to your wrangler.toml. Add this configuration to your wrangler.toml:
4023
4114
 
4024
- \`\`\`
4025
- [[migrations]]
4026
- tag = \\"v1\\" # Should be unique for each entry
4027
- new_classes = [\\"SomeClass\\"]
4028
- \`\`\`
4115
+ \`\`\`
4116
+ [[migrations]]
4117
+ tag = \\"v1\\" # Should be unique for each entry
4118
+ new_classes = [\\"SomeClass\\"]
4119
+ \`\`\`
4029
4120
 
4030
- Refer to
4031
- https://developers.cloudflare.com/workers/learning/using-durable-objects/#durable-object-migrations-in-wranglertoml
4032
- for more details.
4121
+ Refer to
4122
+ https://developers.cloudflare.com/workers/learning/using-durable-objects/#durable-object-migrations-in-wranglertoml
4123
+ for more details.
4033
4124
 
4034
- "
4035
- `);
4125
+ "
4126
+ `);
4036
4127
  });
4037
4128
 
4038
4129
  it("does not warn if all the durable object bindings are to external classes", async () => {
@@ -4062,7 +4153,7 @@ addEventListener('fetch', event => {});`
4062
4153
  Uploaded test-name (TIMINGS)
4063
4154
  Published test-name (TIMINGS)
4064
4155
  https://test-name.test-sub-domain.workers.dev
4065
- Current Deployment ID: undefined"
4156
+ Current Deployment ID: Galaxy-Class"
4066
4157
  `);
4067
4158
  expect(std.err).toMatchInlineSnapshot(`""`);
4068
4159
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -4107,7 +4198,7 @@ addEventListener('fetch', event => {});`
4107
4198
  Uploaded test-name (TIMINGS)
4108
4199
  Published test-name (TIMINGS)
4109
4200
  https://test-name.test-sub-domain.workers.dev
4110
- Current Deployment ID: undefined"
4201
+ Current Deployment ID: Galaxy-Class"
4111
4202
  `);
4112
4203
  expect(std.err).toMatchInlineSnapshot(`""`);
4113
4204
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -4151,6 +4242,7 @@ addEventListener('fetch', event => {});`
4151
4242
  Object {
4152
4243
  "debug": "",
4153
4244
  "err": "",
4245
+ "info": "",
4154
4246
  "out": "Total Upload: xx KiB / gzip: xx KiB
4155
4247
  Your worker has access to the following bindings:
4156
4248
  - Durable Objects:
@@ -4159,7 +4251,7 @@ addEventListener('fetch', event => {});`
4159
4251
  Uploaded test-name (TIMINGS)
4160
4252
  Published test-name (TIMINGS)
4161
4253
  https://test-name.test-sub-domain.workers.dev
4162
- Current Deployment ID: undefined",
4254
+ Current Deployment ID: Galaxy-Class",
4163
4255
  "warn": "",
4164
4256
  }
4165
4257
  `);
@@ -4196,6 +4288,7 @@ addEventListener('fetch', event => {});`
4196
4288
  Object {
4197
4289
  "debug": "",
4198
4290
  "err": "",
4291
+ "info": "",
4199
4292
  "out": "Total Upload: xx KiB / gzip: xx KiB
4200
4293
  Your worker has access to the following bindings:
4201
4294
  - Durable Objects:
@@ -4204,7 +4297,7 @@ addEventListener('fetch', event => {});`
4204
4297
  Uploaded test-name (TIMINGS)
4205
4298
  Published test-name (TIMINGS)
4206
4299
  https://test-name.test-sub-domain.workers.dev
4207
- Current Deployment ID: undefined",
4300
+ Current Deployment ID: Galaxy-Class",
4208
4301
  "warn": "",
4209
4302
  }
4210
4303
  `);
@@ -4251,17 +4344,17 @@ addEventListener('fetch', event => {});`
4251
4344
  Uploaded test-name (TIMINGS)
4252
4345
  Published test-name (TIMINGS)
4253
4346
  https://test-name.test-sub-domain.workers.dev
4254
- Current Deployment ID: undefined"
4347
+ Current Deployment ID: Galaxy-Class"
4255
4348
  `);
4256
4349
  expect(std.err).toMatchInlineSnapshot(`""`);
4257
4350
  expect(std.warn).toMatchInlineSnapshot(`
4258
- "▲ [WARNING] Processing wrangler.toml configuration:
4351
+ "▲ [WARNING] Processing wrangler.toml configuration:
4259
4352
 
4260
- - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in
4261
- the future. DO NOT USE IN PRODUCTION.
4353
+ - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in
4354
+ the future. DO NOT USE IN PRODUCTION.
4262
4355
 
4263
- "
4264
- `);
4356
+ "
4357
+ `);
4265
4358
  });
4266
4359
 
4267
4360
  it("should publish all migrations on first publish (--env)", async () => {
@@ -4315,21 +4408,20 @@ addEventListener('fetch', event => {});`
4315
4408
  Uploaded test-name (xyz) (TIMINGS)
4316
4409
  Published test-name (xyz) (TIMINGS)
4317
4410
  https://xyz.test-name.test-sub-domain.workers.dev
4318
- Current Deployment ID: undefined"
4411
+ Current Deployment ID: Galaxy-Class"
4319
4412
  `);
4320
4413
  expect(std.err).toMatchInlineSnapshot(`""`);
4321
4414
  expect(std.warn).toMatchInlineSnapshot(`
4322
- "▲ [WARNING] Processing wrangler.toml configuration:
4415
+ "▲ [WARNING] Processing wrangler.toml configuration:
4323
4416
 
4324
- - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in
4325
- the future. DO NOT USE IN PRODUCTION.
4417
+ - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in
4418
+ the future. DO NOT USE IN PRODUCTION.
4326
4419
 
4327
- "
4328
- `);
4420
+ "
4421
+ `);
4329
4422
  });
4330
4423
 
4331
4424
  it("should use a script's current migration tag when publishing migrations", async () => {
4332
- unsetAllMocks();
4333
4425
  writeWranglerToml({
4334
4426
  durable_objects: {
4335
4427
  bindings: [
@@ -4348,32 +4440,29 @@ addEventListener('fetch', event => {});`
4348
4440
  );
4349
4441
  mockSubDomainRequest();
4350
4442
  mockServiceScriptData({
4351
- script: { id: "test-name", migration_tag: "v1" },
4443
+ script: { id: "test-name", migration_tag: "v2" },
4352
4444
  });
4353
4445
  mockUploadWorkerRequest({
4354
4446
  legacyEnv: false,
4355
4447
  expectedMigrations: {
4356
- old_tag: "v1",
4357
4448
  new_tag: "v2",
4358
4449
  steps: [
4450
+ {
4451
+ new_classes: ["SomeClass"],
4452
+ },
4359
4453
  {
4360
4454
  new_classes: ["SomeOtherClass"],
4361
4455
  },
4362
4456
  ],
4363
4457
  },
4364
4458
  });
4365
- setMockResponse(
4366
- "/accounts/:accountId/workers/deployments/by-script/:scriptTag",
4367
- () => ({
4368
- latest: { number: "2" },
4369
- })
4370
- );
4371
4459
 
4372
4460
  await runWrangler("publish index.js --legacy-env false");
4373
4461
  expect(std).toMatchInlineSnapshot(`
4374
4462
  Object {
4375
4463
  "debug": "",
4376
4464
  "err": "",
4465
+ "info": "",
4377
4466
  "out": "Total Upload: xx KiB / gzip: xx KiB
4378
4467
  Your worker has access to the following bindings:
4379
4468
  - Durable Objects:
@@ -4382,7 +4471,7 @@ addEventListener('fetch', event => {});`
4382
4471
  Uploaded test-name (TIMINGS)
4383
4472
  Published test-name (TIMINGS)
4384
4473
  https://test-name.test-sub-domain.workers.dev
4385
- Current Deployment ID: undefined",
4474
+ Current Deployment ID: Galaxy-Class",
4386
4475
  "warn": "▲ [WARNING] Processing wrangler.toml configuration:
4387
4476
 
4388
4477
  - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in
@@ -4444,6 +4533,7 @@ addEventListener('fetch', event => {});`
4444
4533
  Object {
4445
4534
  "debug": "",
4446
4535
  "err": "",
4536
+ "info": "",
4447
4537
  "out": "Total Upload: xx KiB / gzip: xx KiB
4448
4538
  Your worker has access to the following bindings:
4449
4539
  - Durable Objects:
@@ -4452,7 +4542,7 @@ addEventListener('fetch', event => {});`
4452
4542
  Uploaded test-name (xyz) (TIMINGS)
4453
4543
  Published test-name (xyz) (TIMINGS)
4454
4544
  https://xyz.test-name.test-sub-domain.workers.dev
4455
- Current Deployment ID: undefined",
4545
+ Current Deployment ID: Galaxy-Class",
4456
4546
  "warn": "▲ [WARNING] Processing wrangler.toml configuration:
4457
4547
 
4458
4548
  - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in
@@ -4497,6 +4587,10 @@ addEventListener('fetch', event => {});`
4497
4587
  { binding: "R2_BUCKET_ONE", bucket_name: "r2-bucket-one-name" },
4498
4588
  { binding: "R2_BUCKET_TWO", bucket_name: "r2-bucket-two-name" },
4499
4589
  ],
4590
+ analytics_engine_datasets: [
4591
+ { binding: "AE_DATASET_ONE", dataset: "ae-dataset-one-name" },
4592
+ { binding: "AE_DATASET_TWO", dataset: "ae-dataset-two-name" },
4593
+ ],
4500
4594
  text_blobs: {
4501
4595
  TEXT_BLOB_ONE: "./my-entire-app-depends-on-this.cfg",
4502
4596
  TEXT_BLOB_TWO: "./the-entirety-of-human-knowledge.txt",
@@ -4514,6 +4608,10 @@ addEventListener('fetch', event => {});`
4514
4608
  data: 1337,
4515
4609
  },
4516
4610
  ],
4611
+ metadata: {
4612
+ extra_data: "interesting value",
4613
+ more_data: "dubious value",
4614
+ },
4517
4615
  },
4518
4616
  vars: {
4519
4617
  ENV_VAR_ONE: 123,
@@ -4558,6 +4656,10 @@ addEventListener('fetch', event => {});`
4558
4656
 
4559
4657
  mockUploadWorkerRequest({
4560
4658
  expectedType: "sw",
4659
+ expectedUnsafeMetaData: {
4660
+ extra_data: "interesting value",
4661
+ more_data: "dubious value",
4662
+ },
4561
4663
  expectedBindings: [
4562
4664
  { json: 123, name: "ENV_VAR_ONE", type: "json" },
4563
4665
  {
@@ -4598,6 +4700,16 @@ addEventListener('fetch', event => {});`
4598
4700
  name: "R2_BUCKET_TWO",
4599
4701
  type: "r2_bucket",
4600
4702
  },
4703
+ {
4704
+ dataset: "ae-dataset-one-name",
4705
+ name: "AE_DATASET_ONE",
4706
+ type: "analytics_engine",
4707
+ },
4708
+ {
4709
+ dataset: "ae-dataset-two-name",
4710
+ name: "AE_DATASET_TWO",
4711
+ type: "analytics_engine",
4712
+ },
4601
4713
  {
4602
4714
  name: "httplogs",
4603
4715
  type: "logfwdr",
@@ -4656,6 +4768,9 @@ addEventListener('fetch', event => {});`
4656
4768
  - logfwdr:
4657
4769
  - httplogs: httplogs
4658
4770
  - trace: trace
4771
+ - Analytics Engine Datasets:
4772
+ - AE_DATASET_ONE: ae-dataset-one-name
4773
+ - AE_DATASET_TWO: ae-dataset-two-name
4659
4774
  - Text Blobs:
4660
4775
  - TEXT_BLOB_ONE: my-entire-app-depends-on-this.cfg
4661
4776
  - TEXT_BLOB_TWO: the-entirety-of-human-knowledge.txt
@@ -4668,19 +4783,22 @@ addEventListener('fetch', event => {});`
4668
4783
  - Wasm Modules:
4669
4784
  - WASM_MODULE_ONE: some_wasm.wasm
4670
4785
  - WASM_MODULE_TWO: more_wasm.wasm
4786
+ - Unsafe Metadata:
4787
+ - extra_data: interesting value
4788
+ - more_data: dubious value
4671
4789
  Uploaded test-name (TIMINGS)
4672
4790
  Published test-name (TIMINGS)
4673
4791
  https://test-name.test-sub-domain.workers.dev
4674
- Current Deployment ID: undefined"
4792
+ Current Deployment ID: Galaxy-Class"
4675
4793
  `);
4676
4794
  expect(std.err).toMatchInlineSnapshot(`""`);
4677
4795
  expect(std.warn).toMatchInlineSnapshot(`
4678
- "▲ [WARNING] Processing wrangler.toml configuration:
4796
+ "▲ [WARNING] Processing wrangler.toml configuration:
4679
4797
 
4680
- - \\"unsafe\\" fields are experimental and may change or break at any time.
4798
+ - \\"unsafe\\" fields are experimental and may change or break at any time.
4681
4799
 
4682
- "
4683
- `);
4800
+ "
4801
+ `);
4684
4802
  });
4685
4803
 
4686
4804
  it("should error when bindings of different types have the same name", async () => {
@@ -4713,6 +4831,12 @@ addEventListener('fetch', event => {});`
4713
4831
  bucket_name: "r2-bucket-two-name",
4714
4832
  },
4715
4833
  ],
4834
+ analytics_engine_datasets: [
4835
+ {
4836
+ binding: "CONFLICTING_NAME_FOUR",
4837
+ dataset: "analytics-engine-dataset-name",
4838
+ },
4839
+ ],
4716
4840
  text_blobs: {
4717
4841
  CONFLICTING_NAME_THREE: "./my-entire-app-depends-on-this.cfg",
4718
4842
  CONFLICTING_NAME_FOUR: "./the-entirety-of-human-knowledge.txt",
@@ -4730,6 +4854,7 @@ addEventListener('fetch', event => {});`
4730
4854
  data: 1337,
4731
4855
  },
4732
4856
  ],
4857
+ metadata: undefined,
4733
4858
  },
4734
4859
  vars: {
4735
4860
  ENV_VAR_ONE: 123,
@@ -4760,13 +4885,13 @@ addEventListener('fetch', event => {});`
4760
4885
  - CONFLICTING_NAME_ONE assigned to Durable Object, KV Namespace, and R2 Bucket bindings.
4761
4886
  - CONFLICTING_NAME_TWO assigned to Durable Object and KV Namespace bindings.
4762
4887
  - CONFLICTING_NAME_THREE assigned to R2 Bucket, Text Blob, Unsafe, Environment Variable, WASM Module, and Data Blob bindings.
4763
- - CONFLICTING_NAME_FOUR assigned to Text Blob and Unsafe bindings.
4888
+ - CONFLICTING_NAME_FOUR assigned to Analytics Engine Dataset, Text Blob, and Unsafe bindings.
4764
4889
  - Bindings must have unique names, so that they can all be referenced in the worker.
4765
4890
  Please change your bindings to have unique names.]
4766
4891
  `);
4767
4892
  expect(std.out).toMatchInlineSnapshot(`
4768
4893
  "
4769
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
4894
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
4770
4895
  `);
4771
4896
  expect(std.err).toMatchInlineSnapshot(`
4772
4897
  "X [ERROR] Processing wrangler.toml configuration:
@@ -4775,7 +4900,7 @@ addEventListener('fetch', event => {});`
4775
4900
  - CONFLICTING_NAME_TWO assigned to Durable Object and KV Namespace bindings.
4776
4901
  - CONFLICTING_NAME_THREE assigned to R2 Bucket, Text Blob, Unsafe, Environment Variable, WASM
4777
4902
  Module, and Data Blob bindings.
4778
- - CONFLICTING_NAME_FOUR assigned to Text Blob and Unsafe bindings.
4903
+ - CONFLICTING_NAME_FOUR assigned to Analytics Engine Dataset, Text Blob, and Unsafe bindings.
4779
4904
  - Bindings must have unique names, so that they can all be referenced in the worker.
4780
4905
  Please change your bindings to have unique names.
4781
4906
 
@@ -4820,6 +4945,16 @@ addEventListener('fetch', event => {});`
4820
4945
  bucket_name: "r2-bucket-two-name",
4821
4946
  },
4822
4947
  ],
4948
+ analytics_engine_datasets: [
4949
+ {
4950
+ binding: "CONFLICTING_AE_DATASET_NAME",
4951
+ dataset: "ae-dataset-one-name",
4952
+ },
4953
+ {
4954
+ binding: "CONFLICTING_AE_DATASET_NAME",
4955
+ dataset: "ae-dataset-two-name",
4956
+ },
4957
+ ],
4823
4958
  unsafe: {
4824
4959
  bindings: [
4825
4960
  {
@@ -4833,6 +4968,7 @@ addEventListener('fetch', event => {});`
4833
4968
  data: 1337,
4834
4969
  },
4835
4970
  ],
4971
+ metadata: undefined,
4836
4972
  },
4837
4973
  // text_blobs, vars, wasm_modules and data_blobs are fine because they're object literals,
4838
4974
  // and by definition cannot have two keys of the same name
@@ -4859,13 +4995,14 @@ addEventListener('fetch', event => {});`
4859
4995
  - CONFLICTING_DURABLE_OBJECT_NAME assigned to multiple Durable Object bindings.
4860
4996
  - CONFLICTING_KV_NAMESPACE_NAME assigned to multiple KV Namespace bindings.
4861
4997
  - CONFLICTING_R2_BUCKET_NAME assigned to multiple R2 Bucket bindings.
4998
+ - CONFLICTING_AE_DATASET_NAME assigned to multiple Analytics Engine Dataset bindings.
4862
4999
  - CONFLICTING_UNSAFE_NAME assigned to multiple Unsafe bindings.
4863
5000
  - Bindings must have unique names, so that they can all be referenced in the worker.
4864
5001
  Please change your bindings to have unique names.]
4865
5002
  `);
4866
5003
  expect(std.out).toMatchInlineSnapshot(`
4867
5004
  "
4868
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
5005
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
4869
5006
  `);
4870
5007
  expect(std.err).toMatchInlineSnapshot(`
4871
5008
  "X [ERROR] Processing wrangler.toml configuration:
@@ -4873,6 +5010,7 @@ addEventListener('fetch', event => {});`
4873
5010
  - CONFLICTING_DURABLE_OBJECT_NAME assigned to multiple Durable Object bindings.
4874
5011
  - CONFLICTING_KV_NAMESPACE_NAME assigned to multiple KV Namespace bindings.
4875
5012
  - CONFLICTING_R2_BUCKET_NAME assigned to multiple R2 Bucket bindings.
5013
+ - CONFLICTING_AE_DATASET_NAME assigned to multiple Analytics Engine Dataset bindings.
4876
5014
  - CONFLICTING_UNSAFE_NAME assigned to multiple Unsafe bindings.
4877
5015
  - Bindings must have unique names, so that they can all be referenced in the worker.
4878
5016
  Please change your bindings to have unique names.
@@ -4934,6 +5072,24 @@ addEventListener('fetch', event => {});`
4934
5072
  bucket_name: "r2-bucket-four-name",
4935
5073
  },
4936
5074
  ],
5075
+ analytics_engine_datasets: [
5076
+ {
5077
+ binding: "CONFLICTING_AE_DATASET_NAME",
5078
+ dataset: "ae-dataset-one-name",
5079
+ },
5080
+ {
5081
+ binding: "CONFLICTING_AE_DATASET_NAME",
5082
+ dataset: "ae-dataset-two-name",
5083
+ },
5084
+ {
5085
+ binding: "CONFLICTING_NAME_THREE",
5086
+ dataset: "ae-dataset-three-name",
5087
+ },
5088
+ {
5089
+ binding: "CONFLICTING_NAME_FOUR",
5090
+ dataset: "ae-dataset-four-name",
5091
+ },
5092
+ ],
4937
5093
  text_blobs: {
4938
5094
  CONFLICTING_NAME_THREE: "./my-entire-app-depends-on-this.cfg",
4939
5095
  CONFLICTING_NAME_FOUR: "./the-entirety-of-human-knowledge.txt",
@@ -4961,6 +5117,7 @@ addEventListener('fetch', event => {});`
4961
5117
  data: null,
4962
5118
  },
4963
5119
  ],
5120
+ metadata: undefined,
4964
5121
  },
4965
5122
  vars: {
4966
5123
  ENV_VAR_ONE: 123,
@@ -4991,15 +5148,16 @@ addEventListener('fetch', event => {});`
4991
5148
  - CONFLICTING_DURABLE_OBJECT_NAME assigned to multiple Durable Object bindings.
4992
5149
  - CONFLICTING_KV_NAMESPACE_NAME assigned to multiple KV Namespace bindings.
4993
5150
  - CONFLICTING_R2_BUCKET_NAME assigned to multiple R2 Bucket bindings.
4994
- - CONFLICTING_NAME_THREE assigned to R2 Bucket, Text Blob, Unsafe, Environment Variable, WASM Module, and Data Blob bindings.
4995
- - CONFLICTING_NAME_FOUR assigned to R2 Bucket, Text Blob, and Unsafe bindings.
5151
+ - CONFLICTING_NAME_THREE assigned to R2 Bucket, Analytics Engine Dataset, Text Blob, Unsafe, Environment Variable, WASM Module, and Data Blob bindings.
5152
+ - CONFLICTING_NAME_FOUR assigned to R2 Bucket, Analytics Engine Dataset, Text Blob, and Unsafe bindings.
5153
+ - CONFLICTING_AE_DATASET_NAME assigned to multiple Analytics Engine Dataset bindings.
4996
5154
  - CONFLICTING_UNSAFE_NAME assigned to multiple Unsafe bindings.
4997
5155
  - Bindings must have unique names, so that they can all be referenced in the worker.
4998
5156
  Please change your bindings to have unique names.]
4999
5157
  `);
5000
5158
  expect(std.out).toMatchInlineSnapshot(`
5001
5159
  "
5002
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
5160
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
5003
5161
  `);
5004
5162
  expect(std.err).toMatchInlineSnapshot(`
5005
5163
  "X [ERROR] Processing wrangler.toml configuration:
@@ -5007,9 +5165,11 @@ addEventListener('fetch', event => {});`
5007
5165
  - CONFLICTING_DURABLE_OBJECT_NAME assigned to multiple Durable Object bindings.
5008
5166
  - CONFLICTING_KV_NAMESPACE_NAME assigned to multiple KV Namespace bindings.
5009
5167
  - CONFLICTING_R2_BUCKET_NAME assigned to multiple R2 Bucket bindings.
5010
- - CONFLICTING_NAME_THREE assigned to R2 Bucket, Text Blob, Unsafe, Environment Variable, WASM
5011
- Module, and Data Blob bindings.
5012
- - CONFLICTING_NAME_FOUR assigned to R2 Bucket, Text Blob, and Unsafe bindings.
5168
+ - CONFLICTING_NAME_THREE assigned to R2 Bucket, Analytics Engine Dataset, Text Blob, Unsafe,
5169
+ Environment Variable, WASM Module, and Data Blob bindings.
5170
+ - CONFLICTING_NAME_FOUR assigned to R2 Bucket, Analytics Engine Dataset, Text Blob, and Unsafe
5171
+ bindings.
5172
+ - CONFLICTING_AE_DATASET_NAME assigned to multiple Analytics Engine Dataset bindings.
5013
5173
  - CONFLICTING_UNSAFE_NAME assigned to multiple Unsafe bindings.
5014
5174
  - Bindings must have unique names, so that they can all be referenced in the worker.
5015
5175
  Please change your bindings to have unique names.
@@ -5043,6 +5203,7 @@ addEventListener('fetch', event => {});`
5043
5203
  ],
5044
5204
  });
5045
5205
  mockSubDomainRequest();
5206
+
5046
5207
  await runWrangler("publish index.js");
5047
5208
  expect(std.out).toMatchInlineSnapshot(`
5048
5209
  "Total Upload: xx KiB / gzip: xx KiB
@@ -5052,7 +5213,7 @@ addEventListener('fetch', event => {});`
5052
5213
  Uploaded test-name (TIMINGS)
5053
5214
  Published test-name (TIMINGS)
5054
5215
  https://test-name.test-sub-domain.workers.dev
5055
- Current Deployment ID: undefined"
5216
+ Current Deployment ID: Galaxy-Class"
5056
5217
  `);
5057
5218
  expect(std.err).toMatchInlineSnapshot(`""`);
5058
5219
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -5075,7 +5236,7 @@ addEventListener('fetch', event => {});`
5075
5236
  );
5076
5237
  expect(std.out).toMatchInlineSnapshot(`
5077
5238
  "
5078
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
5239
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
5079
5240
  `);
5080
5241
  expect(std.err).toMatchInlineSnapshot(`
5081
5242
  "X [ERROR] You cannot configure [wasm_modules] with an ES module worker. Instead, import the .wasm module directly in your code
@@ -5123,7 +5284,7 @@ addEventListener('fetch', event => {});`
5123
5284
  Uploaded test-name (TIMINGS)
5124
5285
  Published test-name (TIMINGS)
5125
5286
  https://test-name.test-sub-domain.workers.dev
5126
- Current Deployment ID: undefined"
5287
+ Current Deployment ID: Galaxy-Class"
5127
5288
  `);
5128
5289
  expect(std.err).toMatchInlineSnapshot(`""`);
5129
5290
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -5157,7 +5318,7 @@ addEventListener('fetch', event => {});`
5157
5318
  Uploaded test-name (TIMINGS)
5158
5319
  Published test-name (TIMINGS)
5159
5320
  https://test-name.test-sub-domain.workers.dev
5160
- Current Deployment ID: undefined"
5321
+ Current Deployment ID: Galaxy-Class"
5161
5322
  `);
5162
5323
  expect(std.err).toMatchInlineSnapshot(`""`);
5163
5324
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -5195,7 +5356,7 @@ addEventListener('fetch', event => {});`
5195
5356
  Uploaded test-name (TIMINGS)
5196
5357
  Published test-name (TIMINGS)
5197
5358
  https://test-name.test-sub-domain.workers.dev
5198
- Current Deployment ID: undefined"
5359
+ Current Deployment ID: Galaxy-Class"
5199
5360
  `);
5200
5361
  expect(std.err).toMatchInlineSnapshot(`""`);
5201
5362
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -5218,7 +5379,7 @@ addEventListener('fetch', event => {});`
5218
5379
  );
5219
5380
  expect(std.out).toMatchInlineSnapshot(`
5220
5381
  "
5221
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
5382
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
5222
5383
  `);
5223
5384
  expect(std.err).toMatchInlineSnapshot(`
5224
5385
  "X [ERROR] You cannot configure [text_blobs] with an ES module worker. Instead, import the file directly in your code, and optionally configure \`[rules]\` in your wrangler.toml
@@ -5270,7 +5431,7 @@ addEventListener('fetch', event => {});`
5270
5431
  Uploaded test-name (TIMINGS)
5271
5432
  Published test-name (TIMINGS)
5272
5433
  https://test-name.test-sub-domain.workers.dev
5273
- Current Deployment ID: undefined"
5434
+ Current Deployment ID: Galaxy-Class"
5274
5435
  `);
5275
5436
  expect(std.err).toMatchInlineSnapshot(`""`);
5276
5437
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -5308,7 +5469,7 @@ addEventListener('fetch', event => {});`
5308
5469
  Uploaded test-name (TIMINGS)
5309
5470
  Published test-name (TIMINGS)
5310
5471
  https://test-name.test-sub-domain.workers.dev
5311
- Current Deployment ID: undefined"
5472
+ Current Deployment ID: Galaxy-Class"
5312
5473
  `);
5313
5474
  expect(std.err).toMatchInlineSnapshot(`""`);
5314
5475
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -5331,7 +5492,7 @@ addEventListener('fetch', event => {});`
5331
5492
  );
5332
5493
  expect(std.out).toMatchInlineSnapshot(`
5333
5494
  "
5334
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
5495
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
5335
5496
  `);
5336
5497
  expect(std.err).toMatchInlineSnapshot(`
5337
5498
  "X [ERROR] You cannot configure [data_blobs] with an ES module worker. Instead, import the file directly in your code, and optionally configure \`[rules]\` in your wrangler.toml
@@ -5383,7 +5544,7 @@ addEventListener('fetch', event => {});`
5383
5544
  Uploaded test-name (TIMINGS)
5384
5545
  Published test-name (TIMINGS)
5385
5546
  https://test-name.test-sub-domain.workers.dev
5386
- Current Deployment ID: undefined"
5547
+ Current Deployment ID: Galaxy-Class"
5387
5548
  `);
5388
5549
  expect(std.err).toMatchInlineSnapshot(`""`);
5389
5550
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -5427,7 +5588,7 @@ addEventListener('fetch', event => {});`
5427
5588
  Uploaded test-name (TIMINGS)
5428
5589
  Published test-name (TIMINGS)
5429
5590
  https://test-name.test-sub-domain.workers.dev
5430
- Current Deployment ID: undefined"
5591
+ Current Deployment ID: Galaxy-Class"
5431
5592
  `);
5432
5593
  expect(std.err).toMatchInlineSnapshot(`""`);
5433
5594
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -5443,6 +5604,7 @@ addEventListener('fetch', event => {});`
5443
5604
  Object {
5444
5605
  "debug": "",
5445
5606
  "err": "",
5607
+ "info": "",
5446
5608
  "out": "Total Upload: xx KiB / gzip: xx KiB
5447
5609
  Your worker has access to the following bindings:
5448
5610
  - Vars:
@@ -5451,7 +5613,7 @@ addEventListener('fetch', event => {});`
5451
5613
  Uploaded test-name (TIMINGS)
5452
5614
  Published test-name (TIMINGS)
5453
5615
  https://test-name.test-sub-domain.workers.dev
5454
- Current Deployment ID: undefined",
5616
+ Current Deployment ID: Galaxy-Class",
5455
5617
  "warn": "",
5456
5618
  }
5457
5619
  `);
@@ -5480,7 +5642,7 @@ addEventListener('fetch', event => {});`
5480
5642
  Uploaded test-name (TIMINGS)
5481
5643
  Published test-name (TIMINGS)
5482
5644
  https://test-name.test-sub-domain.workers.dev
5483
- Current Deployment ID: undefined"
5645
+ Current Deployment ID: Galaxy-Class"
5484
5646
  `);
5485
5647
  expect(std.err).toMatchInlineSnapshot(`""`);
5486
5648
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -5533,7 +5695,7 @@ addEventListener('fetch', event => {});`
5533
5695
  Uploaded test-name (TIMINGS)
5534
5696
  Published test-name (TIMINGS)
5535
5697
  https://test-name.test-sub-domain.workers.dev
5536
- Current Deployment ID: undefined"
5698
+ Current Deployment ID: Galaxy-Class"
5537
5699
  `);
5538
5700
  expect(std.err).toMatchInlineSnapshot(`""`);
5539
5701
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -5580,7 +5742,7 @@ addEventListener('fetch', event => {});`
5580
5742
  Uploaded test-name (TIMINGS)
5581
5743
  Published test-name (TIMINGS)
5582
5744
  https://test-name.test-sub-domain.workers.dev
5583
- Current Deployment ID: undefined"
5745
+ Current Deployment ID: Galaxy-Class"
5584
5746
  `);
5585
5747
  expect(std.err).toMatchInlineSnapshot(`""`);
5586
5748
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -5621,7 +5783,7 @@ addEventListener('fetch', event => {});`
5621
5783
  Uploaded test-name (TIMINGS)
5622
5784
  Published test-name (TIMINGS)
5623
5785
  https://test-name.test-sub-domain.workers.dev
5624
- Current Deployment ID: undefined"
5786
+ Current Deployment ID: Galaxy-Class"
5625
5787
  `);
5626
5788
  expect(std.err).toMatchInlineSnapshot(`""`);
5627
5789
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -5667,14 +5829,15 @@ addEventListener('fetch', event => {});`
5667
5829
  Uploaded test-name (TIMINGS)
5668
5830
  Published test-name (TIMINGS)
5669
5831
  https://test-name.test-sub-domain.workers.dev
5670
- Current Deployment ID: undefined"
5832
+ Current Deployment ID: Galaxy-Class"
5671
5833
  `);
5672
5834
  expect(std.err).toMatchInlineSnapshot(`""`);
5673
5835
  expect(std.warn).toMatchInlineSnapshot(`""`);
5674
5836
  });
5675
5837
 
5676
- it("should error when detecting a service-worker worker implementing durable objects", async () => {
5838
+ it("should support durable objects and D1", async () => {
5677
5839
  writeWranglerToml({
5840
+ main: "index.js",
5678
5841
  durable_objects: {
5679
5842
  bindings: [
5680
5843
  {
@@ -5683,39 +5846,109 @@ addEventListener('fetch', event => {});`
5683
5846
  },
5684
5847
  ],
5685
5848
  },
5686
- });
5687
- writeWorkerSource({ type: "sw" });
5688
- mockSubDomainRequest();
5689
-
5690
- await expect(runWrangler("publish index.js")).rejects
5691
- .toThrowErrorMatchingInlineSnapshot(`
5692
- "You seem to be trying to use Durable Objects in a Worker written as a service-worker.
5693
- 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:
5694
- { name = EXAMPLE_DO_BINDING, class_name = ExampleDurableObject } ==> { name = EXAMPLE_DO_BINDING, class_name = ExampleDurableObject, script_name = example-do-binding-worker }
5695
- Alternatively, migrate your worker to ES Module syntax to implement a Durable Object in this Worker:
5696
- https://developers.cloudflare.com/workers/learning/migrating-to-module-workers/"
5697
- `);
5698
- });
5699
- });
5700
-
5701
- describe("[services]", () => {
5702
- it("should support service bindings", async () => {
5703
- writeWranglerToml({
5704
- services: [
5849
+ migrations: [{ tag: "v1", new_classes: ["ExampleDurableObject"] }],
5850
+ d1_databases: [
5705
5851
  {
5706
- binding: "FOO",
5707
- service: "foo-service",
5708
- environment: "production",
5852
+ binding: "DB",
5853
+ database_name: "test-d1-db",
5854
+ database_id: "UUID-1-2-3-4",
5855
+ preview_database_id: "UUID-1-2-3-4",
5709
5856
  },
5710
5857
  ],
5711
5858
  });
5712
- writeWorkerSource();
5859
+ const scriptContent = `export class ExampleDurableObject {}; export default{};`;
5860
+ fs.writeFileSync("index.js", scriptContent);
5713
5861
  mockSubDomainRequest();
5862
+ mockLegacyScriptData({
5863
+ scripts: [{ id: "test-name", migration_tag: "v1" }],
5864
+ });
5714
5865
  mockUploadWorkerRequest({
5866
+ expectedType: "esm",
5715
5867
  expectedBindings: [
5716
5868
  {
5717
- type: "service",
5718
- name: "FOO",
5869
+ name: "EXAMPLE_DO_BINDING",
5870
+ class_name: "ExampleDurableObject",
5871
+ type: "durable_object_namespace",
5872
+ },
5873
+ { name: "DB", type: "d1_database" },
5874
+ ],
5875
+ });
5876
+
5877
+ await runWrangler("publish index.js --outdir tmp --dry-run");
5878
+ expect(std.out).toMatchInlineSnapshot(`
5879
+ "Total Upload: xx KiB / gzip: xx KiB
5880
+ Your worker has access to the following bindings:
5881
+ - Durable Objects:
5882
+ - EXAMPLE_DO_BINDING: ExampleDurableObject
5883
+ - D1 Databases:
5884
+ - DB: test-d1-db (UUID-1-2-3-4), Preview: (UUID-1-2-3-4)
5885
+ --dry-run: exiting now."
5886
+ `);
5887
+ expect(std.err).toMatchInlineSnapshot(`""`);
5888
+ expect(std.warn).toMatchInlineSnapshot(`
5889
+ "▲ [WARNING] Processing wrangler.toml configuration:
5890
+
5891
+ - D1 Bindings are currently in alpha to allow the API to evolve before general availability.
5892
+ Please report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose
5893
+ Note: Run this command with the environment variable NO_D1_WARNING=true to hide this message
5894
+
5895
+ For example: \`export NO_D1_WARNING=true && wrangler <YOUR COMMAND HERE>\`
5896
+
5897
+ "
5898
+ `);
5899
+ const output = fs.readFileSync("tmp/index.js", "utf-8");
5900
+ expect(output).toContain(
5901
+ `var ExampleDurableObject2 = maskDurableObjectDefinition(ExampleDurableObject);`
5902
+ );
5903
+ expect(output).toContain(
5904
+ `ExampleDurableObject2 as ExampleDurableObject,`
5905
+ );
5906
+ expect(output).toContain(`shim_default as default`);
5907
+ });
5908
+
5909
+ it("should error when detecting a service-worker worker implementing durable objects", async () => {
5910
+ writeWranglerToml({
5911
+ durable_objects: {
5912
+ bindings: [
5913
+ {
5914
+ name: "EXAMPLE_DO_BINDING",
5915
+ class_name: "ExampleDurableObject",
5916
+ },
5917
+ ],
5918
+ },
5919
+ });
5920
+ writeWorkerSource({ type: "sw" });
5921
+ mockSubDomainRequest();
5922
+
5923
+ await expect(runWrangler("publish index.js")).rejects
5924
+ .toThrowErrorMatchingInlineSnapshot(`
5925
+ "You seem to be trying to use Durable Objects in a Worker written as a service-worker.
5926
+ 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:
5927
+ { name = EXAMPLE_DO_BINDING, class_name = ExampleDurableObject } ==> { name = EXAMPLE_DO_BINDING, class_name = ExampleDurableObject, script_name = example-do-binding-worker }
5928
+ Alternatively, migrate your worker to ES Module syntax to implement a Durable Object in this Worker:
5929
+ https://developers.cloudflare.com/workers/learning/migrating-to-module-workers/"
5930
+ `);
5931
+ });
5932
+ });
5933
+
5934
+ describe("[services]", () => {
5935
+ it("should support service bindings", async () => {
5936
+ writeWranglerToml({
5937
+ services: [
5938
+ {
5939
+ binding: "FOO",
5940
+ service: "foo-service",
5941
+ environment: "production",
5942
+ },
5943
+ ],
5944
+ });
5945
+ writeWorkerSource();
5946
+ mockSubDomainRequest();
5947
+ mockUploadWorkerRequest({
5948
+ expectedBindings: [
5949
+ {
5950
+ type: "service",
5951
+ name: "FOO",
5719
5952
  service: "foo-service",
5720
5953
  environment: "production",
5721
5954
  },
@@ -5731,16 +5964,47 @@ addEventListener('fetch', event => {});`
5731
5964
  Uploaded test-name (TIMINGS)
5732
5965
  Published test-name (TIMINGS)
5733
5966
  https://test-name.test-sub-domain.workers.dev
5734
- Current Deployment ID: undefined"
5967
+ Current Deployment ID: Galaxy-Class"
5735
5968
  `);
5736
5969
  expect(std.err).toMatchInlineSnapshot(`""`);
5737
5970
  expect(std.warn).toMatchInlineSnapshot(`
5738
- "▲ [WARNING] Processing wrangler.toml configuration:
5971
+ "▲ [WARNING] Processing wrangler.toml configuration:
5739
5972
 
5740
- - \\"services\\" fields are experimental and may change or break at any time.
5973
+ - \\"services\\" fields are experimental and may change or break at any time.
5741
5974
 
5742
- "
5743
- `);
5975
+ "
5976
+ `);
5977
+ });
5978
+ });
5979
+
5980
+ describe("[analytics_engine_datasets]", () => {
5981
+ it("should support analytics engine bindings", async () => {
5982
+ writeWranglerToml({
5983
+ analytics_engine_datasets: [
5984
+ { binding: "FOO", dataset: "foo-dataset" },
5985
+ ],
5986
+ });
5987
+ writeWorkerSource();
5988
+ mockSubDomainRequest();
5989
+ mockUploadWorkerRequest({
5990
+ expectedBindings: [
5991
+ { dataset: "foo-dataset", name: "FOO", type: "analytics_engine" },
5992
+ ],
5993
+ });
5994
+
5995
+ await runWrangler("publish index.js");
5996
+ expect(std.out).toMatchInlineSnapshot(`
5997
+ "Total Upload: xx KiB / gzip: xx KiB
5998
+ Your worker has access to the following bindings:
5999
+ - Analytics Engine Datasets:
6000
+ - FOO: foo-dataset
6001
+ Uploaded test-name (TIMINGS)
6002
+ Published test-name (TIMINGS)
6003
+ https://test-name.test-sub-domain.workers.dev
6004
+ Current Deployment ID: Galaxy-Class"
6005
+ `);
6006
+ expect(std.err).toMatchInlineSnapshot(`""`);
6007
+ expect(std.warn).toMatchInlineSnapshot(`""`);
5744
6008
  });
5745
6009
  });
5746
6010
 
@@ -5759,7 +6023,7 @@ addEventListener('fetch', event => {});`
5759
6023
  mockUploadWorkerRequest({
5760
6024
  expectedBindings: [
5761
6025
  {
5762
- type: "namespace",
6026
+ type: "dispatch_namespace",
5763
6027
  name: "foo",
5764
6028
  namespace: "Foo",
5765
6029
  },
@@ -5774,16 +6038,10 @@ addEventListener('fetch', event => {});`
5774
6038
  Uploaded test-name (TIMINGS)
5775
6039
  Published test-name (TIMINGS)
5776
6040
  https://test-name.test-sub-domain.workers.dev
5777
- Current Deployment ID: undefined"
6041
+ Current Deployment ID: Galaxy-Class"
5778
6042
  `);
5779
6043
  expect(std.err).toMatchInlineSnapshot(`""`);
5780
- expect(std.warn).toMatchInlineSnapshot(`
5781
- "▲ [WARNING] Processing wrangler.toml configuration:
5782
-
5783
- - \\"dispatch_namespaces\\" fields are experimental and may change or break at any time.
5784
-
5785
- "
5786
- `);
6044
+ expect(std.warn).toMatchInlineSnapshot(`""`);
5787
6045
  });
5788
6046
  });
5789
6047
 
@@ -5798,6 +6056,7 @@ addEventListener('fetch', event => {});`
5798
6056
  param: "binding-param",
5799
6057
  },
5800
6058
  ],
6059
+ metadata: undefined,
5801
6060
  },
5802
6061
  });
5803
6062
  writeWorkerSource();
@@ -5821,16 +6080,16 @@ addEventListener('fetch', event => {});`
5821
6080
  Uploaded test-name (TIMINGS)
5822
6081
  Published test-name (TIMINGS)
5823
6082
  https://test-name.test-sub-domain.workers.dev
5824
- Current Deployment ID: undefined"
6083
+ Current Deployment ID: Galaxy-Class"
5825
6084
  `);
5826
6085
  expect(std.err).toMatchInlineSnapshot(`""`);
5827
6086
  expect(std.warn).toMatchInlineSnapshot(`
5828
- "▲ [WARNING] Processing wrangler.toml configuration:
6087
+ "▲ [WARNING] Processing wrangler.toml configuration:
5829
6088
 
5830
- - \\"unsafe\\" fields are experimental and may change or break at any time.
6089
+ - \\"unsafe\\" fields are experimental and may change or break at any time.
5831
6090
 
5832
- "
5833
- `);
6091
+ "
6092
+ `);
5834
6093
  });
5835
6094
  it("should warn if using unsafe bindings already handled by wrangler", async () => {
5836
6095
  writeWranglerToml({
@@ -5842,6 +6101,7 @@ addEventListener('fetch', event => {});`
5842
6101
  text: "text",
5843
6102
  },
5844
6103
  ],
6104
+ metadata: undefined,
5845
6105
  },
5846
6106
  });
5847
6107
  writeWorkerSource();
@@ -5865,21 +6125,21 @@ addEventListener('fetch', event => {});`
5865
6125
  Uploaded test-name (TIMINGS)
5866
6126
  Published test-name (TIMINGS)
5867
6127
  https://test-name.test-sub-domain.workers.dev
5868
- Current Deployment ID: undefined"
6128
+ Current Deployment ID: Galaxy-Class"
5869
6129
  `);
5870
6130
  expect(std.err).toMatchInlineSnapshot(`""`);
5871
6131
  expect(std.warn).toMatchInlineSnapshot(`
5872
- "▲ [WARNING] Processing wrangler.toml configuration:
6132
+ "▲ [WARNING] Processing wrangler.toml configuration:
5873
6133
 
5874
- - \\"unsafe\\" fields are experimental and may change or break at any time.
5875
- - \\"unsafe.bindings[0]\\": {\\"name\\":\\"my-binding\\",\\"type\\":\\"plain_text\\",\\"text\\":\\"text\\"}
5876
- - The binding type \\"plain_text\\" is directly supported by wrangler.
5877
- Consider migrating this unsafe binding to a format for 'plain_text' bindings that is
5878
- supported by wrangler for optimal support.
5879
- For more details, see https://developers.cloudflare.com/workers/cli-wrangler/configuration
6134
+ - \\"unsafe\\" fields are experimental and may change or break at any time.
6135
+ - \\"unsafe.bindings[0]\\": {\\"name\\":\\"my-binding\\",\\"type\\":\\"plain_text\\",\\"text\\":\\"text\\"}
6136
+ - The binding type \\"plain_text\\" is directly supported by wrangler.
6137
+ Consider migrating this unsafe binding to a format for 'plain_text' bindings that is
6138
+ supported by wrangler for optimal support.
6139
+ For more details, see https://developers.cloudflare.com/workers/cli-wrangler/configuration
5880
6140
 
5881
- "
5882
- `);
6141
+ "
6142
+ `);
5883
6143
  });
5884
6144
  });
5885
6145
  });
@@ -5912,7 +6172,7 @@ addEventListener('fetch', event => {});`
5912
6172
  Uploaded test-name (TIMINGS)
5913
6173
  Published test-name (TIMINGS)
5914
6174
  https://test-name.test-sub-domain.workers.dev
5915
- Current Deployment ID: undefined"
6175
+ Current Deployment ID: Galaxy-Class"
5916
6176
  `);
5917
6177
  expect(std.err).toMatchInlineSnapshot(`""`);
5918
6178
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -5942,7 +6202,7 @@ addEventListener('fetch', event => {});`
5942
6202
  Uploaded test-name (TIMINGS)
5943
6203
  Published test-name (TIMINGS)
5944
6204
  https://test-name.test-sub-domain.workers.dev
5945
- Current Deployment ID: undefined"
6205
+ Current Deployment ID: Galaxy-Class"
5946
6206
  `);
5947
6207
  expect(std.err).toMatchInlineSnapshot(`""`);
5948
6208
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -5976,24 +6236,24 @@ addEventListener('fetch', event => {});`
5976
6236
  Uploaded test-name (TIMINGS)
5977
6237
  Published test-name (TIMINGS)
5978
6238
  https://test-name.test-sub-domain.workers.dev
5979
- Current Deployment ID: undefined"
6239
+ Current Deployment ID: Galaxy-Class"
5980
6240
  `);
5981
6241
  expect(std.err).toMatchInlineSnapshot(`""`);
5982
6242
  expect(std.warn).toMatchInlineSnapshot(`
5983
- "▲ [WARNING] Processing wrangler.toml configuration:
6243
+ "▲ [WARNING] Processing wrangler.toml configuration:
5984
6244
 
5985
- - Deprecation: The \`build.upload.rules\` config field is no longer used, the rules should be
5986
- specified via the \`rules\` config field. Delete the \`build.upload\` field from the configuration
5987
- file, and add this:
5988
- \`\`\`
5989
- [[rules]]
5990
- type = \\"Text\\"
5991
- globs = [ \\"**/*.file\\" ]
5992
- fallthrough = true
5993
- \`\`\`
6245
+ - Deprecation: The \`build.upload.rules\` config field is no longer used, the rules should be
6246
+ specified via the \`rules\` config field. Delete the \`build.upload\` field from the configuration
6247
+ file, and add this:
6248
+ \`\`\`
6249
+ [[rules]]
6250
+ type = \\"Text\\"
6251
+ globs = [ \\"**/*.file\\" ]
6252
+ fallthrough = true
6253
+ \`\`\`
5994
6254
 
5995
- "
5996
- `);
6255
+ "
6256
+ `);
5997
6257
  });
5998
6258
 
5999
6259
  it("should be able to use fallthrough:true for multiple rules", async () => {
@@ -6026,7 +6286,7 @@ addEventListener('fetch', event => {});`
6026
6286
  Uploaded test-name (TIMINGS)
6027
6287
  Published test-name (TIMINGS)
6028
6288
  https://test-name.test-sub-domain.workers.dev
6029
- Current Deployment ID: undefined"
6289
+ Current Deployment ID: Galaxy-Class"
6030
6290
  `);
6031
6291
  expect(std.err).toMatchInlineSnapshot(`""`);
6032
6292
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -6124,7 +6384,7 @@ addEventListener('fetch', event => {});`
6124
6384
  Uploaded test-name (TIMINGS)
6125
6385
  Published test-name (TIMINGS)
6126
6386
  https://test-name.test-sub-domain.workers.dev
6127
- Current Deployment ID: undefined"
6387
+ Current Deployment ID: Galaxy-Class"
6128
6388
  `);
6129
6389
  expect(std.err).toMatchInlineSnapshot(`""`);
6130
6390
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -6155,14 +6415,14 @@ addEventListener('fetch', event => {});`
6155
6415
  Uploaded test-name (TIMINGS)
6156
6416
  Published test-name (TIMINGS)
6157
6417
  https://test-name.test-sub-domain.workers.dev
6158
- Current Deployment ID: undefined"
6418
+ Current Deployment ID: Galaxy-Class"
6159
6419
  `);
6160
6420
  expect(std.err).toMatchInlineSnapshot(`""`);
6161
6421
  expect(std.warn).toMatchInlineSnapshot(`
6162
- "▲ [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\\";
6422
+ "▲ [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\\";
6163
6423
 
6164
- "
6165
- `);
6424
+ "
6425
+ `);
6166
6426
  });
6167
6427
 
6168
6428
  it("should work with legacy module specifiers, with a deprecation warning (2)", async () => {
@@ -6185,14 +6445,14 @@ addEventListener('fetch', event => {});`
6185
6445
  Uploaded test-name (TIMINGS)
6186
6446
  Published test-name (TIMINGS)
6187
6447
  https://test-name.test-sub-domain.workers.dev
6188
- Current Deployment ID: undefined"
6448
+ Current Deployment ID: Galaxy-Class"
6189
6449
  `);
6190
6450
  expect(std.err).toMatchInlineSnapshot(`""`);
6191
6451
  expect(std.warn).toMatchInlineSnapshot(`
6192
- "▲ [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\\";
6452
+ "▲ [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\\";
6193
6453
 
6194
- "
6195
- `);
6454
+ "
6455
+ `);
6196
6456
  });
6197
6457
 
6198
6458
  it("should work with legacy module specifiers, with a deprecation warning (3)", async () => {
@@ -6217,18 +6477,18 @@ addEventListener('fetch', event => {});`
6217
6477
  Uploaded test-name (TIMINGS)
6218
6478
  Published test-name (TIMINGS)
6219
6479
  https://test-name.test-sub-domain.workers.dev
6220
- Current Deployment ID: undefined"
6480
+ Current Deployment ID: Galaxy-Class"
6221
6481
  `);
6222
6482
  expect(std.err).toMatchInlineSnapshot(`""`);
6223
6483
  expect(std.warn).toMatchInlineSnapshot(`
6224
- "▲ [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\\";
6484
+ "▲ [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\\";
6225
6485
 
6226
- "
6227
- `);
6486
+ "
6487
+ `);
6228
6488
  });
6229
6489
 
6230
6490
  it("should not match regular module specifiers when there aren't any possible legacy module matches", async () => {
6231
- // see https://github.com/cloudflare/wrangler2/issues/655 for bug details
6491
+ // see https://github.com/cloudflare/workers-sdk/issues/655 for bug details
6232
6492
 
6233
6493
  fs.writeFileSync(
6234
6494
  "./index.js",
@@ -6247,7 +6507,7 @@ addEventListener('fetch', event => {});`
6247
6507
  Uploaded test-name (TIMINGS)
6248
6508
  Published test-name (TIMINGS)
6249
6509
  https://test-name.test-sub-domain.workers.dev
6250
- Current Deployment ID: undefined"
6510
+ Current Deployment ID: Galaxy-Class"
6251
6511
  `);
6252
6512
  expect(std.err).toMatchInlineSnapshot(`""`);
6253
6513
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -6285,19 +6545,33 @@ addEventListener('fetch', event => {});`
6285
6545
  Object {
6286
6546
  "debug": "",
6287
6547
  "err": "",
6548
+ "info": "",
6288
6549
  "out": "Total Upload: xx KiB / gzip: xx KiB
6289
6550
  Uploaded test-name (TIMINGS)
6290
6551
  Published test-name (TIMINGS)
6291
6552
  https://test-name.test-sub-domain.workers.dev
6292
- Current Deployment ID: undefined",
6553
+ Current Deployment ID: Galaxy-Class",
6293
6554
  "warn": "",
6294
6555
  }
6295
6556
  `);
6296
6557
  });
6297
6558
 
6298
- it("should output to target es2020 even if tsconfig says otherwise", async () => {
6559
+ it("should output to target es2022 even if tsconfig says otherwise", async () => {
6299
6560
  writeWranglerToml();
6300
6561
  writeWorkerSource();
6562
+ fs.writeFileSync(
6563
+ "./index.js",
6564
+ `
6565
+ import { foo } from "./another";
6566
+ const topLevelAwait = await new Promise((resolve) => setTimeout(resolve, 0));
6567
+
6568
+ export default {
6569
+ async fetch(request) {
6570
+
6571
+ return new Response("Hello world!");
6572
+ },
6573
+ };`
6574
+ );
6301
6575
  fs.writeFileSync(
6302
6576
  "tsconfig.json",
6303
6577
  JSON.stringify({
@@ -6308,19 +6582,26 @@ addEventListener('fetch', event => {});`
6308
6582
  })
6309
6583
  );
6310
6584
  mockSubDomainRequest();
6585
+ /**
6586
+ * When we compile with es2022, we should preserve the export statement and top level await
6587
+ * If you attempt to target es2020 top level await will cause a build error
6588
+ * @error Build failed with 1 error:
6589
+ * index.js:3:25: ERROR: Top-level await is not available in the configured target environment ("es2020")
6590
+ */
6311
6591
  mockUploadWorkerRequest({
6312
- expectedEntry: "export {", // just check that the export is preserved
6592
+ expectedEntry: "export {", // check that the export is preserved
6313
6593
  });
6314
6594
  await runWrangler("publish index.js"); // this would throw if we tried to compile with es5
6315
6595
  expect(std).toMatchInlineSnapshot(`
6316
6596
  Object {
6317
6597
  "debug": "",
6318
6598
  "err": "",
6599
+ "info": "",
6319
6600
  "out": "Total Upload: xx KiB / gzip: xx KiB
6320
6601
  Uploaded test-name (TIMINGS)
6321
6602
  Published test-name (TIMINGS)
6322
6603
  https://test-name.test-sub-domain.workers.dev
6323
- Current Deployment ID: undefined",
6604
+ Current Deployment ID: Galaxy-Class",
6324
6605
  "warn": "",
6325
6606
  }
6326
6607
  `);
@@ -6340,11 +6621,110 @@ addEventListener('fetch', event => {});`
6340
6621
  Object {
6341
6622
  "debug": "",
6342
6623
  "err": "",
6624
+ "info": "",
6625
+ "out": "Total Upload: xx KiB / gzip: xx KiB
6626
+ Uploaded test-name (TIMINGS)
6627
+ Published test-name (TIMINGS)
6628
+ https://test-name.test-sub-domain.workers.dev
6629
+ Current Deployment ID: Galaxy-Class",
6630
+ "warn": "",
6631
+ }
6632
+ `);
6633
+ });
6634
+
6635
+ it("should preserve the entry point file name, even when using a facade", async () => {
6636
+ writeWranglerToml();
6637
+ writeWorkerSource();
6638
+ mockSubDomainRequest();
6639
+ mockUploadWorkerRequest();
6640
+ const assets = [
6641
+ { filePath: "file-1.txt", content: "Content of file-1" },
6642
+ { filePath: "file-2.txt", content: "Content of file-2" },
6643
+ ];
6644
+ const kvNamespace = {
6645
+ title: "__test-name-workers_sites_assets",
6646
+ id: "__test-name-workers_sites_assets-id",
6647
+ };
6648
+ writeAssets(assets);
6649
+ mockListKVNamespacesRequest(kvNamespace);
6650
+ mockKeyListRequest(kvNamespace.id, []);
6651
+ mockUploadAssetsToKVRequest(kvNamespace.id, assets);
6652
+ await runWrangler("publish index.js --outdir some-dir --assets assets");
6653
+ expect(fs.existsSync("some-dir/index.js")).toBe(true);
6654
+ expect(fs.existsSync("some-dir/index.js.map")).toBe(true);
6655
+ expect(std).toMatchInlineSnapshot(`
6656
+ Object {
6657
+ "debug": "",
6658
+ "err": "",
6659
+ "info": "",
6660
+ "out": "Reading file-1.txt...
6661
+ Uploading as file-1.2ca234f380.txt...
6662
+ Reading file-2.txt...
6663
+ Uploading as file-2.5938485188.txt...
6664
+ ↗️ Done syncing assets
6665
+ Total Upload: xx KiB / gzip: xx KiB
6666
+ Uploaded test-name (TIMINGS)
6667
+ Published test-name (TIMINGS)
6668
+ https://test-name.test-sub-domain.workers.dev
6669
+ Current Deployment ID: Galaxy-Class",
6670
+ "warn": "▲ [WARNING] The --assets argument is experimental and may change or break at any time
6671
+
6672
+ ",
6673
+ }
6674
+ `);
6675
+ });
6676
+
6677
+ it("should copy any module imports related assets to --outdir if specified", async () => {
6678
+ writeWranglerToml();
6679
+ fs.writeFileSync(
6680
+ "./index.js",
6681
+ `
6682
+ import txt from './textfile.txt';
6683
+ import hello from './hello.wasm';
6684
+ export default{
6685
+ async fetch(){
6686
+ const module = await WebAssembly.instantiate(hello);
6687
+ return new Response(txt + module.exports.hello);
6688
+ }
6689
+ }
6690
+ `
6691
+ );
6692
+ fs.writeFileSync("./textfile.txt", "Hello, World!");
6693
+ fs.writeFileSync("./hello.wasm", "Hello wasm World!");
6694
+ mockSubDomainRequest();
6695
+ mockUploadWorkerRequest({
6696
+ expectedModules: {
6697
+ "./0a0a9f2a6772942557ab5355d76af442f8f65e01-textfile.txt":
6698
+ "Hello, World!",
6699
+ "./d025a03cd31e98e96fb5bd5bce87f9bca4e8ce2c-hello.wasm":
6700
+ "Hello wasm World!",
6701
+ },
6702
+ });
6703
+ await runWrangler("publish index.js --outdir some-dir");
6704
+
6705
+ expect(fs.existsSync("some-dir/index.js")).toBe(true);
6706
+ expect(fs.existsSync("some-dir/index.js.map")).toBe(true);
6707
+ expect(fs.existsSync("some-dir/README.md")).toBe(true);
6708
+ expect(
6709
+ fs.existsSync(
6710
+ "some-dir/0a0a9f2a6772942557ab5355d76af442f8f65e01-textfile.txt"
6711
+ )
6712
+ ).toBe(true);
6713
+ expect(
6714
+ fs.existsSync(
6715
+ "some-dir/d025a03cd31e98e96fb5bd5bce87f9bca4e8ce2c-hello.wasm"
6716
+ )
6717
+ ).toBe(true);
6718
+ expect(std).toMatchInlineSnapshot(`
6719
+ Object {
6720
+ "debug": "",
6721
+ "err": "",
6722
+ "info": "",
6343
6723
  "out": "Total Upload: xx KiB / gzip: xx KiB
6344
6724
  Uploaded test-name (TIMINGS)
6345
6725
  Published test-name (TIMINGS)
6346
6726
  https://test-name.test-sub-domain.workers.dev
6347
- Current Deployment ID: undefined",
6727
+ Current Deployment ID: Galaxy-Class",
6348
6728
  "warn": "",
6349
6729
  }
6350
6730
  `);
@@ -6368,6 +6748,7 @@ addEventListener('fetch', event => {});`
6368
6748
  Object {
6369
6749
  "debug": "",
6370
6750
  "err": "",
6751
+ "info": "",
6371
6752
  "out": "Total Upload: xx KiB / gzip: xx KiB
6372
6753
  Your worker has access to the following bindings:
6373
6754
  - Durable Objects:
@@ -6385,16 +6766,17 @@ addEventListener('fetch', event => {});`
6385
6766
  writeWorkerSource();
6386
6767
  await runWrangler("publish index.js --node-compat --dry-run");
6387
6768
  expect(std).toMatchInlineSnapshot(`
6388
- Object {
6389
- "debug": "",
6390
- "err": "",
6391
- "out": "Total Upload: xx KiB / gzip: xx KiB
6392
- --dry-run: exiting now.",
6393
- "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.
6394
-
6395
- ",
6396
- }
6397
- `);
6769
+ Object {
6770
+ "debug": "",
6771
+ "err": "",
6772
+ "info": "",
6773
+ "out": "Total Upload: xx KiB / gzip: xx KiB
6774
+ --dry-run: exiting now.",
6775
+ "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.
6776
+
6777
+ ",
6778
+ }
6779
+ `);
6398
6780
  });
6399
6781
 
6400
6782
  it("should recommend node compatibility mode when using node builtins and node-compat isn't enabled", async () => {
@@ -6432,31 +6814,105 @@ addEventListener('fetch', event => {});`
6432
6814
  );
6433
6815
  await runWrangler("publish index.js --node-compat --dry-run"); // this would throw if node compatibility didn't exist
6434
6816
  expect(std).toMatchInlineSnapshot(`
6435
- Object {
6436
- "debug": "",
6437
- "err": "",
6438
- "out": "Total Upload: xx KiB / gzip: xx KiB
6439
- --dry-run: exiting now.",
6440
- "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.
6441
-
6442
- ",
6443
- }
6444
- `);
6817
+ Object {
6818
+ "debug": "",
6819
+ "err": "",
6820
+ "info": "",
6821
+ "out": "Total Upload: xx KiB / gzip: xx KiB
6822
+ --dry-run: exiting now.",
6823
+ "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.
6824
+
6825
+ ",
6826
+ }
6827
+ `);
6445
6828
  });
6446
6829
  });
6447
6830
 
6448
- describe("bundle reporter", () => {
6449
- it("should print the bundle size", async () => {
6831
+ describe("`nodejs_compat` compatibility flag", () => {
6832
+ it('when absent, should error on any "external" `node:*` imports', async () => {
6833
+ writeWranglerToml();
6450
6834
  fs.writeFileSync(
6451
- "./text.txt",
6452
- `${new Array(100)
6453
- .fill("Try not. Do or do not. There is no try.")
6454
- .join("")}`
6835
+ "index.js",
6836
+ `
6837
+ import AsyncHooks from 'node:async_hooks';
6838
+ console.log(AsyncHooks);
6839
+ export default {}
6840
+ `
6455
6841
  );
6456
-
6457
- fs.writeFileSync(
6458
- "./hello.html",
6459
- `<!DOCTYPE html>
6842
+ let err: esbuild.BuildFailure | undefined;
6843
+ try {
6844
+ await runWrangler("publish index.js --dry-run"); // expecting this to throw, as node compatibility isn't enabled
6845
+ } catch (e) {
6846
+ err = e as esbuild.BuildFailure;
6847
+ }
6848
+ expect(
6849
+ esbuild.formatMessagesSync(err?.errors ?? [], { kind: "error" }).join()
6850
+ ).toMatch(/Could not resolve "node:async_hooks"/);
6851
+ });
6852
+
6853
+ it('when present, should support any "external" `node:*` imports', async () => {
6854
+ writeWranglerToml();
6855
+ fs.writeFileSync(
6856
+ "index.js",
6857
+ `
6858
+ import AsyncHooks from 'node:async_hooks';
6859
+ console.log(AsyncHooks);
6860
+ export default {}
6861
+ `
6862
+ );
6863
+
6864
+ await runWrangler(
6865
+ "publish index.js --dry-run --outdir=dist --compatibility-flag=nodejs_compat"
6866
+ );
6867
+
6868
+ expect(std).toMatchInlineSnapshot(`
6869
+ Object {
6870
+ "debug": "",
6871
+ "err": "",
6872
+ "info": "",
6873
+ "out": "Total Upload: xx KiB / gzip: xx KiB
6874
+ --dry-run: exiting now.",
6875
+ "warn": "",
6876
+ }
6877
+ `);
6878
+ expect(fs.readFileSync("dist/index.js", { encoding: "utf-8" })).toContain(
6879
+ `import AsyncHooks from "node:async_hooks";`
6880
+ );
6881
+ });
6882
+
6883
+ it("should conflict with the --node-compat option", async () => {
6884
+ writeWranglerToml();
6885
+ fs.writeFileSync(
6886
+ "index.js",
6887
+ `
6888
+ import AsyncHooks from 'node:async_hooks';
6889
+ console.log(AsyncHooks);
6890
+ export default {}
6891
+ `
6892
+ );
6893
+
6894
+ await expect(
6895
+ runWrangler(
6896
+ "publish index.js --dry-run --outdir=dist --compatibility-flag=nodejs_compat --node-compat"
6897
+ )
6898
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
6899
+ `"The \`nodejs_compat\` compatibility flag cannot be used in conjunction with the legacy \`--node-compat\` flag. If you want to use the Workers runtime Node.js compatibility features, please remove the \`--node-compat\` argument from your CLI command or \`node_compat = true\` from your config file."`
6900
+ );
6901
+ });
6902
+ });
6903
+
6904
+ describe("bundle reporter", () => {
6905
+ it("should print the bundle size", async () => {
6906
+ fs.writeFileSync(
6907
+ "./text.txt",
6908
+ `${new Array(100)
6909
+ .fill("Try not. Do or do not. There is no try.")
6910
+ .join("")}`
6911
+ );
6912
+
6913
+ fs.writeFileSync(
6914
+ "./hello.html",
6915
+ `<!DOCTYPE html>
6460
6916
  <html>
6461
6917
  <body>
6462
6918
  <h2>Hello World!</h2>
@@ -6481,34 +6937,45 @@ addEventListener('fetch', event => {});`
6481
6937
  mockSubDomainRequest();
6482
6938
  mockUploadWorkerRequest();
6483
6939
  await runWrangler("publish");
6940
+
6484
6941
  expect(std).toMatchInlineSnapshot(`
6485
6942
  Object {
6486
6943
  "debug": "",
6487
6944
  "err": "",
6945
+ "info": "",
6488
6946
  "out": "Total Upload: xx KiB / gzip: xx KiB
6489
6947
  Uploaded test-name (TIMINGS)
6490
6948
  Published test-name (TIMINGS)
6491
6949
  https://test-name.test-sub-domain.workers.dev
6492
- Current Deployment ID: undefined",
6950
+ Current Deployment ID: Galaxy-Class",
6493
6951
  "warn": "",
6494
6952
  }
6495
6953
  `);
6496
6954
  });
6497
6955
 
6498
6956
  it("should print the bundle size, with API errors", async () => {
6499
- setMockRawResponse(
6500
- "/accounts/:accountId/workers/scripts/:scriptName",
6501
- "PUT",
6502
- () => {
6503
- return createFetchResult({}, false, [
6504
- {
6505
- code: 11337,
6506
- message:
6507
- "Script startup timed out. This could be due to script exceeding size limits or expensive code in the global scope.",
6508
- },
6509
- ]);
6510
- }
6957
+ mockSubDomainRequest();
6958
+ mockUploadWorkerRequest();
6959
+ // Override PUT call to error out from previous helper functions
6960
+ msw.use(
6961
+ rest.put(
6962
+ "*/accounts/:accountId/workers/scripts/:scriptName",
6963
+ (_, res, ctx) => {
6964
+ return res(
6965
+ ctx.json(
6966
+ createFetchResult(null, false, [
6967
+ {
6968
+ code: 11337,
6969
+ message:
6970
+ "Script startup timed out. This could be due to script exceeding size limits or expensive code in the global scope.",
6971
+ },
6972
+ ])
6973
+ )
6974
+ );
6975
+ }
6976
+ )
6511
6977
  );
6978
+
6512
6979
  fs.writeFileSync(
6513
6980
  "./hello.html",
6514
6981
  `<!DOCTYPE html>
@@ -6529,35 +6996,57 @@ addEventListener('fetch', event => {});`
6529
6996
  },
6530
6997
  };`
6531
6998
  );
6999
+
6532
7000
  writeWranglerToml({
6533
7001
  main: "index.js",
6534
7002
  });
6535
- mockSubDomainRequest();
6536
- mockUploadWorkerRequest();
7003
+
6537
7004
  await expect(runWrangler("publish")).rejects.toMatchInlineSnapshot(
6538
7005
  `[ParseError: A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name) failed.]`
6539
7006
  );
6540
7007
  expect(std).toMatchInlineSnapshot(`
6541
- Object {
6542
- "debug": "",
6543
- "err": "",
6544
- "out": "Total Upload: xx KiB / gzip: xx KiB
7008
+ Object {
7009
+ "debug": "",
7010
+ "err": "",
7011
+ "info": "",
7012
+ "out": "Total Upload: xx KiB / gzip: xx KiB
6545
7013
 
6546
- X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name) failed.
7014
+ X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name) failed.
6547
7015
 
6548
- Script startup timed out. This could be due to script exceeding size limits or expensive code in
6549
- the global scope. [code: 11337]
7016
+ Script startup timed out. This could be due to script exceeding size limits or expensive code in
7017
+ the global scope. [code: 11337]
6550
7018
 
6551
- If you think this is a bug, please open an issue at:
6552
- https://github.com/cloudflare/wrangler2/issues/new/choose
7019
+ If you think this is a bug, please open an issue at:
7020
+ https://github.com/cloudflare/workers-sdk/issues/new/choose
6553
7021
 
6554
- ",
6555
- "warn": "",
6556
- }
6557
- `);
7022
+ ",
7023
+ "warn": "",
7024
+ }
7025
+ `);
6558
7026
  });
6559
7027
 
6560
7028
  test("should check biggest dependencies when upload fails with script size error", async () => {
7029
+ mockSubDomainRequest();
7030
+ mockUploadWorkerRequest();
7031
+ // Override PUT call to error out from previous helper functions
7032
+ msw.use(
7033
+ rest.put(
7034
+ "*/accounts/:accountId/workers/scripts/:scriptName",
7035
+ (req, res, ctx) => {
7036
+ return res(
7037
+ ctx.json(
7038
+ createFetchResult({}, false, [
7039
+ {
7040
+ code: 10027,
7041
+ message: "workers.api.error.script_too_large",
7042
+ },
7043
+ ])
7044
+ )
7045
+ );
7046
+ }
7047
+ )
7048
+ );
7049
+
6561
7050
  fs.writeFileSync("dependency.js", `export const thing = "a string dep";`);
6562
7051
 
6563
7052
  fs.writeFileSync(
@@ -6570,27 +7059,20 @@ addEventListener('fetch', event => {});`
6570
7059
  }
6571
7060
  }`
6572
7061
  );
6573
- setMockRawResponse(
6574
- "/accounts/:accountId/workers/scripts/:scriptName",
6575
- "PUT",
6576
- () => {
6577
- return createFetchResult({}, false, [
6578
- { code: 10027, message: "workers.api.error.script_too_large" },
6579
- ]);
6580
- }
6581
- );
7062
+
6582
7063
  writeWranglerToml({
6583
7064
  main: "index.js",
6584
7065
  });
6585
- mockSubDomainRequest();
6586
- mockUploadWorkerRequest();
7066
+
6587
7067
  await expect(runWrangler("publish")).rejects.toMatchInlineSnapshot(
6588
7068
  `[ParseError: A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name) failed.]`
6589
7069
  );
7070
+
6590
7071
  expect(std).toMatchInlineSnapshot(`
6591
7072
  Object {
6592
7073
  "debug": "",
6593
7074
  "err": "",
7075
+ "info": "",
6594
7076
  "out": "Total Upload: xx KiB / gzip: xx KiB
6595
7077
 
6596
7078
  X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name) failed.
@@ -6598,7 +7080,7 @@ addEventListener('fetch', event => {});`
6598
7080
  workers.api.error.script_too_large [code: 10027]
6599
7081
 
6600
7082
  If you think this is a bug, please open an issue at:
6601
- https://github.com/cloudflare/wrangler2/issues/new/choose
7083
+ https://github.com/cloudflare/workers-sdk/issues/new/choose
6602
7084
 
6603
7085
  ",
6604
7086
  "warn": "▲ [WARNING] Here are the 2 largest dependencies included in your script:
@@ -6612,7 +7094,27 @@ addEventListener('fetch', event => {});`
6612
7094
  `);
6613
7095
  });
6614
7096
 
6615
- test("should check biggest dependencies when upload fails with script startup error", async () => {
7097
+ test("should offer some helpful advice when upload fails with script startup error", async () => {
7098
+ mockSubDomainRequest();
7099
+ mockUploadWorkerRequest();
7100
+ // Override PUT call to error out from previous helper functions
7101
+ msw.use(
7102
+ rest.put(
7103
+ "*/accounts/:accountId/workers/scripts/:scriptName",
7104
+ (req, res, ctx) => {
7105
+ return res(
7106
+ ctx.json(
7107
+ createFetchResult({}, false, [
7108
+ {
7109
+ code: 10021,
7110
+ message: "Error: Script startup exceeded CPU time limit.",
7111
+ },
7112
+ ])
7113
+ )
7114
+ );
7115
+ }
7116
+ )
7117
+ );
6616
7118
  fs.writeFileSync("dependency.js", `export const thing = "a string dep";`);
6617
7119
 
6618
7120
  fs.writeFileSync(
@@ -6625,23 +7127,11 @@ addEventListener('fetch', event => {});`
6625
7127
  }
6626
7128
  }`
6627
7129
  );
6628
- setMockRawResponse(
6629
- "/accounts/:accountId/workers/scripts/:scriptName",
6630
- "PUT",
6631
- () => {
6632
- return createFetchResult({}, false, [
6633
- {
6634
- code: 10021,
6635
- message: "Error: Script startup exceeded CPU time limit.",
6636
- },
6637
- ]);
6638
- }
6639
- );
7130
+
6640
7131
  writeWranglerToml({
6641
7132
  main: "index.js",
6642
7133
  });
6643
- mockSubDomainRequest();
6644
- mockUploadWorkerRequest();
7134
+
6645
7135
  await expect(runWrangler("publish")).rejects.toMatchInlineSnapshot(
6646
7136
  `[ParseError: A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name) failed.]`
6647
7137
  );
@@ -6649,6 +7139,7 @@ addEventListener('fetch', event => {});`
6649
7139
  Object {
6650
7140
  "debug": "",
6651
7141
  "err": "",
7142
+ "info": "",
6652
7143
  "out": "Total Upload: xx KiB / gzip: xx KiB
6653
7144
 
6654
7145
  X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name) failed.
@@ -6656,14 +7147,16 @@ addEventListener('fetch', event => {});`
6656
7147
  Error: Script startup exceeded CPU time limit. [code: 10021]
6657
7148
 
6658
7149
  If you think this is a bug, please open an issue at:
6659
- https://github.com/cloudflare/wrangler2/issues/new/choose
7150
+ https://github.com/cloudflare/workers-sdk/issues/new/choose
6660
7151
 
6661
7152
  ",
6662
- "warn": "▲ [WARNING] Here are the 2 largest dependencies included in your script:
7153
+ "warn": "▲ [WARNING] Your Worker failed validation because it exceeded startup limits.
6663
7154
 
6664
- - index.js - xx KiB
6665
- - dependency.js - xx KiB
6666
- If these are unnecessary, consider removing them
7155
+ To ensure fast responses, we place constraints on Worker startup -- like how much CPU it can use,
7156
+ or how long it can take.
7157
+ Your Worker failed validation, which means it hit one of these startup limits.
7158
+ Try reducing the amount of work done during startup (outside the event handler), either by
7159
+ removing code or relocating it inside the event handler.
6667
7160
 
6668
7161
  ",
6669
7162
  }
@@ -6685,6 +7178,7 @@ addEventListener('fetch', event => {});`
6685
7178
  Object {
6686
7179
  "debug": "",
6687
7180
  "err": "",
7181
+ "info": "",
6688
7182
  "out": "Total Upload: xx KiB / gzip: xx KiB",
6689
7183
  "warn": "▲ [WARNING] We recommend keeping your script less than 1MiB (1024 KiB) after gzip. Exceeding past this can affect cold start time
6690
7184
 
@@ -6707,6 +7201,7 @@ addEventListener('fetch', event => {});`
6707
7201
  Object {
6708
7202
  "debug": "",
6709
7203
  "err": "",
7204
+ "info": "",
6710
7205
  "out": "Total Upload: xx KiB / gzip: xx KiB",
6711
7206
  "warn": "",
6712
7207
  }
@@ -6735,6 +7230,7 @@ addEventListener('fetch', event => {});`
6735
7230
  Object {
6736
7231
  "debug": "",
6737
7232
  "err": "",
7233
+ "info": "",
6738
7234
  "out": "",
6739
7235
  "warn": "▲ [WARNING] Here are the 5 largest dependencies included in your script:
6740
7236
 
@@ -6824,7 +7320,7 @@ addEventListener('fetch', event => {});`
6824
7320
  "publish index.js --no-bundle --node-compat --dry-run --outdir dist"
6825
7321
  );
6826
7322
  expect(std.warn).toMatchInlineSnapshot(`
6827
- "▲ [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.
7323
+ "▲ [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.
6828
7324
 
6829
7325
 
6830
7326
  ▲ [WARNING] \`--node-compat\` and \`--no-bundle\` can't be used together. If you want to polyfill Node.js built-ins and disable Wrangler's bundling, please polyfill as part of your own bundling process.
@@ -6844,7 +7340,7 @@ addEventListener('fetch', event => {});`
6844
7340
  fs.writeFileSync("index.js", scriptContent);
6845
7341
  await runWrangler("publish index.js --dry-run --outdir dist");
6846
7342
  expect(std.warn).toMatchInlineSnapshot(`
6847
- "▲ [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.
7343
+ "▲ [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.
6848
7344
 
6849
7345
 
6850
7346
  ▲ [WARNING] \`--node-compat\` and \`--no-bundle\` can't be used together. If you want to polyfill Node.js built-ins and disable Wrangler's bundling, please polyfill as part of your own bundling process.
@@ -6854,63 +7350,37 @@ addEventListener('fetch', event => {});`
6854
7350
  });
6855
7351
  });
6856
7352
 
6857
- it("should publish if the last deployed source check fails", async () => {
6858
- unsetAllMocks();
6859
- writeWorkerSource();
6860
- writeWranglerToml();
6861
- mockSubDomainRequest();
6862
- mockUploadWorkerRequest();
6863
- setMockResponse(
6864
- "/accounts/:accountId/workers/deployments/by-script/:scriptTag",
6865
- () => ({
6866
- latest: { number: "2" },
6867
- })
6868
- );
6869
- setMockRawResponse(
6870
- "/accounts/:accountId/workers/services/:scriptName",
6871
- "GET",
6872
- () => {
6873
- return createFetchResult(null, false, [
6874
- { code: 10090, message: "workers.api.error.service_not_found" },
6875
- ]);
6876
- }
6877
- );
6878
-
6879
- await runWrangler("publish index.js");
6880
- expect(std).toMatchInlineSnapshot(`
6881
- Object {
6882
- "debug": "",
6883
- "err": "",
6884
- "out": "Total Upload: xx KiB / gzip: xx KiB
6885
- Uploaded test-name (TIMINGS)
6886
- Published test-name (TIMINGS)
6887
- https://test-name.test-sub-domain.workers.dev
6888
- Current Deployment ID: undefined",
6889
- "warn": "",
6890
- }
6891
- `);
6892
- });
6893
-
6894
7353
  it("should not publish if there's any other kind of error when checking deployment source", async () => {
6895
- unsetAllMocks();
6896
7354
  writeWorkerSource();
6897
7355
  writeWranglerToml();
6898
7356
  mockSubDomainRequest();
6899
7357
  mockUploadWorkerRequest();
6900
- setMockRawResponse(
6901
- "/accounts/:accountId/workers/services/:scriptName",
6902
- "GET",
6903
- () => {
6904
- return createFetchResult(null, false, [
6905
- { code: 10000, message: "Authentication error" },
6906
- ]);
6907
- }
6908
- );
6909
- setMockResponse(
6910
- "/accounts/:accountId/workers/deployments/by-script/:scriptTag",
6911
- () => ({
6912
- latest: { number: "2" },
6913
- })
7358
+
7359
+ msw.use(
7360
+ rest.get(
7361
+ "*/accounts/:accountId/workers/services/:scriptName",
7362
+ (_, res, ctx) => {
7363
+ return res(
7364
+ ctx.json(
7365
+ createFetchResult(null, false, [
7366
+ { code: 10000, message: "Authentication error" },
7367
+ ])
7368
+ )
7369
+ );
7370
+ }
7371
+ ),
7372
+ rest.get(
7373
+ "*/accounts/:accountId/workers/deployments/by-script/:scriptTag",
7374
+ (_, res, ctx) => {
7375
+ return res(
7376
+ ctx.json(
7377
+ createFetchResult({
7378
+ latest: { number: "2" },
7379
+ })
7380
+ )
7381
+ );
7382
+ }
7383
+ )
6914
7384
  );
6915
7385
 
6916
7386
  await runWrangler("publish index.js");
@@ -6948,7 +7418,7 @@ addEventListener('fetch', event => {});`
6948
7418
  Uploaded test-name (TIMINGS)
6949
7419
  Published test-name (TIMINGS)
6950
7420
  https://test-name.test-sub-domain.workers.dev
6951
- Current Deployment ID: undefined"
7421
+ Current Deployment ID: Galaxy-Class"
6952
7422
  `);
6953
7423
  });
6954
7424
 
@@ -6985,7 +7455,84 @@ addEventListener('fetch', event => {});`
6985
7455
  Published test-name (TIMINGS)
6986
7456
  https://test-name.test-sub-domain.workers.dev
6987
7457
  Consumer for queue1
6988
- Current Deployment ID: undefined"
7458
+ Current Deployment ID: Galaxy-Class"
7459
+ `);
7460
+ });
7461
+
7462
+ it("should support queue consumer concurrency with a max concurrency specified", async () => {
7463
+ writeWranglerToml({
7464
+ queues: {
7465
+ consumers: [
7466
+ {
7467
+ queue: "queue1",
7468
+ dead_letter_queue: "myDLQ",
7469
+ max_batch_size: 5,
7470
+ max_batch_timeout: 3,
7471
+ max_retries: 10,
7472
+ max_concurrency: 5,
7473
+ },
7474
+ ],
7475
+ },
7476
+ });
7477
+ await fs.promises.writeFile("index.js", `export default {};`);
7478
+ mockSubDomainRequest();
7479
+ mockUploadWorkerRequest();
7480
+ mockGetQueue("queue1");
7481
+ mockPutQueueConsumer("queue1", "test-name", {
7482
+ dead_letter_queue: "myDLQ",
7483
+ settings: {
7484
+ batch_size: 5,
7485
+ max_retries: 10,
7486
+ max_wait_time_ms: 3000,
7487
+ max_concurrency: 5,
7488
+ },
7489
+ });
7490
+ await runWrangler("publish index.js");
7491
+ expect(std.out).toMatchInlineSnapshot(`
7492
+ "Total Upload: xx KiB / gzip: xx KiB
7493
+ Uploaded test-name (TIMINGS)
7494
+ Published test-name (TIMINGS)
7495
+ https://test-name.test-sub-domain.workers.dev
7496
+ Consumer for queue1
7497
+ Current Deployment ID: Galaxy-Class"
7498
+ `);
7499
+ });
7500
+
7501
+ it("should support queue consumer concurrency with a null max concurrency", async () => {
7502
+ writeWranglerToml({
7503
+ queues: {
7504
+ consumers: [
7505
+ {
7506
+ queue: "queue1",
7507
+ dead_letter_queue: "myDLQ",
7508
+ max_batch_size: 5,
7509
+ max_batch_timeout: 3,
7510
+ max_retries: 10,
7511
+ max_concurrency: null,
7512
+ },
7513
+ ],
7514
+ },
7515
+ });
7516
+ await fs.promises.writeFile("index.js", `export default {};`);
7517
+ mockSubDomainRequest();
7518
+ mockUploadWorkerRequest();
7519
+ mockGetQueue("queue1");
7520
+ mockPutQueueConsumer("queue1", "test-name", {
7521
+ dead_letter_queue: "myDLQ",
7522
+ settings: {
7523
+ batch_size: 5,
7524
+ max_retries: 10,
7525
+ max_wait_time_ms: 3000,
7526
+ },
7527
+ });
7528
+ await runWrangler("publish index.js");
7529
+ expect(std.out).toMatchInlineSnapshot(`
7530
+ "Total Upload: xx KiB / gzip: xx KiB
7531
+ Uploaded test-name (TIMINGS)
7532
+ Published test-name (TIMINGS)
7533
+ https://test-name.test-sub-domain.workers.dev
7534
+ Consumer for queue1
7535
+ Current Deployment ID: Galaxy-Class"
6989
7536
  `);
6990
7537
  });
6991
7538
 
@@ -7036,6 +7583,37 @@ addEventListener('fetch', event => {});`
7036
7583
  });
7037
7584
  });
7038
7585
 
7586
+ describe("mtls_certificates", () => {
7587
+ it("should upload mtls_certificate bindings", async () => {
7588
+ writeWranglerToml({
7589
+ mtls_certificates: [{ binding: "CERT_ONE", certificate_id: "1234" }],
7590
+ });
7591
+ await fs.promises.writeFile("index.js", `export default {};`);
7592
+ mockSubDomainRequest();
7593
+ mockUploadWorkerRequest({
7594
+ expectedBindings: [
7595
+ {
7596
+ type: "mtls_certificate",
7597
+ name: "CERT_ONE",
7598
+ certificate_id: "1234",
7599
+ },
7600
+ ],
7601
+ });
7602
+
7603
+ await runWrangler("publish index.js");
7604
+ expect(std.out).toMatchInlineSnapshot(`
7605
+ "Total Upload: xx KiB / gzip: xx KiB
7606
+ Your worker has access to the following bindings:
7607
+ - mTLS Certificates:
7608
+ - CERT_ONE: 1234
7609
+ Uploaded test-name (TIMINGS)
7610
+ Published test-name (TIMINGS)
7611
+ https://test-name.test-sub-domain.workers.dev
7612
+ Current Deployment ID: Galaxy-Class"
7613
+ `);
7614
+ });
7615
+ });
7616
+
7039
7617
  describe("--keep-vars", () => {
7040
7618
  it("should send keepVars when keep-vars is passed in", async () => {
7041
7619
  process.env = {
@@ -7057,7 +7635,7 @@ addEventListener('fetch', event => {});`
7057
7635
  Uploaded test-name (TIMINGS)
7058
7636
  Published test-name (TIMINGS)
7059
7637
  https://test-name.test-sub-domain.workers.dev
7060
- Current Deployment ID: undefined"
7638
+ Current Deployment ID: Galaxy-Class"
7061
7639
  `);
7062
7640
  expect(std.err).toMatchInlineSnapshot(`""`);
7063
7641
  });
@@ -7082,7 +7660,34 @@ addEventListener('fetch', event => {});`
7082
7660
  Uploaded test-name (TIMINGS)
7083
7661
  Published test-name (TIMINGS)
7084
7662
  https://test-name.test-sub-domain.workers.dev
7085
- Current Deployment ID: undefined"
7663
+ Current Deployment ID: Galaxy-Class"
7664
+ `);
7665
+ expect(std.err).toMatchInlineSnapshot(`""`);
7666
+ });
7667
+
7668
+ it("should send keepVars when `keep_vars = true`", async () => {
7669
+ process.env = {
7670
+ CLOUDFLARE_API_TOKEN: "hunter2",
7671
+ CLOUDFLARE_ACCOUNT_ID: "some-account-id",
7672
+ };
7673
+ setIsTTY(false);
7674
+ writeWranglerToml({
7675
+ keep_vars: true,
7676
+ });
7677
+ writeWorkerSource();
7678
+ mockSubDomainRequest();
7679
+ mockUploadWorkerRequest({ keepVars: true });
7680
+ mockOAuthServerCallback();
7681
+ mockGetMemberships([]);
7682
+
7683
+ await runWrangler("publish index.js");
7684
+
7685
+ expect(std.out).toMatchInlineSnapshot(`
7686
+ "Total Upload: xx KiB / gzip: xx KiB
7687
+ Uploaded test-name (TIMINGS)
7688
+ Published test-name (TIMINGS)
7689
+ https://test-name.test-sub-domain.workers.dev
7690
+ Current Deployment ID: Galaxy-Class"
7086
7691
  `);
7087
7692
  expect(std.err).toMatchInlineSnapshot(`""`);
7088
7693
  });
@@ -7102,12 +7707,19 @@ function writeAssets(
7102
7707
  fs.writeFileSync(filePathDestination, asset.content);
7103
7708
  }
7104
7709
  }
7710
+ function mockDeploymentsListRequest() {
7711
+ msw.use(...mswSuccessDeployments);
7712
+ }
7713
+
7714
+ function mockLastDeploymentRequest() {
7715
+ msw.use(...mswSuccessDeploymentScriptMetadata);
7716
+ }
7105
7717
 
7106
7718
  /** Create a mock handler for the request to upload a worker script. */
7107
7719
  function mockUploadWorkerRequest(
7108
7720
  options: {
7109
7721
  available_on_subdomain?: boolean;
7110
- expectedEntry?: string;
7722
+ expectedEntry?: string | RegExp;
7111
7723
  expectedMainModule?: string;
7112
7724
  expectedType?: "esm" | "sw";
7113
7725
  expectedBindings?: unknown;
@@ -7115,9 +7727,9 @@ function mockUploadWorkerRequest(
7115
7727
  expectedCompatibilityDate?: string;
7116
7728
  expectedCompatibilityFlags?: string[];
7117
7729
  expectedMigrations?: CfWorkerInit["migrations"];
7730
+ expectedUnsafeMetaData?: Record<string, string>;
7118
7731
  env?: string;
7119
7732
  legacyEnv?: boolean;
7120
- sendScriptIds?: boolean;
7121
7733
  keepVars?: boolean;
7122
7734
  tag?: string;
7123
7735
  } = {}
@@ -7134,76 +7746,97 @@ function mockUploadWorkerRequest(
7134
7746
  env = undefined,
7135
7747
  legacyEnv = false,
7136
7748
  expectedMigrations,
7137
- sendScriptIds,
7749
+ expectedUnsafeMetaData,
7138
7750
  keepVars,
7139
7751
  } = options;
7140
- setMockResponse(
7141
- env && !legacyEnv
7142
- ? "/accounts/:accountId/workers/services/:scriptName/environments/:envName"
7143
- : "/accounts/:accountId/workers/scripts/:scriptName",
7144
- "PUT",
7145
- async ([_url, accountId, scriptName, envName], { body }, queryParams) => {
7146
- expect(accountId).toEqual("some-account-id");
7147
- expect(scriptName).toEqual(
7148
- legacyEnv && env ? `test-name-${env}` : "test-name"
7149
- );
7150
- if (!legacyEnv) {
7151
- expect(envName).toEqual(env);
7152
- }
7153
- expect(queryParams.get("include_subdomain_availability")).toEqual("true");
7154
- expect(queryParams.get("excludeScript")).toEqual("true");
7155
- const formBody = body as FormData;
7156
- if (expectedEntry !== undefined) {
7157
- expect(await (formBody.get("index.js") as File).text()).toMatch(
7158
- expectedEntry
7159
- );
7160
- }
7161
- const metadata = JSON.parse(
7162
- formBody.get("metadata") as string
7163
- ) as WorkerMetadata;
7164
- if (expectedType === "esm") {
7165
- expect(metadata.main_module).toEqual(expectedMainModule);
7166
- } else {
7167
- expect(metadata.body_part).toEqual("index.js");
7168
- }
7752
+ if (env && !legacyEnv) {
7753
+ msw.use(
7754
+ rest.put(
7755
+ "*/accounts/:accountId/workers/services/:scriptName/environments/:envName",
7756
+ handleUpload
7757
+ )
7758
+ );
7759
+ } else {
7760
+ msw.use(
7761
+ rest.put(
7762
+ "*/accounts/:accountId/workers/scripts/:scriptName",
7763
+ handleUpload
7764
+ )
7765
+ );
7766
+ }
7169
7767
 
7170
- if (keepVars) {
7171
- expect(metadata.keep_bindings).toEqual(["plain_text", "json"]);
7172
- } else {
7173
- expect(metadata.keep_bindings).toBeFalsy();
7174
- }
7768
+ async function handleUpload(
7769
+ req: RestRequest,
7770
+ res: ResponseComposition,
7771
+ ctx: RestContext
7772
+ ) {
7773
+ expect(req.params.accountId).toEqual("some-account-id");
7774
+ expect(req.params.scriptName).toEqual(
7775
+ legacyEnv && env ? `test-name-${env}` : "test-name"
7776
+ );
7777
+ if (!legacyEnv) {
7778
+ expect(req.params.envName).toEqual(env);
7779
+ }
7780
+ expect(req.url.searchParams.get("include_subdomain_availability")).toEqual(
7781
+ "true"
7782
+ );
7783
+ expect(req.url.searchParams.get("excludeScript")).toEqual("true");
7175
7784
 
7176
- if ("expectedBindings" in options) {
7177
- expect(metadata.bindings).toEqual(expectedBindings);
7178
- }
7179
- if ("expectedCompatibilityDate" in options) {
7180
- expect(metadata.compatibility_date).toEqual(expectedCompatibilityDate);
7181
- }
7182
- if ("expectedCompatibilityFlags" in options) {
7183
- expect(metadata.compatibility_flags).toEqual(
7184
- expectedCompatibilityFlags
7185
- );
7186
- }
7187
- if ("expectedMigrations" in options) {
7188
- expect(metadata.migrations).toEqual(expectedMigrations);
7189
- }
7190
- for (const [name, content] of Object.entries(expectedModules)) {
7191
- expect(await (formBody.get(name) as File).text()).toEqual(content);
7192
- }
7785
+ const formBody = await (
7786
+ req as MockedRequest as RestRequestWithFormData
7787
+ ).formData();
7788
+ if (expectedEntry !== undefined) {
7789
+ expect(formBody.get("index.js")).toMatch(expectedEntry);
7790
+ }
7791
+ const metadata = JSON.parse(
7792
+ formBody.get("metadata") as string
7793
+ ) as WorkerMetadata;
7794
+ if (expectedType === "esm") {
7795
+ expect(metadata.main_module).toEqual(expectedMainModule);
7796
+ } else {
7797
+ expect(metadata.body_part).toEqual("index.js");
7798
+ }
7193
7799
 
7194
- return {
7195
- available_on_subdomain,
7196
- ...(sendScriptIds
7197
- ? {
7198
- id: "abc12345",
7199
- etag: "etag98765",
7200
- pipeline_hash: "hash9999",
7201
- tag: "sample-tag",
7202
- }
7203
- : {}),
7204
- };
7800
+ if (keepVars) {
7801
+ expect(metadata.keep_bindings).toEqual(["plain_text", "json"]);
7802
+ } else {
7803
+ expect(metadata.keep_bindings).toBeFalsy();
7205
7804
  }
7206
- );
7805
+
7806
+ if ("expectedBindings" in options) {
7807
+ expect(metadata.bindings).toEqual(expectedBindings);
7808
+ }
7809
+ if ("expectedCompatibilityDate" in options) {
7810
+ expect(metadata.compatibility_date).toEqual(expectedCompatibilityDate);
7811
+ }
7812
+ if ("expectedCompatibilityFlags" in options) {
7813
+ expect(metadata.compatibility_flags).toEqual(expectedCompatibilityFlags);
7814
+ }
7815
+ if ("expectedMigrations" in options) {
7816
+ expect(metadata.migrations).toEqual(expectedMigrations);
7817
+ }
7818
+ if (expectedUnsafeMetaData !== undefined) {
7819
+ Object.keys(expectedUnsafeMetaData).forEach((key) => {
7820
+ expect(metadata[key]).toEqual(expectedUnsafeMetaData[key]);
7821
+ });
7822
+ }
7823
+ for (const [name, content] of Object.entries(expectedModules)) {
7824
+ expect(formBody.get(name)).toEqual(content);
7825
+ }
7826
+
7827
+ return res(
7828
+ ctx.json(
7829
+ createFetchResult({
7830
+ available_on_subdomain,
7831
+ id: "abc12345",
7832
+ etag: "etag98765",
7833
+ pipeline_hash: "hash9999",
7834
+ tag: "sample-tag",
7835
+ deployment_id: "Galaxy-Class",
7836
+ })
7837
+ )
7838
+ );
7839
+ }
7207
7840
  }
7208
7841
 
7209
7842
  /** Create a mock handler for the request to get the account's subdomain. */
@@ -7212,18 +7845,30 @@ function mockSubDomainRequest(
7212
7845
  registeredWorkersDev = true
7213
7846
  ) {
7214
7847
  if (registeredWorkersDev) {
7215
- setMockResponse("/accounts/:accountId/workers/subdomain", "GET", () => {
7216
- return { subdomain };
7217
- });
7848
+ msw.use(
7849
+ rest.get("*/accounts/:accountId/workers/subdomain", (req, res, ctx) => {
7850
+ return res.once(ctx.json(createFetchResult({ subdomain })));
7851
+ })
7852
+ );
7218
7853
  } else {
7219
- setMockRawResponse("/accounts/:accountId/workers/subdomain", "GET", () => {
7220
- return createFetchResult(null, false, [
7221
- { code: 10007, message: "haven't registered workers.dev" },
7222
- ]);
7223
- });
7854
+ msw.use(
7855
+ rest.get("*/accounts/:accountId/workers/subdomain", (req, res, ctx) => {
7856
+ return res.once(
7857
+ ctx.json(
7858
+ createFetchResult(null, false, [
7859
+ { code: 10007, message: "haven't registered workers.dev" },
7860
+ ])
7861
+ )
7862
+ );
7863
+ })
7864
+ );
7224
7865
  }
7225
7866
  }
7226
-
7867
+ //
7868
+ //
7869
+ //
7870
+ //
7871
+ //
7227
7872
  /** Create a mock handler to toggle a <script>.<user>.workers.dev subdomain */
7228
7873
  function mockUpdateWorkerRequest({
7229
7874
  env,
@@ -7237,20 +7882,22 @@ function mockUpdateWorkerRequest({
7237
7882
  const requests = { count: 0 };
7238
7883
  const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
7239
7884
  const environment = env && !legacyEnv ? "/environments/:envName" : "";
7240
- setMockResponse(
7241
- `/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/subdomain`,
7242
- "POST",
7243
- ([_url, accountId, scriptName, envName], { body }) => {
7244
- expect(accountId).toEqual("some-account-id");
7245
- expect(scriptName).toEqual(
7246
- legacyEnv && env ? `test-name-${env}` : "test-name"
7247
- );
7248
- if (!legacyEnv) {
7249
- expect(envName).toEqual(env);
7885
+ msw.use(
7886
+ rest.post(
7887
+ `*/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/subdomain`,
7888
+ async (req, res, ctx) => {
7889
+ expect(req.params.accountId).toEqual("some-account-id");
7890
+ expect(req.params.scriptName).toEqual(
7891
+ legacyEnv && env ? `test-name-${env}` : "test-name"
7892
+ );
7893
+ if (!legacyEnv) {
7894
+ expect(req.params.envName).toEqual(env);
7895
+ }
7896
+ const body = await req.json();
7897
+ expect(body).toEqual({ enabled });
7898
+ return res.once(ctx.json(createFetchResult(null)));
7250
7899
  }
7251
- expect(JSON.parse(body as string)).toEqual({ enabled });
7252
- return null;
7253
- }
7900
+ )
7254
7901
  );
7255
7902
  return requests;
7256
7903
  }
@@ -7267,25 +7914,26 @@ function mockPublishRoutesRequest({
7267
7914
  const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
7268
7915
  const environment = env && !legacyEnv ? "/environments/:envName" : "";
7269
7916
 
7270
- setMockResponse(
7271
- `/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/routes`,
7272
- "PUT",
7273
- ([_url, accountId, scriptName, envName], { body }) => {
7274
- expect(accountId).toEqual("some-account-id");
7275
- expect(scriptName).toEqual(
7276
- legacyEnv && env ? `test-name-${env}` : "test-name"
7277
- );
7278
- if (!legacyEnv) {
7279
- expect(envName).toEqual(env);
7917
+ msw.use(
7918
+ rest.put(
7919
+ `*/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/routes`,
7920
+ async (req, res, ctx) => {
7921
+ expect(req.params.accountId).toEqual("some-account-id");
7922
+ expect(req.params.scriptName).toEqual(
7923
+ legacyEnv && env ? `test-name-${env}` : "test-name"
7924
+ );
7925
+ if (!legacyEnv) {
7926
+ expect(req.params.envName).toEqual(env);
7927
+ }
7928
+ const body = await req.json();
7929
+ expect(body).toEqual(
7930
+ routes.map((route) =>
7931
+ typeof route !== "object" ? { pattern: route } : route
7932
+ )
7933
+ );
7934
+ return res.once(ctx.json(createFetchResult(null)));
7280
7935
  }
7281
-
7282
- expect(JSON.parse(body as string)).toEqual(
7283
- routes.map((route) =>
7284
- typeof route !== "object" ? { pattern: route } : route
7285
- )
7286
- );
7287
- return null;
7288
- }
7936
+ )
7289
7937
  );
7290
7938
  }
7291
7939
 
@@ -7299,13 +7947,19 @@ function mockUnauthorizedPublishRoutesRequest({
7299
7947
  const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
7300
7948
  const environment = env && !legacyEnv ? "/environments/:envName" : "";
7301
7949
 
7302
- setMockRawResponse(
7303
- `/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/routes`,
7304
- "PUT",
7305
- () =>
7306
- createFetchResult(null, false, [
7307
- { message: "Authentication error", code: 10000 },
7308
- ])
7950
+ msw.use(
7951
+ rest.put(
7952
+ `*/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/routes`,
7953
+ (req, res, ctx) => {
7954
+ return res.once(
7955
+ ctx.json(
7956
+ createFetchResult(null, false, [
7957
+ { message: "Authentication error", code: 10000 },
7958
+ ])
7959
+ )
7960
+ );
7961
+ }
7962
+ )
7309
7963
  );
7310
7964
  }
7311
7965
 
@@ -7313,22 +7967,27 @@ function mockPublishRoutesFallbackRequest(route: {
7313
7967
  pattern: string;
7314
7968
  script: string;
7315
7969
  }) {
7316
- setMockResponse(`/zones/:zoneId/workers/routes`, "POST", (_url, { body }) => {
7317
- expect(JSON.parse(body as string)).toEqual(route);
7318
- return route.pattern;
7319
- });
7970
+ msw.use(
7971
+ rest.post(`*/zones/:zoneId/workers/routes`, async (req, res, ctx) => {
7972
+ const body = await req.json();
7973
+ expect(body).toEqual(route);
7974
+ return res.once(ctx.json(createFetchResult(route.pattern)));
7975
+ })
7976
+ );
7320
7977
  }
7321
7978
 
7322
7979
  function mockCustomDomainLookup(origin: CustomDomain) {
7323
- setMockResponse(
7324
- `/accounts/:accountId/workers/domains/records/:domainTag`,
7325
- "GET",
7326
- ([_url, accountId, domainTag]) => {
7327
- expect(accountId).toEqual("some-account-id");
7328
- expect(domainTag).toEqual(origin.id);
7329
-
7330
- return origin;
7331
- }
7980
+ msw.use(
7981
+ rest.get(
7982
+ `*/accounts/:accountId/workers/domains/records/:domainTag`,
7983
+
7984
+ (req, res, ctx) => {
7985
+ expect(req.params.accountId).toEqual("some-account-id");
7986
+ expect(req.params.domainTag).toEqual(origin.id);
7987
+
7988
+ return res.once(ctx.json(createFetchResult(origin)));
7989
+ }
7990
+ )
7332
7991
  );
7333
7992
  }
7334
7993
 
@@ -7345,47 +8004,47 @@ function mockCustomDomainsChangesetRequest({
7345
8004
  }) {
7346
8005
  const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
7347
8006
  const environment = env && !legacyEnv ? "/environments/:envName" : "";
8007
+ msw.use(
8008
+ rest.post(
8009
+ `*/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/domains/changeset`,
8010
+ async (req, res, ctx) => {
8011
+ expect(req.params.accountId).toEqual("some-account-id");
8012
+ expect(req.params.scriptName).toEqual(
8013
+ legacyEnv && env ? `test-name-${env}` : "test-name"
8014
+ );
8015
+ if (!legacyEnv) {
8016
+ expect(req.params.envName).toEqual(env);
8017
+ }
7348
8018
 
7349
- setMockResponse(
7350
- `/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/domains/changeset`,
7351
- "POST",
7352
- ([_url, accountId, scriptName, envName], { body }) => {
7353
- expect(accountId).toEqual("some-account-id");
7354
- expect(scriptName).toEqual(
7355
- legacyEnv && env ? `test-name-${env}` : "test-name"
7356
- );
7357
- if (!legacyEnv) {
7358
- expect(envName).toEqual(env);
7359
- }
8019
+ const domains: Array<
8020
+ { hostname: string } & ({ zone_id?: string } | { zone_name?: string })
8021
+ > = await req.json();
7360
8022
 
7361
- const domains: Array<
7362
- { hostname: string } & ({ zone_id?: string } | { zone_name?: string })
7363
- > = JSON.parse(body as string);
7364
-
7365
- const changeset: CustomDomainChangeset = {
7366
- added: domains.map((domain) => {
7367
- return {
7368
- ...domain,
7369
- id: "",
7370
- service: scriptName,
7371
- environment: envName,
7372
- zone_name: "",
7373
- zone_id: "",
7374
- };
7375
- }),
7376
- removed: [],
7377
- updated:
7378
- originConflicts?.map((domain) => {
8023
+ const changeset: CustomDomainChangeset = {
8024
+ added: domains.map((domain) => {
7379
8025
  return {
7380
8026
  ...domain,
7381
- modified: true,
8027
+ id: "",
8028
+ service: req.params.scriptName as string,
8029
+ environment: req.params.envName as string,
8030
+ zone_name: "",
8031
+ zone_id: "",
7382
8032
  };
7383
- }) ?? [],
7384
- conflicting: dnsRecordConflicts,
7385
- };
8033
+ }),
8034
+ removed: [],
8035
+ updated:
8036
+ originConflicts?.map((domain) => {
8037
+ return {
8038
+ ...domain,
8039
+ modified: true,
8040
+ };
8041
+ }) ?? [],
8042
+ conflicting: dnsRecordConflicts,
8043
+ };
7386
8044
 
7387
- return changeset;
7388
- }
8045
+ return res.once(ctx.json(createFetchResult(changeset)));
8046
+ }
8047
+ )
7389
8048
  );
7390
8049
  }
7391
8050
 
@@ -7409,37 +8068,36 @@ function mockPublishCustomDomainsRequest({
7409
8068
  const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
7410
8069
  const environment = env && !legacyEnv ? "/environments/:envName" : "";
7411
8070
 
7412
- setMockResponse(
7413
- `/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/domains/records`,
7414
- "PUT",
7415
- ([_url, accountId, scriptName, envName], { body }) => {
7416
- expect(accountId).toEqual("some-account-id");
7417
- expect(scriptName).toEqual(
7418
- legacyEnv && env ? `test-name-${env}` : "test-name"
7419
- );
7420
- if (!legacyEnv) {
7421
- expect(envName).toEqual(env);
7422
- }
7423
-
7424
- expect(JSON.parse(body as string)).toEqual({
7425
- ...publishFlags,
7426
- origins: domains,
7427
- });
8071
+ msw.use(
8072
+ rest.put(
8073
+ `*/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/domains/records`,
8074
+ async (req, res, ctx) => {
8075
+ expect(req.params.accountId).toEqual("some-account-id");
8076
+ expect(req.params.scriptName).toEqual(
8077
+ legacyEnv && env ? `test-name-${env}` : "test-name"
8078
+ );
8079
+ if (!legacyEnv) {
8080
+ expect(req.params.envName).toEqual(env);
8081
+ }
8082
+ const body = await req.json();
8083
+ expect(body).toEqual({
8084
+ ...publishFlags,
8085
+ origins: domains,
8086
+ });
7428
8087
 
7429
- return null;
7430
- }
8088
+ return res.once(ctx.json(createFetchResult(null)));
8089
+ }
8090
+ )
7431
8091
  );
7432
8092
  }
7433
8093
 
7434
8094
  /** Create a mock handler for the request to get a list of all KV namespaces. */
7435
8095
  function mockListKVNamespacesRequest(...namespaces: KVNamespaceInfo[]) {
7436
- setMockResponse(
7437
- "/accounts/:accountId/storage/kv/namespaces",
7438
- "GET",
7439
- ([_url, accountId]) => {
7440
- expect(accountId).toEqual("some-account-id");
7441
- return namespaces;
7442
- }
8096
+ msw.use(
8097
+ rest.get("*/accounts/:accountId/storage/kv/namespaces", (req, res, ctx) => {
8098
+ expect(req.params.accountId).toEqual("some-account-id");
8099
+ return res.once(ctx.json(createFetchResult(namespaces)));
8100
+ })
7443
8101
  );
7444
8102
  }
7445
8103
 
@@ -7458,6 +8116,7 @@ interface StaticAssetUpload {
7458
8116
  }
7459
8117
 
7460
8118
  /** Create a mock handler for the request that tries to do a bulk upload of assets to a KV namespace. */
8119
+ //TODO: This is getting called multiple times in the test, we need to check if that is happening in Production --Jacob 2021-03-02
7461
8120
  function mockUploadAssetsToKVRequest(
7462
8121
  expectedNamespaceId: string,
7463
8122
  assets?: ExpectedAsset[]
@@ -7465,22 +8124,24 @@ function mockUploadAssetsToKVRequest(
7465
8124
  const requests: {
7466
8125
  uploads: StaticAssetUpload[];
7467
8126
  }[] = [];
7468
- setMockResponse(
7469
- "/accounts/:accountId/storage/kv/namespaces/:namespaceId/bulk",
7470
- "PUT",
7471
- ([_url, accountId, namespaceId], { body }) => {
7472
- expect(accountId).toEqual("some-account-id");
7473
- expect(namespaceId).toEqual(expectedNamespaceId);
7474
- const uploads = JSON.parse(body as string);
7475
- if (assets) {
7476
- expect(assets.length).toEqual(uploads.length);
7477
- for (let i = 0; i < uploads.length; i++) {
7478
- checkAssetUpload(assets[i], uploads[i]);
8127
+ msw.use(
8128
+ rest.put(
8129
+ "*/accounts/:accountId/storage/kv/namespaces/:namespaceId/bulk",
8130
+ async (req, res, ctx) => {
8131
+ expect(req.params.accountId).toEqual("some-account-id");
8132
+ expect(req.params.namespaceId).toEqual(expectedNamespaceId);
8133
+ const uploads = await req.json();
8134
+ if (assets) {
8135
+ expect(assets.length).toEqual(uploads.length);
8136
+ for (let i = 0; i < uploads.length; i++) {
8137
+ checkAssetUpload(assets[i], uploads[i]);
8138
+ }
7479
8139
  }
7480
- } else {
8140
+
7481
8141
  requests.push({ uploads });
8142
+ return res(ctx.json(createFetchResult([])));
7482
8143
  }
7483
- }
8144
+ )
7484
8145
  );
7485
8146
  return requests;
7486
8147
  }
@@ -7504,16 +8165,24 @@ function mockDeleteUnusedAssetsRequest(
7504
8165
  expectedNamespaceId: string,
7505
8166
  assets: string[]
7506
8167
  ) {
7507
- setMockResponse(
7508
- "/accounts/:accountId/storage/kv/namespaces/:namespaceId/bulk",
7509
- "DELETE",
7510
- ([_url, accountId, namespaceId], { body }) => {
7511
- expect(accountId).toEqual("some-account-id");
7512
- expect(namespaceId).toEqual(expectedNamespaceId);
7513
- const deletes = JSON.parse(body as string);
7514
- expect(assets).toEqual(deletes);
7515
- return null;
7516
- }
8168
+ msw.use(
8169
+ rest.delete(
8170
+ "*/accounts/:accountId/storage/kv/namespaces/:namespaceId/bulk",
8171
+ async (req, res, ctx) => {
8172
+ expect(req.params.accountId).toEqual("some-account-id");
8173
+ expect(req.params.namespaceId).toEqual(expectedNamespaceId);
8174
+ const deletes = await req.json();
8175
+ expect(assets).toEqual(deletes);
8176
+ return res.once(
8177
+ ctx.json({
8178
+ success: true,
8179
+ errors: [],
8180
+ messages: [],
8181
+ result: null,
8182
+ })
8183
+ );
8184
+ }
8185
+ )
7517
8186
  );
7518
8187
  }
7519
8188
 
@@ -7521,13 +8190,18 @@ type LegacyScriptInfo = { id: string; migration_tag?: string };
7521
8190
 
7522
8191
  function mockLegacyScriptData(options: { scripts: LegacyScriptInfo[] }) {
7523
8192
  const { scripts } = options;
7524
- setMockResponse(
7525
- "/accounts/:accountId/workers/scripts",
7526
- "GET",
7527
- ([_url, accountId]) => {
7528
- expect(accountId).toEqual("some-account-id");
7529
- return scripts;
7530
- }
8193
+ msw.use(
8194
+ rest.get("*/accounts/:accountId/workers/scripts", (req, res, ctx) => {
8195
+ expect(req.params.accountId).toEqual("some-account-id");
8196
+ return res.once(
8197
+ ctx.json({
8198
+ success: true,
8199
+ errors: [],
8200
+ messages: [],
8201
+ result: scripts,
8202
+ })
8203
+ );
8204
+ })
7531
8205
  );
7532
8206
  }
7533
8207
 
@@ -7541,74 +8215,140 @@ function mockServiceScriptData(options: {
7541
8215
  const { script } = options;
7542
8216
  if (options.env) {
7543
8217
  if (!script) {
7544
- setMockRawResponse(
7545
- "/accounts/:accountId/workers/services/:scriptName/environments/:envName",
7546
- "GET",
7547
- () => {
7548
- return createFetchResult(null, false, [
7549
- { code: 10092, message: "workers.api.error.environment_not_found" },
7550
- ]);
7551
- }
8218
+ msw.use(
8219
+ rest.get(
8220
+ "*/accounts/:accountId/workers/services/:scriptName/environments/:envName",
8221
+ (_, res, ctx) => {
8222
+ return res.once(
8223
+ ctx.json({
8224
+ success: false,
8225
+ errors: [
8226
+ {
8227
+ code: 10092,
8228
+ message: "workers.api.error.environment_not_found",
8229
+ },
8230
+ ],
8231
+ messages: [],
8232
+ result: null,
8233
+ })
8234
+ );
8235
+ }
8236
+ )
7552
8237
  );
7553
8238
  return;
7554
8239
  }
7555
- setMockResponse(
7556
- "/accounts/:accountId/workers/services/:scriptName/environments/:envName",
7557
- "GET",
7558
- ([_url, accountId, scriptName, envName]) => {
7559
- expect(accountId).toEqual("some-account-id");
7560
- expect(scriptName).toEqual(options.scriptName || "test-name");
7561
- expect(envName).toEqual(options.env);
7562
- return { script };
7563
- }
8240
+ msw.use(
8241
+ rest.get(
8242
+ "*/accounts/:accountId/workers/services/:scriptName/environments/:envName",
8243
+ (req, res, ctx) => {
8244
+ expect(req.params.accountId).toEqual("some-account-id");
8245
+ expect(req.params.scriptName).toEqual(
8246
+ options.scriptName || "test-name"
8247
+ );
8248
+ expect(req.params.envName).toEqual(options.env);
8249
+ return res.once(
8250
+ ctx.json({
8251
+ success: true,
8252
+ errors: [],
8253
+ messages: [],
8254
+ result: { script },
8255
+ })
8256
+ );
8257
+ }
8258
+ )
7564
8259
  );
7565
8260
  } else {
7566
8261
  if (!script) {
7567
- setMockRawResponse(
7568
- "/accounts/:accountId/workers/services/:scriptName",
7569
- "GET",
7570
- () => {
7571
- return createFetchResult(null, false, [
7572
- { code: 10090, message: "workers.api.error.service_not_found" },
7573
- ]);
7574
- }
8262
+ msw.use(
8263
+ rest.get(
8264
+ "*/accounts/:accountId/workers/services/:scriptName",
8265
+ (req, res, ctx) => {
8266
+ return res.once(
8267
+ ctx.json({
8268
+ success: false,
8269
+ errors: [
8270
+ {
8271
+ code: 10090,
8272
+ message: "workers.api.error.service_not_found",
8273
+ },
8274
+ ],
8275
+ messages: [],
8276
+ result: null,
8277
+ })
8278
+ );
8279
+ }
8280
+ )
7575
8281
  );
7576
8282
  return;
7577
8283
  }
7578
- setMockResponse(
7579
- "/accounts/:accountId/workers/services/:scriptName",
7580
- "GET",
7581
- ([_url, accountId, scriptName]) => {
7582
- expect(accountId).toEqual("some-account-id");
7583
- expect(scriptName).toEqual(options.scriptName || "test-name");
7584
- return { default_environment: { script } };
7585
- }
8284
+ msw.use(
8285
+ rest.get(
8286
+ "*/accounts/:accountId/workers/services/:scriptName",
8287
+ (req, res, ctx) => {
8288
+ expect(req.params.accountId).toEqual("some-account-id");
8289
+ expect(req.params.scriptName).toEqual(
8290
+ options.scriptName || "test-name"
8291
+ );
8292
+ return res.once(
8293
+ ctx.json({
8294
+ success: true,
8295
+ errors: [],
8296
+ messages: [],
8297
+ result: { default_environment: { script } },
8298
+ })
8299
+ );
8300
+ }
8301
+ )
7586
8302
  );
7587
8303
  }
7588
8304
  }
7589
8305
 
7590
8306
  function mockGetQueue(expectedQueueName: string) {
7591
8307
  const requests = { count: 0 };
7592
- setMockResponse(
7593
- `/accounts/:accountId/workers/queues/${expectedQueueName}`,
7594
- "GET",
7595
- ([_url, accountId]) => {
7596
- expect(accountId).toEqual("some-account-id");
7597
- requests.count += 1;
7598
- return { queue: expectedQueueName };
7599
- }
8308
+ msw.use(
8309
+ rest.get(
8310
+ `*/accounts/:accountId/workers/queues/${expectedQueueName}`,
8311
+ (req, res, ctx) => {
8312
+ expect(req.params.accountId).toEqual("some-account-id");
8313
+ requests.count += 1;
8314
+ return res(
8315
+ ctx.json({
8316
+ success: true,
8317
+ errors: [],
8318
+ messages: [],
8319
+ result: { queue: expectedQueueName },
8320
+ })
8321
+ );
8322
+ }
8323
+ )
7600
8324
  );
7601
8325
  return requests;
7602
8326
  }
7603
8327
 
7604
8328
  function mockGetQueueMissing(expectedQueueName: string) {
7605
8329
  const requests = { count: 0 };
7606
- setMockResponse(
7607
- `/accounts/:accountId/workers/queues/${expectedQueueName}`,
7608
- "GET",
7609
- ([_url, _accountId]) => {
7610
- throw { code: 11000 };
7611
- }
8330
+ msw.use(
8331
+ rest.get(
8332
+ `*/accounts/:accountId/workers/queues/${expectedQueueName}`,
8333
+ (req, res, ctx) => {
8334
+ requests.count += 1;
8335
+ expect(req.params.accountId).toEqual("some-account-id");
8336
+
8337
+ return res(
8338
+ ctx.json({
8339
+ success: false,
8340
+ errors: [
8341
+ {
8342
+ code: 11000,
8343
+ message: "workers.api.error.queue_not_found",
8344
+ },
8345
+ ],
8346
+ messages: [],
8347
+ result: null,
8348
+ })
8349
+ );
8350
+ }
8351
+ )
7612
8352
  );
7613
8353
  return requests;
7614
8354
  }
@@ -7619,15 +8359,65 @@ function mockPutQueueConsumer(
7619
8359
  expectedBody: PutConsumerBody
7620
8360
  ) {
7621
8361
  const requests = { count: 0 };
7622
- setMockResponse(
7623
- `/accounts/:accountId/workers/queues/${expectedQueueName}/consumers/${expectedConsumerName}`,
7624
- "PUT",
7625
- ([_url, accountId], { body }) => {
7626
- expect(accountId).toEqual("some-account-id");
7627
- expect(JSON.parse(body as string)).toEqual(expectedBody);
7628
- requests.count += 1;
7629
- return { queue: expectedQueueName };
7630
- }
8362
+ msw.use(
8363
+ rest.put(
8364
+ `*/accounts/:accountId/workers/queues/${expectedQueueName}/consumers/${expectedConsumerName}`,
8365
+ async (req, res, ctx) => {
8366
+ const body = await req.json();
8367
+ expect(req.params.accountId).toEqual("some-account-id");
8368
+ expect(body).toEqual(expectedBody);
8369
+ requests.count += 1;
8370
+ return res(
8371
+ ctx.json({
8372
+ success: true,
8373
+ errors: [],
8374
+ messages: [],
8375
+ result: { queue: expectedQueueName },
8376
+ })
8377
+ );
8378
+ }
8379
+ )
7631
8380
  );
7632
8381
  return requests;
7633
8382
  }
8383
+
8384
+ // MSW FormData & Blob polyfills to test FormData requests
8385
+ function mockFormDataToString(this: FormData) {
8386
+ const entries = [];
8387
+ for (const [key, value] of this.entries()) {
8388
+ if (value instanceof Blob) {
8389
+ const reader = new FileReaderSync();
8390
+ reader.readAsText(value);
8391
+ const result = reader.result;
8392
+ entries.push([key, result]);
8393
+ } else {
8394
+ entries.push([key, value]);
8395
+ }
8396
+ }
8397
+ return JSON.stringify({
8398
+ __formdata: entries,
8399
+ });
8400
+ }
8401
+
8402
+ async function mockFormDataFromString(this: MockedRequest): Promise<FormData> {
8403
+ const { __formdata } = await this.json();
8404
+ expect(__formdata).toBeInstanceOf(Array);
8405
+
8406
+ const form = new FormData();
8407
+ for (const [key, value] of __formdata) {
8408
+ form.set(key, value);
8409
+ }
8410
+ return form;
8411
+ }
8412
+
8413
+ // The following two functions workaround the fact that MSW does not yet support FormData in requests.
8414
+ // We use the fact that MSW relies upon `node-fetch` internally, which will call `toString()` on the FormData object,
8415
+ // rather than passing it through or serializing it as a proper FormData object.
8416
+ // The hack is to serialize FormData to a JSON string by overriding `FormData.toString()`.
8417
+ // And then to deserialize back to a FormData object by monkey-patching a `formData()` helper onto `MockedRequest`.
8418
+ FormData.prototype.toString = mockFormDataToString;
8419
+ export interface RestRequestWithFormData extends MockedRequest, RestRequest {
8420
+ formData(): Promise<FormData>;
8421
+ }
8422
+ (MockedRequest.prototype as RestRequestWithFormData).formData =
8423
+ mockFormDataFromString;