wrangler 0.0.0-e7a0cd5b → 0.0.0-e7cf0caa

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 (237) 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 +27 -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 -86
  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 -56
  15. package/src/__tests__/dev.test.tsx +198 -90
  16. package/src/__tests__/generate.test.ts +12 -10
  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 +128 -27
  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 +1615 -852
  61. package/src/__tests__/pubsub.test.ts +226 -100
  62. package/src/__tests__/queues.test.ts +238 -77
  63. package/src/__tests__/r2.test.ts +55 -57
  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 +43 -26
  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 +263 -140
  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 +79 -24
  87. package/src/config/index.ts +99 -38
  88. package/src/config/validation-helpers.ts +1 -1
  89. package/src/config/validation.ts +248 -19
  90. package/src/create-worker-preview.ts +19 -8
  91. package/src/create-worker-upload-form.ts +60 -22
  92. package/src/d1/backups.tsx +43 -42
  93. package/src/d1/constants.ts +2 -0
  94. package/src/d1/create.tsx +44 -30
  95. package/src/d1/{delete.tsx → delete.ts} +11 -14
  96. package/src/d1/execute.tsx +209 -151
  97. package/src/d1/index.ts +31 -7
  98. package/src/d1/list.tsx +22 -10
  99. package/src/d1/migrations/apply.tsx +212 -0
  100. package/src/d1/migrations/create.tsx +79 -0
  101. package/src/d1/migrations/helpers.ts +172 -0
  102. package/src/d1/migrations/index.ts +3 -0
  103. package/src/d1/migrations/list.tsx +95 -0
  104. package/src/d1/migrations/options.ts +23 -0
  105. package/src/d1/options.ts +12 -2
  106. package/src/d1/splitter.ts +161 -0
  107. package/src/d1/{types.tsx → types.ts} +11 -0
  108. package/src/d1/utils.ts +12 -2
  109. package/src/delete.ts +8 -16
  110. package/src/deployments.ts +340 -46
  111. package/src/deprecated/index.ts +8 -302
  112. package/src/dev/dev.tsx +57 -44
  113. package/src/dev/local.tsx +294 -91
  114. package/src/dev/remote.tsx +32 -3
  115. package/src/dev/start-server.ts +89 -68
  116. package/src/dev/use-esbuild.ts +17 -18
  117. package/src/dev/validate-dev-props.ts +9 -0
  118. package/src/{dev-registry.tsx → dev-registry.ts} +2 -1
  119. package/src/dev.tsx +178 -118
  120. package/src/dialogs.ts +136 -0
  121. package/src/dispatch-namespace.ts +21 -17
  122. package/src/docs/index.ts +97 -0
  123. package/src/entry.ts +19 -11
  124. package/src/environment-variables/factory.ts +88 -0
  125. package/src/environment-variables/misc-variables.ts +30 -0
  126. package/src/generate/index.ts +298 -0
  127. package/src/git-client.ts +15 -4
  128. package/src/{index.tsx → index.ts} +137 -63
  129. package/src/init.ts +249 -187
  130. package/src/inspect.ts +16 -1
  131. package/src/jest.d.ts +4 -0
  132. package/src/kv/index.ts +15 -17
  133. package/src/logger.ts +32 -5
  134. package/src/metrics/metrics-config.ts +3 -3
  135. package/src/metrics/send-event.ts +6 -1
  136. package/src/miniflare-cli/assets.ts +64 -28
  137. package/src/miniflare-cli/index.ts +4 -7
  138. package/src/miniflare-cli/tsconfig.json +9 -0
  139. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -0
  140. package/src/miniflare-cli/types.ts +11 -0
  141. package/src/module-collection.ts +91 -25
  142. package/src/mtls-certificate/cli.ts +155 -0
  143. package/src/pages/build.ts +410 -0
  144. package/src/pages/buildFunctions.ts +140 -0
  145. package/src/pages/deployment-tails.ts +281 -0
  146. package/src/pages/deployments.tsx +11 -33
  147. package/src/pages/{dev.tsx → dev.ts} +147 -124
  148. package/src/pages/errors.ts +1 -0
  149. package/src/pages/functions/buildPlugin.ts +72 -69
  150. package/src/pages/functions/buildWorker.ts +249 -114
  151. package/src/pages/functions/tsconfig.json +8 -0
  152. package/src/pages/functions/tsconfig.tsbuildinfo +1 -0
  153. package/src/pages/{functions.tsx → functions.ts} +8 -4
  154. package/src/pages/{index.tsx → index.ts} +11 -3
  155. package/src/pages/projects.tsx +12 -22
  156. package/src/pages/prompt-select-project.tsx +31 -0
  157. package/src/pages/publish.tsx +45 -214
  158. package/src/pages/types.ts +6 -9
  159. package/src/pages/upload.tsx +58 -14
  160. package/src/pages/utils.ts +14 -3
  161. package/src/parse.ts +23 -1
  162. package/src/paths.ts +1 -1
  163. package/src/proxy.ts +5 -0
  164. package/src/publish/index.ts +20 -16
  165. package/src/publish/publish.ts +72 -47
  166. package/src/pubsub/{pubsub-commands.tsx → pubsub-commands.ts} +19 -20
  167. package/src/queues/cli/commands/consumer/add.ts +24 -24
  168. package/src/queues/cli/commands/consumer/index.ts +3 -6
  169. package/src/queues/cli/commands/consumer/remove.ts +11 -18
  170. package/src/queues/cli/commands/create.ts +8 -8
  171. package/src/queues/cli/commands/delete.ts +8 -8
  172. package/src/queues/cli/commands/index.ts +6 -4
  173. package/src/queues/cli/commands/list.ts +8 -8
  174. package/src/queues/client.ts +1 -0
  175. package/src/queues/utils.ts +18 -0
  176. package/src/r2/constants.ts +4 -0
  177. package/src/r2/helpers.ts +1 -0
  178. package/src/r2/index.ts +40 -28
  179. package/src/secret/index.ts +14 -17
  180. package/src/{sites.tsx → sites.ts} +1 -1
  181. package/src/tail/createTail.ts +94 -3
  182. package/src/tail/filters.ts +1 -1
  183. package/src/tail/index.ts +8 -11
  184. package/src/tail/printing.ts +15 -0
  185. package/src/traverse-module-graph.ts +53 -0
  186. package/src/tsconfig-sanity.ts +16 -0
  187. package/src/type-generation.ts +79 -57
  188. package/src/user/access.ts +0 -1
  189. package/src/user/auth-variables.ts +113 -0
  190. package/src/user/choose-account.tsx +1 -31
  191. package/src/user/index.ts +0 -1
  192. package/src/user/{user.tsx → user.ts} +123 -82
  193. package/src/utils/render.ts +93 -0
  194. package/src/{whoami.tsx → whoami.ts} +37 -71
  195. package/src/worker.ts +35 -3
  196. package/src/yargs-types.ts +22 -5
  197. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  198. package/templates/__tests__/tsconfig.json +8 -0
  199. package/templates/__tests__/tsconfig.tsbuildinfo +1 -0
  200. package/templates/checked-fetch.js +9 -3
  201. package/templates/d1-beta-facade.js +95 -25
  202. package/templates/facade.d.ts +14 -0
  203. package/templates/first-party-worker-module-facade.ts +4 -3
  204. package/templates/format-dev-errors.ts +8 -6
  205. package/templates/gitignore +1 -0
  206. package/templates/init-tests/test-jest-new-worker.js +3 -5
  207. package/templates/init-tests/test-vitest-new-worker.js +3 -5
  208. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  209. package/templates/middleware/loader-modules.ts +2 -2
  210. package/templates/middleware/loader-sw.ts +51 -31
  211. package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
  212. package/templates/new-worker.ts +3 -0
  213. package/templates/pages-dev-pipeline.ts +4 -1
  214. package/templates/pages-shim.ts +4 -1
  215. package/templates/pages-template-plugin.ts +19 -10
  216. package/templates/serve-static-assets.ts +17 -14
  217. package/templates/service-bindings-module-facade.js +1 -0
  218. package/templates/tsconfig-sanity.ts +11 -0
  219. package/templates/tsconfig.init.json +105 -0
  220. package/templates/tsconfig.json +5 -103
  221. package/templates/tsconfig.tsbuildinfo +1 -0
  222. package/wrangler-dist/cli.d.ts +826 -77
  223. package/wrangler-dist/cli.js +130734 -140838
  224. package/wrangler-dist/wasm-sync.wasm +0 -0
  225. package/src/__tests__/api-devregistry.test.js +0 -57
  226. package/src/__tests__/d1.test.ts +0 -72
  227. package/src/__tests__/dialogs.test.tsx +0 -40
  228. package/src/__tests__/helpers/mock-cfetch.ts +0 -333
  229. package/src/__tests__/pages.test.ts +0 -2223
  230. package/src/dialogs.tsx +0 -163
  231. package/src/environment-variables.ts +0 -50
  232. package/src/pages/build.tsx +0 -238
  233. package/src/user/env-vars.ts +0 -46
  234. package/templates/experimental-local-cache-stubs.js +0 -27
  235. /package/src/{bundle-reporter.tsx → bundle-reporter.ts} +0 -0
  236. /package/src/dev/{get-local-persistence-path.tsx → get-local-persistence-path.ts} +0 -0
  237. /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/versions/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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2",
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: 2",
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: 2",
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2",
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: 2"
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: 2",
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: 2"
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: 2",
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: 2",
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: 2",
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2",
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: 2"
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: 2"
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: 2",
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: 2",
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2",
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: 2",
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: 2"
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: 2"
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/versions/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: 2",
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: 2",
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2",
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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: 2"
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,48 +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: 2"
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:
5873
-
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
5880
-
5881
- "
5882
- `);
5883
- });
5884
- });
6132
+ "▲ [WARNING] Processing wrangler.toml configuration:
5885
6133
 
5886
- describe("[metadata_binding]", () => {
5887
- it("should pass metadata binding to backend", async () => {
5888
- writeWranglerToml({
5889
- metadata_binding: "nasm_A19750603000",
5890
- });
5891
- writeWorkerSource();
5892
- mockSubDomainRequest();
5893
- mockUploadWorkerRequest({
5894
- expectedBindings: [{ name: "nasm_A19750603000", type: "metadata" }],
5895
- });
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
5896
6140
 
5897
- await runWrangler("publish index.js");
5898
- expect(std.out).toMatchInlineSnapshot(`
5899
- "Total Upload: xx KiB / gzip: xx KiB
5900
- Your worker has access to the following bindings:
5901
- - Metadata Binding:
5902
- - metadata: nasm_A19750603000
5903
- Uploaded test-name (TIMINGS)
5904
- Published test-name (TIMINGS)
5905
- https://test-name.test-sub-domain.workers.dev
5906
- Current Deployment: 2"
6141
+ "
5907
6142
  `);
5908
- expect(std.err).toMatchInlineSnapshot(`""`);
5909
- expect(std.warn).toMatchInlineSnapshot(`""`);
5910
6143
  });
5911
6144
  });
5912
6145
  });
@@ -5939,7 +6172,7 @@ addEventListener('fetch', event => {});`
5939
6172
  Uploaded test-name (TIMINGS)
5940
6173
  Published test-name (TIMINGS)
5941
6174
  https://test-name.test-sub-domain.workers.dev
5942
- Current Deployment: 2"
6175
+ Current Deployment ID: Galaxy-Class"
5943
6176
  `);
5944
6177
  expect(std.err).toMatchInlineSnapshot(`""`);
5945
6178
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -5969,7 +6202,7 @@ addEventListener('fetch', event => {});`
5969
6202
  Uploaded test-name (TIMINGS)
5970
6203
  Published test-name (TIMINGS)
5971
6204
  https://test-name.test-sub-domain.workers.dev
5972
- Current Deployment: 2"
6205
+ Current Deployment ID: Galaxy-Class"
5973
6206
  `);
5974
6207
  expect(std.err).toMatchInlineSnapshot(`""`);
5975
6208
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -6003,24 +6236,24 @@ addEventListener('fetch', event => {});`
6003
6236
  Uploaded test-name (TIMINGS)
6004
6237
  Published test-name (TIMINGS)
6005
6238
  https://test-name.test-sub-domain.workers.dev
6006
- Current Deployment: 2"
6239
+ Current Deployment ID: Galaxy-Class"
6007
6240
  `);
6008
6241
  expect(std.err).toMatchInlineSnapshot(`""`);
6009
6242
  expect(std.warn).toMatchInlineSnapshot(`
6010
- "▲ [WARNING] Processing wrangler.toml configuration:
6243
+ "▲ [WARNING] Processing wrangler.toml configuration:
6011
6244
 
6012
- - Deprecation: The \`build.upload.rules\` config field is no longer used, the rules should be
6013
- specified via the \`rules\` config field. Delete the \`build.upload\` field from the configuration
6014
- file, and add this:
6015
- \`\`\`
6016
- [[rules]]
6017
- type = \\"Text\\"
6018
- globs = [ \\"**/*.file\\" ]
6019
- fallthrough = true
6020
- \`\`\`
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
+ \`\`\`
6021
6254
 
6022
- "
6023
- `);
6255
+ "
6256
+ `);
6024
6257
  });
6025
6258
 
6026
6259
  it("should be able to use fallthrough:true for multiple rules", async () => {
@@ -6053,7 +6286,7 @@ addEventListener('fetch', event => {});`
6053
6286
  Uploaded test-name (TIMINGS)
6054
6287
  Published test-name (TIMINGS)
6055
6288
  https://test-name.test-sub-domain.workers.dev
6056
- Current Deployment: 2"
6289
+ Current Deployment ID: Galaxy-Class"
6057
6290
  `);
6058
6291
  expect(std.err).toMatchInlineSnapshot(`""`);
6059
6292
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -6151,7 +6384,7 @@ addEventListener('fetch', event => {});`
6151
6384
  Uploaded test-name (TIMINGS)
6152
6385
  Published test-name (TIMINGS)
6153
6386
  https://test-name.test-sub-domain.workers.dev
6154
- Current Deployment: 2"
6387
+ Current Deployment ID: Galaxy-Class"
6155
6388
  `);
6156
6389
  expect(std.err).toMatchInlineSnapshot(`""`);
6157
6390
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -6182,14 +6415,14 @@ addEventListener('fetch', event => {});`
6182
6415
  Uploaded test-name (TIMINGS)
6183
6416
  Published test-name (TIMINGS)
6184
6417
  https://test-name.test-sub-domain.workers.dev
6185
- Current Deployment: 2"
6418
+ Current Deployment ID: Galaxy-Class"
6186
6419
  `);
6187
6420
  expect(std.err).toMatchInlineSnapshot(`""`);
6188
6421
  expect(std.warn).toMatchInlineSnapshot(`
6189
- "▲ [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\\";
6190
6423
 
6191
- "
6192
- `);
6424
+ "
6425
+ `);
6193
6426
  });
6194
6427
 
6195
6428
  it("should work with legacy module specifiers, with a deprecation warning (2)", async () => {
@@ -6212,14 +6445,14 @@ addEventListener('fetch', event => {});`
6212
6445
  Uploaded test-name (TIMINGS)
6213
6446
  Published test-name (TIMINGS)
6214
6447
  https://test-name.test-sub-domain.workers.dev
6215
- Current Deployment: 2"
6448
+ Current Deployment ID: Galaxy-Class"
6216
6449
  `);
6217
6450
  expect(std.err).toMatchInlineSnapshot(`""`);
6218
6451
  expect(std.warn).toMatchInlineSnapshot(`
6219
- "▲ [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\\";
6220
6453
 
6221
- "
6222
- `);
6454
+ "
6455
+ `);
6223
6456
  });
6224
6457
 
6225
6458
  it("should work with legacy module specifiers, with a deprecation warning (3)", async () => {
@@ -6244,18 +6477,18 @@ addEventListener('fetch', event => {});`
6244
6477
  Uploaded test-name (TIMINGS)
6245
6478
  Published test-name (TIMINGS)
6246
6479
  https://test-name.test-sub-domain.workers.dev
6247
- Current Deployment: 2"
6480
+ Current Deployment ID: Galaxy-Class"
6248
6481
  `);
6249
6482
  expect(std.err).toMatchInlineSnapshot(`""`);
6250
6483
  expect(std.warn).toMatchInlineSnapshot(`
6251
- "▲ [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\\";
6252
6485
 
6253
- "
6254
- `);
6486
+ "
6487
+ `);
6255
6488
  });
6256
6489
 
6257
6490
  it("should not match regular module specifiers when there aren't any possible legacy module matches", async () => {
6258
- // see https://github.com/cloudflare/wrangler2/issues/655 for bug details
6491
+ // see https://github.com/cloudflare/workers-sdk/issues/655 for bug details
6259
6492
 
6260
6493
  fs.writeFileSync(
6261
6494
  "./index.js",
@@ -6274,7 +6507,7 @@ addEventListener('fetch', event => {});`
6274
6507
  Uploaded test-name (TIMINGS)
6275
6508
  Published test-name (TIMINGS)
6276
6509
  https://test-name.test-sub-domain.workers.dev
6277
- Current Deployment: 2"
6510
+ Current Deployment ID: Galaxy-Class"
6278
6511
  `);
6279
6512
  expect(std.err).toMatchInlineSnapshot(`""`);
6280
6513
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -6312,19 +6545,33 @@ addEventListener('fetch', event => {});`
6312
6545
  Object {
6313
6546
  "debug": "",
6314
6547
  "err": "",
6548
+ "info": "",
6315
6549
  "out": "Total Upload: xx KiB / gzip: xx KiB
6316
6550
  Uploaded test-name (TIMINGS)
6317
6551
  Published test-name (TIMINGS)
6318
6552
  https://test-name.test-sub-domain.workers.dev
6319
- Current Deployment: 2",
6553
+ Current Deployment ID: Galaxy-Class",
6320
6554
  "warn": "",
6321
6555
  }
6322
6556
  `);
6323
6557
  });
6324
6558
 
6325
- 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 () => {
6326
6560
  writeWranglerToml();
6327
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
+ );
6328
6575
  fs.writeFileSync(
6329
6576
  "tsconfig.json",
6330
6577
  JSON.stringify({
@@ -6335,19 +6582,26 @@ addEventListener('fetch', event => {});`
6335
6582
  })
6336
6583
  );
6337
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
+ */
6338
6591
  mockUploadWorkerRequest({
6339
- expectedEntry: "export {", // just check that the export is preserved
6592
+ expectedEntry: "export {", // check that the export is preserved
6340
6593
  });
6341
6594
  await runWrangler("publish index.js"); // this would throw if we tried to compile with es5
6342
6595
  expect(std).toMatchInlineSnapshot(`
6343
6596
  Object {
6344
6597
  "debug": "",
6345
6598
  "err": "",
6599
+ "info": "",
6346
6600
  "out": "Total Upload: xx KiB / gzip: xx KiB
6347
6601
  Uploaded test-name (TIMINGS)
6348
6602
  Published test-name (TIMINGS)
6349
6603
  https://test-name.test-sub-domain.workers.dev
6350
- Current Deployment: 2",
6604
+ Current Deployment ID: Galaxy-Class",
6351
6605
  "warn": "",
6352
6606
  }
6353
6607
  `);
@@ -6367,11 +6621,110 @@ addEventListener('fetch', event => {});`
6367
6621
  Object {
6368
6622
  "debug": "",
6369
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": "",
6370
6723
  "out": "Total Upload: xx KiB / gzip: xx KiB
6371
6724
  Uploaded test-name (TIMINGS)
6372
6725
  Published test-name (TIMINGS)
6373
6726
  https://test-name.test-sub-domain.workers.dev
6374
- Current Deployment: 2",
6727
+ Current Deployment ID: Galaxy-Class",
6375
6728
  "warn": "",
6376
6729
  }
6377
6730
  `);
@@ -6395,6 +6748,7 @@ addEventListener('fetch', event => {});`
6395
6748
  Object {
6396
6749
  "debug": "",
6397
6750
  "err": "",
6751
+ "info": "",
6398
6752
  "out": "Total Upload: xx KiB / gzip: xx KiB
6399
6753
  Your worker has access to the following bindings:
6400
6754
  - Durable Objects:
@@ -6412,16 +6766,17 @@ addEventListener('fetch', event => {});`
6412
6766
  writeWorkerSource();
6413
6767
  await runWrangler("publish index.js --node-compat --dry-run");
6414
6768
  expect(std).toMatchInlineSnapshot(`
6415
- Object {
6416
- "debug": "",
6417
- "err": "",
6418
- "out": "Total Upload: xx KiB / gzip: xx KiB
6419
- --dry-run: exiting now.",
6420
- "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.
6421
-
6422
- ",
6423
- }
6424
- `);
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
+ `);
6425
6780
  });
6426
6781
 
6427
6782
  it("should recommend node compatibility mode when using node builtins and node-compat isn't enabled", async () => {
@@ -6459,22 +6814,96 @@ addEventListener('fetch', event => {});`
6459
6814
  );
6460
6815
  await runWrangler("publish index.js --node-compat --dry-run"); // this would throw if node compatibility didn't exist
6461
6816
  expect(std).toMatchInlineSnapshot(`
6462
- Object {
6463
- "debug": "",
6464
- "err": "",
6465
- "out": "Total Upload: xx KiB / gzip: xx KiB
6466
- --dry-run: exiting now.",
6467
- "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.
6468
-
6469
- ",
6470
- }
6471
- `);
6472
- });
6473
- });
6474
-
6475
- describe("bundle reporter", () => {
6476
- it("should print the bundle size", async () => {
6477
- fs.writeFileSync(
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
+ `);
6828
+ });
6829
+ });
6830
+
6831
+ describe("`nodejs_compat` compatibility flag", () => {
6832
+ it('when absent, should error on any "external" `node:*` imports', async () => {
6833
+ writeWranglerToml();
6834
+ fs.writeFileSync(
6835
+ "index.js",
6836
+ `
6837
+ import AsyncHooks from 'node:async_hooks';
6838
+ console.log(AsyncHooks);
6839
+ export default {}
6840
+ `
6841
+ );
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(
6478
6907
  "./text.txt",
6479
6908
  `${new Array(100)
6480
6909
  .fill("Try not. Do or do not. There is no try.")
@@ -6508,34 +6937,45 @@ addEventListener('fetch', event => {});`
6508
6937
  mockSubDomainRequest();
6509
6938
  mockUploadWorkerRequest();
6510
6939
  await runWrangler("publish");
6940
+
6511
6941
  expect(std).toMatchInlineSnapshot(`
6512
6942
  Object {
6513
6943
  "debug": "",
6514
6944
  "err": "",
6945
+ "info": "",
6515
6946
  "out": "Total Upload: xx KiB / gzip: xx KiB
6516
6947
  Uploaded test-name (TIMINGS)
6517
6948
  Published test-name (TIMINGS)
6518
6949
  https://test-name.test-sub-domain.workers.dev
6519
- Current Deployment: 2",
6950
+ Current Deployment ID: Galaxy-Class",
6520
6951
  "warn": "",
6521
6952
  }
6522
6953
  `);
6523
6954
  });
6524
6955
 
6525
6956
  it("should print the bundle size, with API errors", async () => {
6526
- setMockRawResponse(
6527
- "/accounts/:accountId/workers/scripts/:scriptName",
6528
- "PUT",
6529
- () => {
6530
- return createFetchResult({}, false, [
6531
- {
6532
- code: 11337,
6533
- message:
6534
- "Script startup timed out. This could be due to script exceeding size limits or expensive code in the global scope.",
6535
- },
6536
- ]);
6537
- }
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
+ )
6538
6977
  );
6978
+
6539
6979
  fs.writeFileSync(
6540
6980
  "./hello.html",
6541
6981
  `<!DOCTYPE html>
@@ -6556,35 +6996,57 @@ addEventListener('fetch', event => {});`
6556
6996
  },
6557
6997
  };`
6558
6998
  );
6999
+
6559
7000
  writeWranglerToml({
6560
7001
  main: "index.js",
6561
7002
  });
6562
- mockSubDomainRequest();
6563
- mockUploadWorkerRequest();
7003
+
6564
7004
  await expect(runWrangler("publish")).rejects.toMatchInlineSnapshot(
6565
7005
  `[ParseError: A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name) failed.]`
6566
7006
  );
6567
7007
  expect(std).toMatchInlineSnapshot(`
6568
- Object {
6569
- "debug": "",
6570
- "err": "",
6571
- "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
6572
7013
 
6573
- 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.
6574
7015
 
6575
- Script startup timed out. This could be due to script exceeding size limits or expensive code in
6576
- 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]
6577
7018
 
6578
- If you think this is a bug, please open an issue at:
6579
- 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
6580
7021
 
6581
- ",
6582
- "warn": "",
6583
- }
6584
- `);
7022
+ ",
7023
+ "warn": "",
7024
+ }
7025
+ `);
6585
7026
  });
6586
7027
 
6587
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
+
6588
7050
  fs.writeFileSync("dependency.js", `export const thing = "a string dep";`);
6589
7051
 
6590
7052
  fs.writeFileSync(
@@ -6597,27 +7059,20 @@ addEventListener('fetch', event => {});`
6597
7059
  }
6598
7060
  }`
6599
7061
  );
6600
- setMockRawResponse(
6601
- "/accounts/:accountId/workers/scripts/:scriptName",
6602
- "PUT",
6603
- () => {
6604
- return createFetchResult({}, false, [
6605
- { code: 10027, message: "workers.api.error.script_too_large" },
6606
- ]);
6607
- }
6608
- );
7062
+
6609
7063
  writeWranglerToml({
6610
7064
  main: "index.js",
6611
7065
  });
6612
- mockSubDomainRequest();
6613
- mockUploadWorkerRequest();
7066
+
6614
7067
  await expect(runWrangler("publish")).rejects.toMatchInlineSnapshot(
6615
7068
  `[ParseError: A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name) failed.]`
6616
7069
  );
7070
+
6617
7071
  expect(std).toMatchInlineSnapshot(`
6618
7072
  Object {
6619
7073
  "debug": "",
6620
7074
  "err": "",
7075
+ "info": "",
6621
7076
  "out": "Total Upload: xx KiB / gzip: xx KiB
6622
7077
 
6623
7078
  X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name) failed.
@@ -6625,7 +7080,7 @@ addEventListener('fetch', event => {});`
6625
7080
  workers.api.error.script_too_large [code: 10027]
6626
7081
 
6627
7082
  If you think this is a bug, please open an issue at:
6628
- https://github.com/cloudflare/wrangler2/issues/new/choose
7083
+ https://github.com/cloudflare/workers-sdk/issues/new/choose
6629
7084
 
6630
7085
  ",
6631
7086
  "warn": "▲ [WARNING] Here are the 2 largest dependencies included in your script:
@@ -6639,7 +7094,27 @@ addEventListener('fetch', event => {});`
6639
7094
  `);
6640
7095
  });
6641
7096
 
6642
- 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
+ );
6643
7118
  fs.writeFileSync("dependency.js", `export const thing = "a string dep";`);
6644
7119
 
6645
7120
  fs.writeFileSync(
@@ -6652,23 +7127,11 @@ addEventListener('fetch', event => {});`
6652
7127
  }
6653
7128
  }`
6654
7129
  );
6655
- setMockRawResponse(
6656
- "/accounts/:accountId/workers/scripts/:scriptName",
6657
- "PUT",
6658
- () => {
6659
- return createFetchResult({}, false, [
6660
- {
6661
- code: 10021,
6662
- message: "Error: Script startup exceeded CPU time limit.",
6663
- },
6664
- ]);
6665
- }
6666
- );
7130
+
6667
7131
  writeWranglerToml({
6668
7132
  main: "index.js",
6669
7133
  });
6670
- mockSubDomainRequest();
6671
- mockUploadWorkerRequest();
7134
+
6672
7135
  await expect(runWrangler("publish")).rejects.toMatchInlineSnapshot(
6673
7136
  `[ParseError: A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name) failed.]`
6674
7137
  );
@@ -6676,6 +7139,7 @@ addEventListener('fetch', event => {});`
6676
7139
  Object {
6677
7140
  "debug": "",
6678
7141
  "err": "",
7142
+ "info": "",
6679
7143
  "out": "Total Upload: xx KiB / gzip: xx KiB
6680
7144
 
6681
7145
  X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name) failed.
@@ -6683,14 +7147,16 @@ addEventListener('fetch', event => {});`
6683
7147
  Error: Script startup exceeded CPU time limit. [code: 10021]
6684
7148
 
6685
7149
  If you think this is a bug, please open an issue at:
6686
- https://github.com/cloudflare/wrangler2/issues/new/choose
7150
+ https://github.com/cloudflare/workers-sdk/issues/new/choose
6687
7151
 
6688
7152
  ",
6689
- "warn": "▲ [WARNING] Here are the 2 largest dependencies included in your script:
7153
+ "warn": "▲ [WARNING] Your Worker failed validation because it exceeded startup limits.
6690
7154
 
6691
- - index.js - xx KiB
6692
- - dependency.js - xx KiB
6693
- 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.
6694
7160
 
6695
7161
  ",
6696
7162
  }
@@ -6712,6 +7178,7 @@ addEventListener('fetch', event => {});`
6712
7178
  Object {
6713
7179
  "debug": "",
6714
7180
  "err": "",
7181
+ "info": "",
6715
7182
  "out": "Total Upload: xx KiB / gzip: xx KiB",
6716
7183
  "warn": "▲ [WARNING] We recommend keeping your script less than 1MiB (1024 KiB) after gzip. Exceeding past this can affect cold start time
6717
7184
 
@@ -6734,6 +7201,7 @@ addEventListener('fetch', event => {});`
6734
7201
  Object {
6735
7202
  "debug": "",
6736
7203
  "err": "",
7204
+ "info": "",
6737
7205
  "out": "Total Upload: xx KiB / gzip: xx KiB",
6738
7206
  "warn": "",
6739
7207
  }
@@ -6762,6 +7230,7 @@ addEventListener('fetch', event => {});`
6762
7230
  Object {
6763
7231
  "debug": "",
6764
7232
  "err": "",
7233
+ "info": "",
6765
7234
  "out": "",
6766
7235
  "warn": "▲ [WARNING] Here are the 5 largest dependencies included in your script:
6767
7236
 
@@ -6851,7 +7320,7 @@ addEventListener('fetch', event => {});`
6851
7320
  "publish index.js --no-bundle --node-compat --dry-run --outdir dist"
6852
7321
  );
6853
7322
  expect(std.warn).toMatchInlineSnapshot(`
6854
- "▲ [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.
6855
7324
 
6856
7325
 
6857
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.
@@ -6871,7 +7340,7 @@ addEventListener('fetch', event => {});`
6871
7340
  fs.writeFileSync("index.js", scriptContent);
6872
7341
  await runWrangler("publish index.js --dry-run --outdir dist");
6873
7342
  expect(std.warn).toMatchInlineSnapshot(`
6874
- "▲ [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.
6875
7344
 
6876
7345
 
6877
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.
@@ -6881,63 +7350,37 @@ addEventListener('fetch', event => {});`
6881
7350
  });
6882
7351
  });
6883
7352
 
6884
- it("should publish if the last deployed source check fails", async () => {
6885
- unsetAllMocks();
6886
- writeWorkerSource();
6887
- writeWranglerToml();
6888
- mockSubDomainRequest();
6889
- mockUploadWorkerRequest();
6890
- setMockResponse(
6891
- "/accounts/:accountId/workers/versions/by-script/:scriptTag",
6892
- () => ({
6893
- latest: { number: "2" },
6894
- })
6895
- );
6896
- setMockRawResponse(
6897
- "/accounts/:accountId/workers/services/:scriptName",
6898
- "GET",
6899
- () => {
6900
- return createFetchResult(null, false, [
6901
- { code: 10090, message: "workers.api.error.service_not_found" },
6902
- ]);
6903
- }
6904
- );
6905
-
6906
- await runWrangler("publish index.js");
6907
- expect(std).toMatchInlineSnapshot(`
6908
- Object {
6909
- "debug": "",
6910
- "err": "",
6911
- "out": "Total Upload: xx KiB / gzip: xx KiB
6912
- Uploaded test-name (TIMINGS)
6913
- Published test-name (TIMINGS)
6914
- https://test-name.test-sub-domain.workers.dev
6915
- Current Deployment: 2",
6916
- "warn": "",
6917
- }
6918
- `);
6919
- });
6920
-
6921
7353
  it("should not publish if there's any other kind of error when checking deployment source", async () => {
6922
- unsetAllMocks();
6923
7354
  writeWorkerSource();
6924
7355
  writeWranglerToml();
6925
7356
  mockSubDomainRequest();
6926
7357
  mockUploadWorkerRequest();
6927
- setMockRawResponse(
6928
- "/accounts/:accountId/workers/services/:scriptName",
6929
- "GET",
6930
- () => {
6931
- return createFetchResult(null, false, [
6932
- { code: 10000, message: "Authentication error" },
6933
- ]);
6934
- }
6935
- );
6936
- setMockResponse(
6937
- "/accounts/:accountId/workers/versions/by-script/:scriptTag",
6938
- () => ({
6939
- latest: { number: "2" },
6940
- })
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
+ )
6941
7384
  );
6942
7385
 
6943
7386
  await runWrangler("publish index.js");
@@ -6975,7 +7418,7 @@ addEventListener('fetch', event => {});`
6975
7418
  Uploaded test-name (TIMINGS)
6976
7419
  Published test-name (TIMINGS)
6977
7420
  https://test-name.test-sub-domain.workers.dev
6978
- Current Deployment: 2"
7421
+ Current Deployment ID: Galaxy-Class"
6979
7422
  `);
6980
7423
  });
6981
7424
 
@@ -7012,7 +7455,84 @@ addEventListener('fetch', event => {});`
7012
7455
  Published test-name (TIMINGS)
7013
7456
  https://test-name.test-sub-domain.workers.dev
7014
7457
  Consumer for queue1
7015
- Current Deployment: 2"
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"
7016
7536
  `);
7017
7537
  });
7018
7538
 
@@ -7063,6 +7583,37 @@ addEventListener('fetch', event => {});`
7063
7583
  });
7064
7584
  });
7065
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
+
7066
7617
  describe("--keep-vars", () => {
7067
7618
  it("should send keepVars when keep-vars is passed in", async () => {
7068
7619
  process.env = {
@@ -7084,7 +7635,7 @@ addEventListener('fetch', event => {});`
7084
7635
  Uploaded test-name (TIMINGS)
7085
7636
  Published test-name (TIMINGS)
7086
7637
  https://test-name.test-sub-domain.workers.dev
7087
- Current Deployment: 2"
7638
+ Current Deployment ID: Galaxy-Class"
7088
7639
  `);
7089
7640
  expect(std.err).toMatchInlineSnapshot(`""`);
7090
7641
  });
@@ -7109,7 +7660,34 @@ addEventListener('fetch', event => {});`
7109
7660
  Uploaded test-name (TIMINGS)
7110
7661
  Published test-name (TIMINGS)
7111
7662
  https://test-name.test-sub-domain.workers.dev
7112
- Current Deployment: 2"
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"
7113
7691
  `);
7114
7692
  expect(std.err).toMatchInlineSnapshot(`""`);
7115
7693
  });
@@ -7129,12 +7707,19 @@ function writeAssets(
7129
7707
  fs.writeFileSync(filePathDestination, asset.content);
7130
7708
  }
7131
7709
  }
7710
+ function mockDeploymentsListRequest() {
7711
+ msw.use(...mswSuccessDeployments);
7712
+ }
7713
+
7714
+ function mockLastDeploymentRequest() {
7715
+ msw.use(...mswSuccessDeploymentScriptMetadata);
7716
+ }
7132
7717
 
7133
7718
  /** Create a mock handler for the request to upload a worker script. */
7134
7719
  function mockUploadWorkerRequest(
7135
7720
  options: {
7136
7721
  available_on_subdomain?: boolean;
7137
- expectedEntry?: string;
7722
+ expectedEntry?: string | RegExp;
7138
7723
  expectedMainModule?: string;
7139
7724
  expectedType?: "esm" | "sw";
7140
7725
  expectedBindings?: unknown;
@@ -7142,9 +7727,9 @@ function mockUploadWorkerRequest(
7142
7727
  expectedCompatibilityDate?: string;
7143
7728
  expectedCompatibilityFlags?: string[];
7144
7729
  expectedMigrations?: CfWorkerInit["migrations"];
7730
+ expectedUnsafeMetaData?: Record<string, string>;
7145
7731
  env?: string;
7146
7732
  legacyEnv?: boolean;
7147
- sendScriptIds?: boolean;
7148
7733
  keepVars?: boolean;
7149
7734
  tag?: string;
7150
7735
  } = {}
@@ -7161,76 +7746,97 @@ function mockUploadWorkerRequest(
7161
7746
  env = undefined,
7162
7747
  legacyEnv = false,
7163
7748
  expectedMigrations,
7164
- sendScriptIds,
7749
+ expectedUnsafeMetaData,
7165
7750
  keepVars,
7166
7751
  } = options;
7167
- setMockResponse(
7168
- env && !legacyEnv
7169
- ? "/accounts/:accountId/workers/services/:scriptName/environments/:envName"
7170
- : "/accounts/:accountId/workers/scripts/:scriptName",
7171
- "PUT",
7172
- async ([_url, accountId, scriptName, envName], { body }, queryParams) => {
7173
- expect(accountId).toEqual("some-account-id");
7174
- expect(scriptName).toEqual(
7175
- legacyEnv && env ? `test-name-${env}` : "test-name"
7176
- );
7177
- if (!legacyEnv) {
7178
- expect(envName).toEqual(env);
7179
- }
7180
- expect(queryParams.get("include_subdomain_availability")).toEqual("true");
7181
- expect(queryParams.get("excludeScript")).toEqual("true");
7182
- const formBody = body as FormData;
7183
- if (expectedEntry !== undefined) {
7184
- expect(await (formBody.get("index.js") as File).text()).toMatch(
7185
- expectedEntry
7186
- );
7187
- }
7188
- const metadata = JSON.parse(
7189
- formBody.get("metadata") as string
7190
- ) as WorkerMetadata;
7191
- if (expectedType === "esm") {
7192
- expect(metadata.main_module).toEqual(expectedMainModule);
7193
- } else {
7194
- expect(metadata.body_part).toEqual("index.js");
7195
- }
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
+ }
7196
7767
 
7197
- if (keepVars) {
7198
- expect(metadata.keep_bindings).toEqual(["plain_text", "json"]);
7199
- } else {
7200
- expect(metadata.keep_bindings).toBeFalsy();
7201
- }
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");
7202
7784
 
7203
- if ("expectedBindings" in options) {
7204
- expect(metadata.bindings).toEqual(expectedBindings);
7205
- }
7206
- if ("expectedCompatibilityDate" in options) {
7207
- expect(metadata.compatibility_date).toEqual(expectedCompatibilityDate);
7208
- }
7209
- if ("expectedCompatibilityFlags" in options) {
7210
- expect(metadata.compatibility_flags).toEqual(
7211
- expectedCompatibilityFlags
7212
- );
7213
- }
7214
- if ("expectedMigrations" in options) {
7215
- expect(metadata.migrations).toEqual(expectedMigrations);
7216
- }
7217
- for (const [name, content] of Object.entries(expectedModules)) {
7218
- expect(await (formBody.get(name) as File).text()).toEqual(content);
7219
- }
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
+ }
7220
7799
 
7221
- return {
7222
- available_on_subdomain,
7223
- ...(sendScriptIds
7224
- ? {
7225
- id: "abc12345",
7226
- etag: "etag98765",
7227
- pipeline_hash: "hash9999",
7228
- tag: "sample-tag",
7229
- }
7230
- : {}),
7231
- };
7800
+ if (keepVars) {
7801
+ expect(metadata.keep_bindings).toEqual(["plain_text", "json"]);
7802
+ } else {
7803
+ expect(metadata.keep_bindings).toBeFalsy();
7232
7804
  }
7233
- );
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
+ }
7234
7840
  }
7235
7841
 
7236
7842
  /** Create a mock handler for the request to get the account's subdomain. */
@@ -7239,18 +7845,30 @@ function mockSubDomainRequest(
7239
7845
  registeredWorkersDev = true
7240
7846
  ) {
7241
7847
  if (registeredWorkersDev) {
7242
- setMockResponse("/accounts/:accountId/workers/subdomain", "GET", () => {
7243
- return { subdomain };
7244
- });
7848
+ msw.use(
7849
+ rest.get("*/accounts/:accountId/workers/subdomain", (req, res, ctx) => {
7850
+ return res.once(ctx.json(createFetchResult({ subdomain })));
7851
+ })
7852
+ );
7245
7853
  } else {
7246
- setMockRawResponse("/accounts/:accountId/workers/subdomain", "GET", () => {
7247
- return createFetchResult(null, false, [
7248
- { code: 10007, message: "haven't registered workers.dev" },
7249
- ]);
7250
- });
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
+ );
7251
7865
  }
7252
7866
  }
7253
-
7867
+ //
7868
+ //
7869
+ //
7870
+ //
7871
+ //
7254
7872
  /** Create a mock handler to toggle a <script>.<user>.workers.dev subdomain */
7255
7873
  function mockUpdateWorkerRequest({
7256
7874
  env,
@@ -7264,20 +7882,22 @@ function mockUpdateWorkerRequest({
7264
7882
  const requests = { count: 0 };
7265
7883
  const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
7266
7884
  const environment = env && !legacyEnv ? "/environments/:envName" : "";
7267
- setMockResponse(
7268
- `/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/subdomain`,
7269
- "POST",
7270
- ([_url, accountId, scriptName, envName], { body }) => {
7271
- expect(accountId).toEqual("some-account-id");
7272
- expect(scriptName).toEqual(
7273
- legacyEnv && env ? `test-name-${env}` : "test-name"
7274
- );
7275
- if (!legacyEnv) {
7276
- 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)));
7277
7899
  }
7278
- expect(JSON.parse(body as string)).toEqual({ enabled });
7279
- return null;
7280
- }
7900
+ )
7281
7901
  );
7282
7902
  return requests;
7283
7903
  }
@@ -7294,25 +7914,26 @@ function mockPublishRoutesRequest({
7294
7914
  const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
7295
7915
  const environment = env && !legacyEnv ? "/environments/:envName" : "";
7296
7916
 
7297
- setMockResponse(
7298
- `/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/routes`,
7299
- "PUT",
7300
- ([_url, accountId, scriptName, envName], { body }) => {
7301
- expect(accountId).toEqual("some-account-id");
7302
- expect(scriptName).toEqual(
7303
- legacyEnv && env ? `test-name-${env}` : "test-name"
7304
- );
7305
- if (!legacyEnv) {
7306
- 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)));
7307
7935
  }
7308
-
7309
- expect(JSON.parse(body as string)).toEqual(
7310
- routes.map((route) =>
7311
- typeof route !== "object" ? { pattern: route } : route
7312
- )
7313
- );
7314
- return null;
7315
- }
7936
+ )
7316
7937
  );
7317
7938
  }
7318
7939
 
@@ -7326,13 +7947,19 @@ function mockUnauthorizedPublishRoutesRequest({
7326
7947
  const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
7327
7948
  const environment = env && !legacyEnv ? "/environments/:envName" : "";
7328
7949
 
7329
- setMockRawResponse(
7330
- `/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/routes`,
7331
- "PUT",
7332
- () =>
7333
- createFetchResult(null, false, [
7334
- { message: "Authentication error", code: 10000 },
7335
- ])
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
+ )
7336
7963
  );
7337
7964
  }
7338
7965
 
@@ -7340,22 +7967,27 @@ function mockPublishRoutesFallbackRequest(route: {
7340
7967
  pattern: string;
7341
7968
  script: string;
7342
7969
  }) {
7343
- setMockResponse(`/zones/:zoneId/workers/routes`, "POST", (_url, { body }) => {
7344
- expect(JSON.parse(body as string)).toEqual(route);
7345
- return route.pattern;
7346
- });
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
+ );
7347
7977
  }
7348
7978
 
7349
7979
  function mockCustomDomainLookup(origin: CustomDomain) {
7350
- setMockResponse(
7351
- `/accounts/:accountId/workers/domains/records/:domainTag`,
7352
- "GET",
7353
- ([_url, accountId, domainTag]) => {
7354
- expect(accountId).toEqual("some-account-id");
7355
- expect(domainTag).toEqual(origin.id);
7356
-
7357
- return origin;
7358
- }
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
+ )
7359
7991
  );
7360
7992
  }
7361
7993
 
@@ -7372,47 +8004,47 @@ function mockCustomDomainsChangesetRequest({
7372
8004
  }) {
7373
8005
  const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
7374
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
+ }
7375
8018
 
7376
- setMockResponse(
7377
- `/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/domains/changeset`,
7378
- "POST",
7379
- ([_url, accountId, scriptName, envName], { body }) => {
7380
- expect(accountId).toEqual("some-account-id");
7381
- expect(scriptName).toEqual(
7382
- legacyEnv && env ? `test-name-${env}` : "test-name"
7383
- );
7384
- if (!legacyEnv) {
7385
- expect(envName).toEqual(env);
7386
- }
8019
+ const domains: Array<
8020
+ { hostname: string } & ({ zone_id?: string } | { zone_name?: string })
8021
+ > = await req.json();
7387
8022
 
7388
- const domains: Array<
7389
- { hostname: string } & ({ zone_id?: string } | { zone_name?: string })
7390
- > = JSON.parse(body as string);
7391
-
7392
- const changeset: CustomDomainChangeset = {
7393
- added: domains.map((domain) => {
7394
- return {
7395
- ...domain,
7396
- id: "",
7397
- service: scriptName,
7398
- environment: envName,
7399
- zone_name: "",
7400
- zone_id: "",
7401
- };
7402
- }),
7403
- removed: [],
7404
- updated:
7405
- originConflicts?.map((domain) => {
8023
+ const changeset: CustomDomainChangeset = {
8024
+ added: domains.map((domain) => {
7406
8025
  return {
7407
8026
  ...domain,
7408
- modified: true,
8027
+ id: "",
8028
+ service: req.params.scriptName as string,
8029
+ environment: req.params.envName as string,
8030
+ zone_name: "",
8031
+ zone_id: "",
7409
8032
  };
7410
- }) ?? [],
7411
- conflicting: dnsRecordConflicts,
7412
- };
8033
+ }),
8034
+ removed: [],
8035
+ updated:
8036
+ originConflicts?.map((domain) => {
8037
+ return {
8038
+ ...domain,
8039
+ modified: true,
8040
+ };
8041
+ }) ?? [],
8042
+ conflicting: dnsRecordConflicts,
8043
+ };
7413
8044
 
7414
- return changeset;
7415
- }
8045
+ return res.once(ctx.json(createFetchResult(changeset)));
8046
+ }
8047
+ )
7416
8048
  );
7417
8049
  }
7418
8050
 
@@ -7436,37 +8068,36 @@ function mockPublishCustomDomainsRequest({
7436
8068
  const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
7437
8069
  const environment = env && !legacyEnv ? "/environments/:envName" : "";
7438
8070
 
7439
- setMockResponse(
7440
- `/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/domains/records`,
7441
- "PUT",
7442
- ([_url, accountId, scriptName, envName], { body }) => {
7443
- expect(accountId).toEqual("some-account-id");
7444
- expect(scriptName).toEqual(
7445
- legacyEnv && env ? `test-name-${env}` : "test-name"
7446
- );
7447
- if (!legacyEnv) {
7448
- expect(envName).toEqual(env);
7449
- }
7450
-
7451
- expect(JSON.parse(body as string)).toEqual({
7452
- ...publishFlags,
7453
- origins: domains,
7454
- });
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
+ });
7455
8087
 
7456
- return null;
7457
- }
8088
+ return res.once(ctx.json(createFetchResult(null)));
8089
+ }
8090
+ )
7458
8091
  );
7459
8092
  }
7460
8093
 
7461
8094
  /** Create a mock handler for the request to get a list of all KV namespaces. */
7462
8095
  function mockListKVNamespacesRequest(...namespaces: KVNamespaceInfo[]) {
7463
- setMockResponse(
7464
- "/accounts/:accountId/storage/kv/namespaces",
7465
- "GET",
7466
- ([_url, accountId]) => {
7467
- expect(accountId).toEqual("some-account-id");
7468
- return namespaces;
7469
- }
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
+ })
7470
8101
  );
7471
8102
  }
7472
8103
 
@@ -7485,6 +8116,7 @@ interface StaticAssetUpload {
7485
8116
  }
7486
8117
 
7487
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
7488
8120
  function mockUploadAssetsToKVRequest(
7489
8121
  expectedNamespaceId: string,
7490
8122
  assets?: ExpectedAsset[]
@@ -7492,22 +8124,24 @@ function mockUploadAssetsToKVRequest(
7492
8124
  const requests: {
7493
8125
  uploads: StaticAssetUpload[];
7494
8126
  }[] = [];
7495
- setMockResponse(
7496
- "/accounts/:accountId/storage/kv/namespaces/:namespaceId/bulk",
7497
- "PUT",
7498
- ([_url, accountId, namespaceId], { body }) => {
7499
- expect(accountId).toEqual("some-account-id");
7500
- expect(namespaceId).toEqual(expectedNamespaceId);
7501
- const uploads = JSON.parse(body as string);
7502
- if (assets) {
7503
- expect(assets.length).toEqual(uploads.length);
7504
- for (let i = 0; i < uploads.length; i++) {
7505
- 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
+ }
7506
8139
  }
7507
- } else {
8140
+
7508
8141
  requests.push({ uploads });
8142
+ return res(ctx.json(createFetchResult([])));
7509
8143
  }
7510
- }
8144
+ )
7511
8145
  );
7512
8146
  return requests;
7513
8147
  }
@@ -7531,16 +8165,24 @@ function mockDeleteUnusedAssetsRequest(
7531
8165
  expectedNamespaceId: string,
7532
8166
  assets: string[]
7533
8167
  ) {
7534
- setMockResponse(
7535
- "/accounts/:accountId/storage/kv/namespaces/:namespaceId/bulk",
7536
- "DELETE",
7537
- ([_url, accountId, namespaceId], { body }) => {
7538
- expect(accountId).toEqual("some-account-id");
7539
- expect(namespaceId).toEqual(expectedNamespaceId);
7540
- const deletes = JSON.parse(body as string);
7541
- expect(assets).toEqual(deletes);
7542
- return null;
7543
- }
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
+ )
7544
8186
  );
7545
8187
  }
7546
8188
 
@@ -7548,13 +8190,18 @@ type LegacyScriptInfo = { id: string; migration_tag?: string };
7548
8190
 
7549
8191
  function mockLegacyScriptData(options: { scripts: LegacyScriptInfo[] }) {
7550
8192
  const { scripts } = options;
7551
- setMockResponse(
7552
- "/accounts/:accountId/workers/scripts",
7553
- "GET",
7554
- ([_url, accountId]) => {
7555
- expect(accountId).toEqual("some-account-id");
7556
- return scripts;
7557
- }
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
+ })
7558
8205
  );
7559
8206
  }
7560
8207
 
@@ -7568,74 +8215,140 @@ function mockServiceScriptData(options: {
7568
8215
  const { script } = options;
7569
8216
  if (options.env) {
7570
8217
  if (!script) {
7571
- setMockRawResponse(
7572
- "/accounts/:accountId/workers/services/:scriptName/environments/:envName",
7573
- "GET",
7574
- () => {
7575
- return createFetchResult(null, false, [
7576
- { code: 10092, message: "workers.api.error.environment_not_found" },
7577
- ]);
7578
- }
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
+ )
7579
8237
  );
7580
8238
  return;
7581
8239
  }
7582
- setMockResponse(
7583
- "/accounts/:accountId/workers/services/:scriptName/environments/:envName",
7584
- "GET",
7585
- ([_url, accountId, scriptName, envName]) => {
7586
- expect(accountId).toEqual("some-account-id");
7587
- expect(scriptName).toEqual(options.scriptName || "test-name");
7588
- expect(envName).toEqual(options.env);
7589
- return { script };
7590
- }
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
+ )
7591
8259
  );
7592
8260
  } else {
7593
8261
  if (!script) {
7594
- setMockRawResponse(
7595
- "/accounts/:accountId/workers/services/:scriptName",
7596
- "GET",
7597
- () => {
7598
- return createFetchResult(null, false, [
7599
- { code: 10090, message: "workers.api.error.service_not_found" },
7600
- ]);
7601
- }
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
+ )
7602
8281
  );
7603
8282
  return;
7604
8283
  }
7605
- setMockResponse(
7606
- "/accounts/:accountId/workers/services/:scriptName",
7607
- "GET",
7608
- ([_url, accountId, scriptName]) => {
7609
- expect(accountId).toEqual("some-account-id");
7610
- expect(scriptName).toEqual(options.scriptName || "test-name");
7611
- return { default_environment: { script } };
7612
- }
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
+ )
7613
8302
  );
7614
8303
  }
7615
8304
  }
7616
8305
 
7617
8306
  function mockGetQueue(expectedQueueName: string) {
7618
8307
  const requests = { count: 0 };
7619
- setMockResponse(
7620
- `/accounts/:accountId/workers/queues/${expectedQueueName}`,
7621
- "GET",
7622
- ([_url, accountId]) => {
7623
- expect(accountId).toEqual("some-account-id");
7624
- requests.count += 1;
7625
- return { queue: expectedQueueName };
7626
- }
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
+ )
7627
8324
  );
7628
8325
  return requests;
7629
8326
  }
7630
8327
 
7631
8328
  function mockGetQueueMissing(expectedQueueName: string) {
7632
8329
  const requests = { count: 0 };
7633
- setMockResponse(
7634
- `/accounts/:accountId/workers/queues/${expectedQueueName}`,
7635
- "GET",
7636
- ([_url, _accountId]) => {
7637
- throw { code: 100123 };
7638
- }
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
+ )
7639
8352
  );
7640
8353
  return requests;
7641
8354
  }
@@ -7646,15 +8359,65 @@ function mockPutQueueConsumer(
7646
8359
  expectedBody: PutConsumerBody
7647
8360
  ) {
7648
8361
  const requests = { count: 0 };
7649
- setMockResponse(
7650
- `/accounts/:accountId/workers/queues/${expectedQueueName}/consumers/${expectedConsumerName}`,
7651
- "PUT",
7652
- ([_url, accountId], { body }) => {
7653
- expect(accountId).toEqual("some-account-id");
7654
- expect(JSON.parse(body as string)).toEqual(expectedBody);
7655
- requests.count += 1;
7656
- return { queue: expectedQueueName };
7657
- }
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
+ )
7658
8380
  );
7659
8381
  return requests;
7660
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;