wrangler 2.7.1 → 2.8.1

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 (63) hide show
  1. package/package.json +1 -1
  2. package/src/__tests__/d1/d1.test.ts +12 -8
  3. package/src/__tests__/deployments.test.ts +4 -4
  4. package/src/__tests__/helpers/mock-dialogs.ts +2 -0
  5. package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -5
  6. package/src/__tests__/helpers/mock-known-routes.ts +7 -2
  7. package/src/__tests__/helpers/mock-kv.ts +29 -16
  8. package/src/__tests__/helpers/mock-oauth-flow.ts +90 -98
  9. package/src/__tests__/helpers/msw/handlers/deployments.ts +20 -10
  10. package/src/__tests__/helpers/msw/handlers/namespaces.ts +18 -41
  11. package/src/__tests__/helpers/msw/handlers/r2.ts +14 -34
  12. package/src/__tests__/helpers/msw/handlers/script.ts +9 -28
  13. package/src/__tests__/helpers/msw/handlers/user.ts +13 -24
  14. package/src/__tests__/helpers/msw/handlers/zones.ts +6 -8
  15. package/src/__tests__/helpers/msw/index.ts +30 -1
  16. package/src/__tests__/init.test.ts +3 -14
  17. package/src/__tests__/jest.setup.ts +0 -23
  18. package/src/__tests__/pages-deployment-tail.test.ts +72 -1
  19. package/src/__tests__/pages.test.ts +52 -53
  20. package/src/__tests__/publish.test.ts +870 -522
  21. package/src/__tests__/r2.test.ts +11 -35
  22. package/src/__tests__/secret.test.ts +1 -9
  23. package/src/__tests__/tail.test.ts +72 -19
  24. package/src/__tests__/tsconfig.tsbuildinfo +1 -1
  25. package/src/__tests__/user.test.ts +5 -16
  26. package/src/__tests__/whoami.test.tsx +6 -17
  27. package/src/__tests__/worker-namespace.test.ts +56 -48
  28. package/src/api/index.ts +1 -0
  29. package/src/api/pages/index.ts +5 -0
  30. package/src/api/pages/publish.tsx +321 -0
  31. package/src/bundle.ts +62 -10
  32. package/src/cfetch/internal.ts +0 -3
  33. package/src/cli.ts +2 -2
  34. package/src/config/environment.ts +12 -10
  35. package/src/d1/backups.tsx +1 -5
  36. package/src/d1/utils.ts +1 -1
  37. package/src/deployments.ts +16 -6
  38. package/src/dev/local.tsx +1 -10
  39. package/src/dev/remote.tsx +2 -0
  40. package/src/dev/start-server.ts +5 -10
  41. package/src/dev/use-esbuild.ts +1 -0
  42. package/src/docs/index.ts +2 -1
  43. package/src/entry.ts +1 -2
  44. package/src/index.ts +1 -1
  45. package/src/init.ts +1 -1
  46. package/src/metrics/send-event.ts +2 -1
  47. package/src/pages/build.ts +4 -124
  48. package/src/pages/buildFunctions.ts +129 -0
  49. package/src/pages/dev.ts +68 -63
  50. package/src/pages/functions/buildPlugin.ts +3 -20
  51. package/src/pages/functions/buildWorker.ts +143 -21
  52. package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
  53. package/src/pages/publish.tsx +21 -220
  54. package/src/publish/publish.ts +30 -4
  55. package/src/tail/createTail.ts +28 -1
  56. package/src/tail/printing.ts +15 -0
  57. package/templates/checked-fetch.js +1 -3
  58. package/templates/d1-beta-facade.js +1 -1
  59. package/templates/middleware/loader-modules.ts +2 -0
  60. package/templates/tsconfig.tsbuildinfo +1 -1
  61. package/wrangler-dist/cli.d.ts +132 -10
  62. package/wrangler-dist/cli.js +3532 -3330
  63. package/src/__tests__/helpers/mock-cfetch.ts +0 -278
@@ -1,9 +1,11 @@
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,
@@ -11,35 +13,40 @@ import {
11
13
  import { writeAuthConfigFile } from "../user";
12
14
  import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
13
15
  import { mockAuthDomain } from "./helpers/mock-auth-domain";
14
- import {
15
- createFetchResult,
16
- setMockRawResponse,
17
- setMockResponse,
18
- unsetAllMocks,
19
- unsetSpecialMockFns,
20
- } from "./helpers/mock-cfetch";
21
16
  import {
22
17
  mockConsoleMethods,
23
18
  normalizeSlashes,
24
19
  normalizeTempDirs,
25
20
  } from "./helpers/mock-console";
26
- import { mockConfirm } from "./helpers/mock-dialogs";
21
+ import { clearDialogs, mockConfirm } from "./helpers/mock-dialogs";
27
22
  import { mockGetZoneFromHostRequest } from "./helpers/mock-get-zone-from-host";
28
23
  import { useMockIsTTY } from "./helpers/mock-istty";
29
24
  import { mockCollectKnownRoutesRequest } from "./helpers/mock-known-routes";
30
25
  import { mockKeyListRequest } from "./helpers/mock-kv";
31
- 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
+ mswSuccessLastDeployment,
36
+ } from "./helpers/msw";
37
+ import { FileReaderSync } from "./helpers/msw/read-file-sync";
32
38
  import { runInTempDir } from "./helpers/run-in-tmp";
33
39
  import { runWrangler } from "./helpers/run-wrangler";
34
40
  import { writeWorkerSource } from "./helpers/write-worker-source";
35
41
  import writeWranglerToml from "./helpers/write-wrangler-toml";
42
+
36
43
  import type { Config } from "../config";
37
44
  import type { WorkerMetadata } from "../create-worker-upload-form";
38
45
  import type { KVNamespaceInfo } from "../kv/helpers";
39
- import type { CustomDomainChangeset, CustomDomain } from "../publish/publish";
46
+ import type { CustomDomain, CustomDomainChangeset } from "../publish/publish";
40
47
  import type { PutConsumerBody } from "../queues/client";
41
48
  import type { CfWorkerInit } from "../worker";
42
- import type { FormData, File } from "undici";
49
+ import type { ResponseComposition, RestContext, RestRequest } from "msw";
43
50
 
44
51
  describe("publish", () => {
45
52
  mockAccountId();
@@ -48,10 +55,9 @@ describe("publish", () => {
48
55
  const { setIsTTY } = useMockIsTTY();
49
56
  const std = mockConsoleMethods();
50
57
  const {
51
- mockDomainUsesAccess,
52
58
  mockOAuthServerCallback,
53
59
  mockGrantAccessToken,
54
- mockGrantAuthorization,
60
+ mockDomainUsesAccess,
55
61
  } = mockOAuthFlow();
56
62
 
57
63
  beforeEach(() => {
@@ -60,28 +66,15 @@ describe("publish", () => {
60
66
  setImmediate(fn);
61
67
  });
62
68
  setIsTTY(true);
63
- setMockResponse(
64
- "/accounts/:accountId/workers/services/:scriptName",
65
- () => ({
66
- default_environment: { script: { last_deployed_from: "wrangler" } },
67
- })
68
- );
69
- setMockResponse(
70
- "/accounts/:accountId/workers/deployments/by-script/:scriptTag",
71
- () => ({
72
- latest: { number: "2" },
73
- })
74
- );
69
+ mockLastDeploymentRequest();
70
+ mockDeploymentsListRequest();
75
71
  });
76
72
 
77
73
  afterEach(() => {
78
- unsetAllMocks();
79
- unsetSpecialMockFns();
74
+ clearDialogs();
80
75
  });
81
76
 
82
77
  describe("output additional script information", () => {
83
- mockApiToken();
84
-
85
78
  it("for first party workers, it should print worker information at log level", async () => {
86
79
  setIsTTY(false);
87
80
  fs.writeFileSync(
@@ -112,7 +105,7 @@ describe("publish", () => {
112
105
  Uploaded test-name (TIMINGS)
113
106
  Published test-name (TIMINGS)
114
107
  https://test-name.test-sub-domain.workers.dev
115
- Current Deployment ID: undefined",
108
+ Current Deployment ID: Galaxy-Class",
116
109
  "warn": "",
117
110
  }
118
111
  `);
@@ -121,6 +114,7 @@ describe("publish", () => {
121
114
 
122
115
  describe("authentication", () => {
123
116
  mockApiToken({ apiToken: null });
117
+
124
118
  beforeEach(() => {
125
119
  // @ts-expect-error disable the mock we'd setup earlier
126
120
  // or else our server won't bother listening for oauth requests
@@ -129,21 +123,18 @@ describe("publish", () => {
129
123
  });
130
124
 
131
125
  it("drops a user into the login flow if they're unauthenticated", async () => {
126
+ setIsTTY(true);
132
127
  writeWranglerToml();
133
128
  writeWorkerSource();
134
129
  mockDomainUsesAccess({ usesAccess: false });
135
130
  mockSubDomainRequest();
136
131
  mockUploadWorkerRequest();
137
- mockOAuthServerCallback();
138
- const accessTokenRequest = mockGrantAccessToken({ respondWith: "ok" });
139
- mockGrantAuthorization({ respondWith: "success" });
132
+ mockExchangeRefreshTokenForAccessToken({ respondWith: "refreshSuccess" });
133
+ mockOAuthServerCallback("success");
134
+ mockDeploymentsListRequest();
140
135
 
141
136
  await expect(runWrangler("publish index.js")).resolves.toBeUndefined();
142
137
 
143
- expect(accessTokenRequest.actual.url).toEqual(
144
- accessTokenRequest.expected.url
145
- );
146
-
147
138
  expect(std.out).toMatchInlineSnapshot(`
148
139
  "Attempting to login via OAuth...
149
140
  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
@@ -152,7 +143,7 @@ describe("publish", () => {
152
143
  Uploaded test-name (TIMINGS)
153
144
  Published test-name (TIMINGS)
154
145
  https://test-name.test-sub-domain.workers.dev
155
- Current Deployment ID: undefined"
146
+ Current Deployment ID: Galaxy-Class"
156
147
  `);
157
148
  expect(std.warn).toMatchInlineSnapshot(`""`);
158
149
  expect(std.err).toMatchInlineSnapshot(`""`);
@@ -170,18 +161,19 @@ describe("publish", () => {
170
161
  });
171
162
  mockSubDomainRequest();
172
163
  mockUploadWorkerRequest();
173
- mockOAuthServerCallback();
164
+ mockExchangeRefreshTokenForAccessToken({
165
+ respondWith: "refreshSuccess",
166
+ });
174
167
  const accessTokenRequest = mockGrantAccessToken({
175
- domain: "dash.staging.cloudflare.com",
176
168
  respondWith: "ok",
169
+ domain: "dash.staging.cloudflare.com",
177
170
  });
178
- mockGrantAuthorization({ respondWith: "success" });
171
+ mockOAuthServerCallback("success");
172
+ mockDeploymentsListRequest();
179
173
 
180
174
  await expect(runWrangler("publish index.js")).resolves.toBeUndefined();
181
175
 
182
- expect(accessTokenRequest.actual.url).toEqual(
183
- accessTokenRequest.expected.url
184
- );
176
+ expect(accessTokenRequest.actual).toEqual(accessTokenRequest.expected);
185
177
 
186
178
  expect(std.out).toMatchInlineSnapshot(`
187
179
  "Attempting to login via OAuth...
@@ -191,7 +183,7 @@ describe("publish", () => {
191
183
  Uploaded test-name (TIMINGS)
192
184
  Published test-name (TIMINGS)
193
185
  https://test-name.test-sub-domain.workers.dev
194
- Current Deployment ID: undefined"
186
+ Current Deployment ID: Galaxy-Class"
195
187
  `);
196
188
  expect(std.warn).toMatchInlineSnapshot(`""`);
197
189
  expect(std.err).toMatchInlineSnapshot(`""`);
@@ -214,7 +206,7 @@ describe("publish", () => {
214
206
  Uploaded test-name (TIMINGS)
215
207
  Published test-name (TIMINGS)
216
208
  https://test-name.test-sub-domain.workers.dev
217
- Current Deployment ID: undefined"
209
+ Current Deployment ID: Galaxy-Class"
218
210
  `);
219
211
  expect(std.warn).toMatchInlineSnapshot(`
220
212
  "▲ [WARNING] It looks like you have used Wrangler 1's \`config\` command to login with an API token.
@@ -255,7 +247,7 @@ describe("publish", () => {
255
247
  Uploaded test-name (TIMINGS)
256
248
  Published test-name (TIMINGS)
257
249
  https://test-name.test-sub-domain.workers.dev
258
- Current Deployment ID: undefined"
250
+ Current Deployment ID: Galaxy-Class"
259
251
  `);
260
252
  expect(std.err).toMatchInlineSnapshot(`""`);
261
253
  });
@@ -280,7 +272,7 @@ describe("publish", () => {
280
272
  Uploaded test-name (TIMINGS)
281
273
  Published test-name (TIMINGS)
282
274
  https://test-name.test-sub-domain.workers.dev
283
- Current Deployment ID: undefined"
275
+ Current Deployment ID: Galaxy-Class"
284
276
  `);
285
277
  expect(std.err).toMatchInlineSnapshot(`""`);
286
278
  });
@@ -384,7 +376,7 @@ describe("publish", () => {
384
376
  Uploaded test-name-some-env (TIMINGS)
385
377
  Published test-name-some-env (TIMINGS)
386
378
  https://test-name-some-env.test-sub-domain.workers.dev
387
- Current Deployment ID: undefined"
379
+ Current Deployment ID: Galaxy-Class"
388
380
  `);
389
381
  expect(std.err).toMatchInlineSnapshot(`""`);
390
382
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -405,7 +397,7 @@ describe("publish", () => {
405
397
  Uploaded test-name (TIMINGS)
406
398
  Published test-name (TIMINGS)
407
399
  https://test-name.test-sub-domain.workers.dev
408
- Current Deployment ID: undefined"
400
+ Current Deployment ID: Galaxy-Class"
409
401
  `);
410
402
  expect(std.err).toMatchInlineSnapshot(`""`);
411
403
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -426,7 +418,7 @@ describe("publish", () => {
426
418
  Uploaded test-name-some-env (TIMINGS)
427
419
  Published test-name-some-env (TIMINGS)
428
420
  https://test-name-some-env.test-sub-domain.workers.dev
429
- Current Deployment ID: undefined"
421
+ Current Deployment ID: Galaxy-Class"
430
422
  `);
431
423
  expect(std.err).toMatchInlineSnapshot(`""`);
432
424
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -447,7 +439,7 @@ describe("publish", () => {
447
439
  Uploaded test-name-some-env (TIMINGS)
448
440
  Published test-name-some-env (TIMINGS)
449
441
  https://test-name-some-env.test-sub-domain.workers.dev
450
- Current Deployment ID: undefined"
442
+ Current Deployment ID: Galaxy-Class"
451
443
  `);
452
444
  expect(std.err).toMatchInlineSnapshot(`""`);
453
445
  expect(std.warn).toMatchInlineSnapshot(`
@@ -519,7 +511,7 @@ describe("publish", () => {
519
511
  Uploaded test-name (TIMINGS)
520
512
  Published test-name (TIMINGS)
521
513
  https://test-name.test-sub-domain.workers.dev
522
- Current Deployment ID: undefined"
514
+ Current Deployment ID: Galaxy-Class"
523
515
  `);
524
516
  expect(std.err).toMatchInlineSnapshot(`""`);
525
517
  expect(std.warn).toMatchInlineSnapshot(`
@@ -547,7 +539,7 @@ describe("publish", () => {
547
539
  Uploaded test-name (some-env) (TIMINGS)
548
540
  Published test-name (some-env) (TIMINGS)
549
541
  https://some-env.test-name.test-sub-domain.workers.dev
550
- Current Deployment ID: undefined"
542
+ Current Deployment ID: Galaxy-Class"
551
543
  `);
552
544
  expect(std.err).toMatchInlineSnapshot(`""`);
553
545
  expect(std.warn).toMatchInlineSnapshot(`
@@ -594,7 +586,7 @@ describe("publish", () => {
594
586
  Uploaded test-name (TIMINGS)
595
587
  Published test-name (TIMINGS)
596
588
  https://test-name.test-sub-domain.workers.dev
597
- Current Deployment ID: undefined"
589
+ Current Deployment ID: Galaxy-Class"
598
590
  `);
599
591
  expect(std.err).toMatchInlineSnapshot(`""`);
600
592
  });
@@ -629,7 +621,7 @@ describe("publish", () => {
629
621
  Uploaded test-name (TIMINGS)
630
622
  Published test-name (TIMINGS)
631
623
  https://test-name.test-sub-domain.workers.dev
632
- Current Deployment ID: undefined",
624
+ Current Deployment ID: Galaxy-Class",
633
625
  "warn": "▲ [WARNING] Processing wrangler.toml configuration:
634
626
 
635
627
  - The \\"route\\" field in your configuration is an empty string and will be ignored.
@@ -680,7 +672,7 @@ describe("publish", () => {
680
672
  *another-boring-website.com (zone name: some-zone.com)
681
673
  example.com/some-route/* (zone id: JGHFHG654gjcj)
682
674
  more-examples.com/*
683
- Current Deployment ID: undefined",
675
+ Current Deployment ID: Galaxy-Class",
684
676
  "warn": "",
685
677
  }
686
678
  `);
@@ -742,7 +734,7 @@ describe("publish", () => {
742
734
  *another-boring-website.com (zone name: some-zone.com)
743
735
  example.com/some-route/* (zone id: JGHFHG654gjcj)
744
736
  more-examples.com/*
745
- Current Deployment ID: undefined",
737
+ Current Deployment ID: Galaxy-Class",
746
738
  "warn": "▲ [WARNING] Processing wrangler.toml configuration:
747
739
 
748
740
  - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in
@@ -845,7 +837,7 @@ describe("publish", () => {
845
837
  Uploaded test-name (TIMINGS)
846
838
  Published test-name (TIMINGS)
847
839
  example.com/some-route/*
848
- Current Deployment ID: undefined"
840
+ Current Deployment ID: Galaxy-Class"
849
841
  `);
850
842
  });
851
843
 
@@ -1126,7 +1118,7 @@ Update them to point to this script instead?`,
1126
1118
  Uploaded test-name (TIMINGS)
1127
1119
  Published test-name (TIMINGS)
1128
1120
  https://test-name.test-sub-domain.workers.dev
1129
- Current Deployment ID: undefined"
1121
+ Current Deployment ID: Galaxy-Class"
1130
1122
  `);
1131
1123
  expect(std.err).toMatchInlineSnapshot(`""`);
1132
1124
  });
@@ -1144,7 +1136,7 @@ Update them to point to this script instead?`,
1144
1136
  Uploaded test-name (TIMINGS)
1145
1137
  Published test-name (TIMINGS)
1146
1138
  https://test-name.test-sub-domain.workers.dev
1147
- Current Deployment ID: undefined"
1139
+ Current Deployment ID: Galaxy-Class"
1148
1140
  `);
1149
1141
  expect(std.err).toMatchInlineSnapshot(`""`);
1150
1142
  });
@@ -1162,7 +1154,7 @@ Update them to point to this script instead?`,
1162
1154
  Uploaded test-name (TIMINGS)
1163
1155
  Published test-name (TIMINGS)
1164
1156
  https://test-name.test-sub-domain.workers.dev
1165
- Current Deployment ID: undefined"
1157
+ Current Deployment ID: Galaxy-Class"
1166
1158
  `);
1167
1159
  expect(std.err).toMatchInlineSnapshot(`""`);
1168
1160
  });
@@ -1182,7 +1174,7 @@ Update them to point to this script instead?`,
1182
1174
  Uploaded test-name (TIMINGS)
1183
1175
  Published test-name (TIMINGS)
1184
1176
  https://test-name.test-sub-domain.workers.dev
1185
- Current Deployment ID: undefined"
1177
+ Current Deployment ID: Galaxy-Class"
1186
1178
  `);
1187
1179
  expect(std.err).toMatchInlineSnapshot(`""`);
1188
1180
  });
@@ -1200,7 +1192,7 @@ Update them to point to this script instead?`,
1200
1192
  Uploaded test-name (TIMINGS)
1201
1193
  Published test-name (TIMINGS)
1202
1194
  https://test-name.test-sub-domain.workers.dev
1203
- Current Deployment ID: undefined"
1195
+ Current Deployment ID: Galaxy-Class"
1204
1196
  `);
1205
1197
  expect(std.err).toMatchInlineSnapshot(`""`);
1206
1198
  expect(std.warn).toMatchInlineSnapshot(`
@@ -1237,7 +1229,7 @@ Update them to point to this script instead?`,
1237
1229
  Uploaded test-name (TIMINGS)
1238
1230
  Published test-name (TIMINGS)
1239
1231
  https://test-name.test-sub-domain.workers.dev
1240
- Current Deployment ID: undefined"
1232
+ Current Deployment ID: Galaxy-Class"
1241
1233
  `);
1242
1234
  expect(std.err).toMatchInlineSnapshot(`""`);
1243
1235
  expect(std.warn).toMatchInlineSnapshot(`
@@ -1288,7 +1280,7 @@ Update them to point to this script instead?`,
1288
1280
  Uploaded test-name (TIMINGS)
1289
1281
  Published test-name (TIMINGS)
1290
1282
  https://test-name.test-sub-domain.workers.dev
1291
- Current Deployment ID: undefined"
1283
+ Current Deployment ID: Galaxy-Class"
1292
1284
  `);
1293
1285
  expect(std.err).toMatchInlineSnapshot(`""`);
1294
1286
  });
@@ -1308,7 +1300,7 @@ Update them to point to this script instead?`,
1308
1300
  Uploaded test-name (TIMINGS)
1309
1301
  Published test-name (TIMINGS)
1310
1302
  https://test-name.test-sub-domain.workers.dev
1311
- Current Deployment ID: undefined"
1303
+ Current Deployment ID: Galaxy-Class"
1312
1304
  `);
1313
1305
  expect(std.err).toMatchInlineSnapshot(`""`);
1314
1306
  });
@@ -1340,7 +1332,7 @@ export default{
1340
1332
  Uploaded test-name (TIMINGS)
1341
1333
  Published test-name (TIMINGS)
1342
1334
  https://test-name.test-sub-domain.workers.dev
1343
- Current Deployment ID: undefined"
1335
+ Current Deployment ID: Galaxy-Class"
1344
1336
  `);
1345
1337
  expect(std.err).toMatchInlineSnapshot(`""`);
1346
1338
  });
@@ -1358,7 +1350,7 @@ export default{
1358
1350
  Uploaded test-name (TIMINGS)
1359
1351
  Published test-name (TIMINGS)
1360
1352
  https://test-name.test-sub-domain.workers.dev
1361
- Current Deployment ID: undefined"
1353
+ Current Deployment ID: Galaxy-Class"
1362
1354
  `);
1363
1355
  expect(std.err).toMatchInlineSnapshot(`""`);
1364
1356
  });
@@ -1453,7 +1445,7 @@ addEventListener('fetch', event => {});`
1453
1445
  Uploaded test-name (TIMINGS)
1454
1446
  Published test-name (TIMINGS)
1455
1447
  https://test-name.test-sub-domain.workers.dev
1456
- Current Deployment ID: undefined"
1448
+ Current Deployment ID: Galaxy-Class"
1457
1449
  `);
1458
1450
  expect(std.err).toMatchInlineSnapshot(`""`);
1459
1451
  });
@@ -1536,7 +1528,7 @@ addEventListener('fetch', event => {});`
1536
1528
  Uploaded test-name (TIMINGS)
1537
1529
  Published test-name (TIMINGS)
1538
1530
  https://test-name.test-sub-domain.workers.dev
1539
- Current Deployment ID: undefined",
1531
+ Current Deployment ID: Galaxy-Class",
1540
1532
  "warn": "▲ [WARNING] Processing wrangler.toml configuration:
1541
1533
 
1542
1534
  - Deprecation: \\"site.entry-point\\":
@@ -1589,7 +1581,7 @@ addEventListener('fetch', event => {});`
1589
1581
  Uploaded test-name (TIMINGS)
1590
1582
  Published test-name (TIMINGS)
1591
1583
  https://test-name.test-sub-domain.workers.dev
1592
- Current Deployment ID: undefined"
1584
+ Current Deployment ID: Galaxy-Class"
1593
1585
  `);
1594
1586
  expect(std.err).toMatchInlineSnapshot(`""`);
1595
1587
  expect(normalizeSlashes(std.warn)).toMatchInlineSnapshot(`
@@ -1679,7 +1671,7 @@ addEventListener('fetch', event => {});`
1679
1671
  Uploaded test-name (TIMINGS)
1680
1672
  Published test-name (TIMINGS)
1681
1673
  https://test-name.test-sub-domain.workers.dev
1682
- Current Deployment ID: undefined",
1674
+ Current Deployment ID: Galaxy-Class",
1683
1675
  "warn": "▲ [WARNING] The --assets argument is experimental and may change or break at any time
1684
1676
 
1685
1677
 
@@ -1728,7 +1720,7 @@ addEventListener('fetch', event => {});`
1728
1720
  Uploaded test-name (TIMINGS)
1729
1721
  Published test-name (TIMINGS)
1730
1722
  https://test-name.test-sub-domain.workers.dev
1731
- Current Deployment ID: undefined"
1723
+ Current Deployment ID: Galaxy-Class"
1732
1724
  `);
1733
1725
  expect(std.err).toMatchInlineSnapshot(`""`);
1734
1726
  });
@@ -1769,7 +1761,7 @@ addEventListener('fetch', event => {});`
1769
1761
  Uploaded test-name (TIMINGS)
1770
1762
  Published test-name (TIMINGS)
1771
1763
  https://test-name.test-sub-domain.workers.dev
1772
- Current Deployment ID: undefined",
1764
+ Current Deployment ID: Galaxy-Class",
1773
1765
  "warn": "▲ [WARNING] The --assets argument is experimental and may change or break at any time
1774
1766
 
1775
1767
  ",
@@ -1954,7 +1946,7 @@ addEventListener('fetch', event => {});`
1954
1946
  Uploaded test-name (TIMINGS)
1955
1947
  Published test-name (TIMINGS)
1956
1948
  https://test-name.test-sub-domain.workers.dev
1957
- Current Deployment ID: undefined",
1949
+ Current Deployment ID: Galaxy-Class",
1958
1950
  "warn": "▲ [WARNING] The --assets argument is experimental and may change or break at any time
1959
1951
 
1960
1952
  ",
@@ -2001,7 +1993,7 @@ addEventListener('fetch', event => {});`
2001
1993
  Uploaded test-name (TIMINGS)
2002
1994
  Published test-name (TIMINGS)
2003
1995
  https://test-name.test-sub-domain.workers.dev
2004
- Current Deployment ID: undefined",
1996
+ Current Deployment ID: Galaxy-Class",
2005
1997
  "warn": "▲ [WARNING] Processing wrangler.toml configuration:
2006
1998
 
2007
1999
  - \\"assets\\" fields are experimental and may change or break at any time.
@@ -2058,7 +2050,7 @@ addEventListener('fetch', event => {});`
2058
2050
  Uploaded test-name (TIMINGS)
2059
2051
  Published test-name (TIMINGS)
2060
2052
  https://test-name.test-sub-domain.workers.dev
2061
- Current Deployment ID: undefined"
2053
+ Current Deployment ID: Galaxy-Class"
2062
2054
  `);
2063
2055
  expect(std.err).toMatchInlineSnapshot(`""`);
2064
2056
  });
@@ -2116,7 +2108,7 @@ addEventListener('fetch', event => {});`
2116
2108
  Uploaded test-name (TIMINGS)
2117
2109
  Published test-name (TIMINGS)
2118
2110
  https://test-name.test-sub-domain.workers.dev
2119
- Current Deployment ID: undefined"
2111
+ Current Deployment ID: Galaxy-Class"
2120
2112
  `);
2121
2113
  expect(std.err).toMatchInlineSnapshot(`""`);
2122
2114
  });
@@ -2168,7 +2160,7 @@ addEventListener('fetch', event => {});`
2168
2160
  Uploaded test-name (TIMINGS)
2169
2161
  Published test-name (TIMINGS)
2170
2162
  https://test-name.test-sub-domain.workers.dev
2171
- Current Deployment ID: undefined"
2163
+ Current Deployment ID: Galaxy-Class"
2172
2164
  `);
2173
2165
  expect(std.err).toMatchInlineSnapshot(`""`);
2174
2166
  });
@@ -2218,7 +2210,7 @@ addEventListener('fetch', event => {});`
2218
2210
  Uploaded test-name (some-env) (TIMINGS)
2219
2211
  Published test-name (some-env) (TIMINGS)
2220
2212
  https://some-env.test-name.test-sub-domain.workers.dev
2221
- Current Deployment ID: undefined"
2213
+ Current Deployment ID: Galaxy-Class"
2222
2214
  `);
2223
2215
  expect(std.err).toMatchInlineSnapshot(`""`);
2224
2216
  });
@@ -2269,7 +2261,7 @@ addEventListener('fetch', event => {});`
2269
2261
  Uploaded test-name-some-env (TIMINGS)
2270
2262
  Published test-name-some-env (TIMINGS)
2271
2263
  https://test-name-some-env.test-sub-domain.workers.dev
2272
- Current Deployment ID: undefined"
2264
+ Current Deployment ID: Galaxy-Class"
2273
2265
  `);
2274
2266
  expect(std.err).toMatchInlineSnapshot(`""`);
2275
2267
  });
@@ -2313,7 +2305,7 @@ addEventListener('fetch', event => {});`
2313
2305
  Uploaded test-name (TIMINGS)
2314
2306
  Published test-name (TIMINGS)
2315
2307
  https://test-name.test-sub-domain.workers.dev
2316
- Current Deployment ID: undefined"
2308
+ Current Deployment ID: Galaxy-Class"
2317
2309
  `);
2318
2310
  expect(std.err).toMatchInlineSnapshot(`""`);
2319
2311
  });
@@ -2354,7 +2346,7 @@ addEventListener('fetch', event => {});`
2354
2346
  Uploaded test-name (TIMINGS)
2355
2347
  Published test-name (TIMINGS)
2356
2348
  https://test-name.test-sub-domain.workers.dev
2357
- Current Deployment ID: undefined"
2349
+ Current Deployment ID: Galaxy-Class"
2358
2350
  `);
2359
2351
  expect(std.err).toMatchInlineSnapshot(`""`);
2360
2352
  });
@@ -2395,7 +2387,7 @@ addEventListener('fetch', event => {});`
2395
2387
  Uploaded test-name (TIMINGS)
2396
2388
  Published test-name (TIMINGS)
2397
2389
  https://test-name.test-sub-domain.workers.dev
2398
- Current Deployment ID: undefined"
2390
+ Current Deployment ID: Galaxy-Class"
2399
2391
  `);
2400
2392
  expect(std.err).toMatchInlineSnapshot(`""`);
2401
2393
  });
@@ -2437,7 +2429,7 @@ addEventListener('fetch', event => {});`
2437
2429
  Uploaded test-name (TIMINGS)
2438
2430
  Published test-name (TIMINGS)
2439
2431
  https://test-name.test-sub-domain.workers.dev
2440
- Current Deployment ID: undefined"
2432
+ Current Deployment ID: Galaxy-Class"
2441
2433
  `);
2442
2434
  expect(std.err).toMatchInlineSnapshot(`""`);
2443
2435
  });
@@ -2479,7 +2471,7 @@ addEventListener('fetch', event => {});`
2479
2471
  Uploaded test-name (TIMINGS)
2480
2472
  Published test-name (TIMINGS)
2481
2473
  https://test-name.test-sub-domain.workers.dev
2482
- Current Deployment ID: undefined"
2474
+ Current Deployment ID: Galaxy-Class"
2483
2475
  `);
2484
2476
  expect(std.err).toMatchInlineSnapshot(`""`);
2485
2477
  });
@@ -2521,7 +2513,7 @@ addEventListener('fetch', event => {});`
2521
2513
  Uploaded test-name (TIMINGS)
2522
2514
  Published test-name (TIMINGS)
2523
2515
  https://test-name.test-sub-domain.workers.dev
2524
- Current Deployment ID: undefined"
2516
+ Current Deployment ID: Galaxy-Class"
2525
2517
  `);
2526
2518
  expect(std.err).toMatchInlineSnapshot(`""`);
2527
2519
  });
@@ -2563,7 +2555,7 @@ addEventListener('fetch', event => {});`
2563
2555
  Uploaded test-name (TIMINGS)
2564
2556
  Published test-name (TIMINGS)
2565
2557
  https://test-name.test-sub-domain.workers.dev
2566
- Current Deployment ID: undefined"
2558
+ Current Deployment ID: Galaxy-Class"
2567
2559
  `);
2568
2560
  expect(std.err).toMatchInlineSnapshot(`""`);
2569
2561
  });
@@ -2607,7 +2599,7 @@ addEventListener('fetch', event => {});`
2607
2599
  Uploaded test-name (TIMINGS)
2608
2600
  Published test-name (TIMINGS)
2609
2601
  https://test-name.test-sub-domain.workers.dev
2610
- Current Deployment ID: undefined"
2602
+ Current Deployment ID: Galaxy-Class"
2611
2603
  `);
2612
2604
  expect(std.err).toMatchInlineSnapshot(`""`);
2613
2605
  });
@@ -2655,7 +2647,7 @@ addEventListener('fetch', event => {});`
2655
2647
  Uploaded test-name (TIMINGS)
2656
2648
  Published test-name (TIMINGS)
2657
2649
  https://test-name.test-sub-domain.workers.dev
2658
- Current Deployment ID: undefined"
2650
+ Current Deployment ID: Galaxy-Class"
2659
2651
  `);
2660
2652
  expect(std.err).toMatchInlineSnapshot(`""`);
2661
2653
  });
@@ -2805,7 +2797,7 @@ addEventListener('fetch', event => {});`
2805
2797
  Uploaded test-name (TIMINGS)
2806
2798
  Published test-name (TIMINGS)
2807
2799
  https://test-name.test-sub-domain.workers.dev
2808
- Current Deployment ID: undefined",
2800
+ Current Deployment ID: Galaxy-Class",
2809
2801
  "warn": "",
2810
2802
  }
2811
2803
  `);
@@ -2905,7 +2897,7 @@ addEventListener('fetch', event => {});`
2905
2897
  Uploaded test-name (TIMINGS)
2906
2898
  Published test-name (TIMINGS)
2907
2899
  https://test-name.test-sub-domain.workers.dev
2908
- Current Deployment ID: undefined"
2900
+ Current Deployment ID: Galaxy-Class"
2909
2901
  `);
2910
2902
  expect(std.err).toMatchInlineSnapshot(`""`);
2911
2903
  });
@@ -2960,7 +2952,7 @@ addEventListener('fetch', event => {});`
2960
2952
  Uploaded test-name (TIMINGS)
2961
2953
  Published test-name (TIMINGS)
2962
2954
  https://test-name.test-sub-domain.workers.dev
2963
- Current Deployment ID: undefined"
2955
+ Current Deployment ID: Galaxy-Class"
2964
2956
  `);
2965
2957
  expect(std.err).toMatchInlineSnapshot(`""`);
2966
2958
  });
@@ -3002,7 +2994,7 @@ addEventListener('fetch', event => {});`
3002
2994
  Uploaded test-name (TIMINGS)
3003
2995
  Published test-name (TIMINGS)
3004
2996
  https://test-name.test-sub-domain.workers.dev
3005
- Current Deployment ID: undefined",
2997
+ Current Deployment ID: Galaxy-Class",
3006
2998
  "warn": "",
3007
2999
  }
3008
3000
  `);
@@ -3045,7 +3037,7 @@ addEventListener('fetch', event => {});`
3045
3037
  Uploaded test-name (TIMINGS)
3046
3038
  Published test-name (TIMINGS)
3047
3039
  https://test-name.test-sub-domain.workers.dev
3048
- Current Deployment ID: undefined",
3040
+ Current Deployment ID: Galaxy-Class",
3049
3041
  "warn": "▲ [WARNING] The --assets argument is experimental and may change or break at any time
3050
3042
 
3051
3043
  ",
@@ -3068,7 +3060,7 @@ addEventListener('fetch', event => {});`
3068
3060
  Uploaded test-name (TIMINGS)
3069
3061
  Published test-name (TIMINGS)
3070
3062
  https://test-name.test-sub-domain.workers.dev
3071
- Current Deployment ID: undefined"
3063
+ Current Deployment ID: Galaxy-Class"
3072
3064
  `);
3073
3065
  expect(std.err).toMatchInlineSnapshot(`""`);
3074
3066
  });
@@ -3089,7 +3081,7 @@ addEventListener('fetch', event => {});`
3089
3081
  Uploaded test-name (TIMINGS)
3090
3082
  Published test-name (TIMINGS)
3091
3083
  https://test-name.test-sub-domain.workers.dev
3092
- Current Deployment ID: undefined"
3084
+ Current Deployment ID: Galaxy-Class"
3093
3085
  `);
3094
3086
  expect(std.err).toMatchInlineSnapshot(`""`);
3095
3087
  });
@@ -3109,7 +3101,7 @@ addEventListener('fetch', event => {});`
3109
3101
  Uploaded test-name (TIMINGS)
3110
3102
  Published test-name (TIMINGS)
3111
3103
  https://test-name.test-sub-domain.workers.dev
3112
- Current Deployment ID: undefined"
3104
+ Current Deployment ID: Galaxy-Class"
3113
3105
  `);
3114
3106
  expect(std.err).toMatchInlineSnapshot(`""`);
3115
3107
  });
@@ -3128,7 +3120,7 @@ addEventListener('fetch', event => {});`
3128
3120
  "Total Upload: xx KiB / gzip: xx KiB
3129
3121
  Uploaded test-name (TIMINGS)
3130
3122
  No publish targets for test-name (TIMINGS)
3131
- Current Deployment ID: undefined"
3123
+ Current Deployment ID: Galaxy-Class"
3132
3124
  `);
3133
3125
  expect(std.err).toMatchInlineSnapshot(`""`);
3134
3126
  });
@@ -3149,7 +3141,7 @@ addEventListener('fetch', event => {});`
3149
3141
  "Total Upload: xx KiB / gzip: xx KiB
3150
3142
  Uploaded test-name (TIMINGS)
3151
3143
  No publish targets for test-name (TIMINGS)
3152
- Current Deployment ID: undefined"
3144
+ Current Deployment ID: Galaxy-Class"
3153
3145
  `);
3154
3146
  expect(std.err).toMatchInlineSnapshot(`""`);
3155
3147
  });
@@ -3174,7 +3166,7 @@ addEventListener('fetch', event => {});`
3174
3166
  "Total Upload: xx KiB / gzip: xx KiB
3175
3167
  Uploaded test-name (dev) (TIMINGS)
3176
3168
  No publish targets for test-name (dev) (TIMINGS)
3177
- Current Deployment ID: undefined"
3169
+ Current Deployment ID: Galaxy-Class"
3178
3170
  `);
3179
3171
  expect(std.err).toMatchInlineSnapshot(`""`);
3180
3172
  });
@@ -3200,7 +3192,7 @@ addEventListener('fetch', event => {});`
3200
3192
  "Total Upload: xx KiB / gzip: xx KiB
3201
3193
  Uploaded test-name (dev) (TIMINGS)
3202
3194
  No publish targets for test-name (dev) (TIMINGS)
3203
- Current Deployment ID: undefined"
3195
+ Current Deployment ID: Galaxy-Class"
3204
3196
  `);
3205
3197
  expect(std.err).toMatchInlineSnapshot(`""`);
3206
3198
  });
@@ -3227,7 +3219,7 @@ addEventListener('fetch', event => {});`
3227
3219
  Uploaded test-name (dev) (TIMINGS)
3228
3220
  Published test-name (dev) (TIMINGS)
3229
3221
  https://dev.test-name.test-sub-domain.workers.dev
3230
- Current Deployment ID: undefined"
3222
+ Current Deployment ID: Galaxy-Class"
3231
3223
  `);
3232
3224
  expect(std.err).toMatchInlineSnapshot(`""`);
3233
3225
  });
@@ -3255,7 +3247,7 @@ addEventListener('fetch', event => {});`
3255
3247
  Uploaded test-name (dev) (TIMINGS)
3256
3248
  Published test-name (dev) (TIMINGS)
3257
3249
  https://dev.test-name.test-sub-domain.workers.dev
3258
- Current Deployment ID: undefined"
3250
+ Current Deployment ID: Galaxy-Class"
3259
3251
  `);
3260
3252
  expect(std.err).toMatchInlineSnapshot(`""`);
3261
3253
  });
@@ -3284,7 +3276,7 @@ addEventListener('fetch', event => {});`
3284
3276
  Uploaded test-name (dev) (TIMINGS)
3285
3277
  Published test-name (dev) (TIMINGS)
3286
3278
  https://dev.test-name.test-sub-domain.workers.dev
3287
- Current Deployment ID: undefined"
3279
+ Current Deployment ID: Galaxy-Class"
3288
3280
  `);
3289
3281
  expect(std.err).toMatchInlineSnapshot(`""`);
3290
3282
  });
@@ -3316,7 +3308,7 @@ addEventListener('fetch', event => {});`
3316
3308
  Uploaded test-name (dev) (TIMINGS)
3317
3309
  Published test-name (dev) (TIMINGS)
3318
3310
  https://dev.test-name.test-sub-domain.workers.dev
3319
- Current Deployment ID: undefined"
3311
+ Current Deployment ID: Galaxy-Class"
3320
3312
  `);
3321
3313
  expect(std.err).toMatchInlineSnapshot(`""`);
3322
3314
  });
@@ -3350,7 +3342,7 @@ addEventListener('fetch', event => {});`
3350
3342
  Uploaded test-name (dev) (TIMINGS)
3351
3343
  Published test-name (dev) (TIMINGS)
3352
3344
  https://dev.test-name.test-sub-domain.workers.dev
3353
- Current Deployment ID: undefined"
3345
+ Current Deployment ID: Galaxy-Class"
3354
3346
  `);
3355
3347
  expect(std.err).toMatchInlineSnapshot(`""`);
3356
3348
  });
@@ -3411,7 +3403,7 @@ addEventListener('fetch', event => {});`
3411
3403
  Uploaded test-name (TIMINGS)
3412
3404
  Published test-name (TIMINGS)
3413
3405
  https://test-name.test-sub-domain.workers.dev
3414
- Current Deployment ID: undefined"
3406
+ Current Deployment ID: Galaxy-Class"
3415
3407
  `);
3416
3408
  expect(std.err).toMatchInlineSnapshot(`""`);
3417
3409
  });
@@ -3430,7 +3422,7 @@ addEventListener('fetch', event => {});`
3430
3422
  Uploaded test-name (TIMINGS)
3431
3423
  Published test-name (TIMINGS)
3432
3424
  https://test-name.test-sub-domain.workers.dev
3433
- Current Deployment ID: undefined"
3425
+ Current Deployment ID: Galaxy-Class"
3434
3426
  `);
3435
3427
  expect(std.err).toMatchInlineSnapshot(`""`);
3436
3428
  });
@@ -3444,7 +3436,7 @@ addEventListener('fetch', event => {});`
3444
3436
  mockSubDomainRequest("does-not-exist", false);
3445
3437
 
3446
3438
  mockConfirm({
3447
- text: `Would you like to register a workers.dev subdomain now?`,
3439
+ text: "Would you like to register a workers.dev subdomain now?",
3448
3440
  result: false,
3449
3441
  });
3450
3442
 
@@ -3473,7 +3465,7 @@ addEventListener('fetch', event => {});`
3473
3465
  Uploaded test-name (TIMINGS)
3474
3466
  Published test-name (TIMINGS)
3475
3467
  http://example.com/*
3476
- Current Deployment ID: undefined"
3468
+ Current Deployment ID: Galaxy-Class"
3477
3469
  `);
3478
3470
  expect(std.err).toMatchInlineSnapshot(`""`);
3479
3471
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -3508,7 +3500,7 @@ addEventListener('fetch', event => {});`
3508
3500
  Uploaded test-name-production (TIMINGS)
3509
3501
  Published test-name-production (TIMINGS)
3510
3502
  http://production.example.com/*
3511
- Current Deployment ID: undefined"
3503
+ Current Deployment ID: Galaxy-Class"
3512
3504
  `);
3513
3505
  expect(std.err).toMatchInlineSnapshot(`""`);
3514
3506
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -3542,7 +3534,7 @@ addEventListener('fetch', event => {});`
3542
3534
  Uploaded test-name-production (TIMINGS)
3543
3535
  Published test-name-production (TIMINGS)
3544
3536
  http://production.example.com/*
3545
- Current Deployment ID: undefined"
3537
+ Current Deployment ID: Galaxy-Class"
3546
3538
  `);
3547
3539
  expect(std.err).toMatchInlineSnapshot(`""`);
3548
3540
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -3570,7 +3562,7 @@ addEventListener('fetch', event => {});`
3570
3562
  Published test-name (TIMINGS)
3571
3563
  https://test-name.test-sub-domain.workers.dev
3572
3564
  http://example.com/*
3573
- Current Deployment ID: undefined"
3565
+ Current Deployment ID: Galaxy-Class"
3574
3566
  `);
3575
3567
  expect(std.err).toMatchInlineSnapshot(`""`);
3576
3568
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -3606,7 +3598,7 @@ addEventListener('fetch', event => {});`
3606
3598
  Published test-name-production (TIMINGS)
3607
3599
  https://test-name-production.test-sub-domain.workers.dev
3608
3600
  http://production.example.com/*
3609
- Current Deployment ID: undefined"
3601
+ Current Deployment ID: Galaxy-Class"
3610
3602
  `);
3611
3603
  expect(std.err).toMatchInlineSnapshot(`""`);
3612
3604
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -3642,7 +3634,7 @@ addEventListener('fetch', event => {});`
3642
3634
  Published test-name-production (TIMINGS)
3643
3635
  https://test-name-production.test-sub-domain.workers.dev
3644
3636
  http://production.example.com/*
3645
- Current Deployment ID: undefined"
3637
+ Current Deployment ID: Galaxy-Class"
3646
3638
  `);
3647
3639
  expect(std.err).toMatchInlineSnapshot(`""`);
3648
3640
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -3677,7 +3669,7 @@ addEventListener('fetch', event => {});`
3677
3669
  Uploaded test-name-production (TIMINGS)
3678
3670
  Published test-name-production (TIMINGS)
3679
3671
  http://production.example.com/*
3680
- Current Deployment ID: undefined"
3672
+ Current Deployment ID: Galaxy-Class"
3681
3673
  `);
3682
3674
  expect(std.err).toMatchInlineSnapshot(`""`);
3683
3675
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -3712,7 +3704,7 @@ addEventListener('fetch', event => {});`
3712
3704
  Uploaded test-name-production (TIMINGS)
3713
3705
  Published test-name-production (TIMINGS)
3714
3706
  http://production.example.com/*
3715
- Current Deployment ID: undefined"
3707
+ Current Deployment ID: Galaxy-Class"
3716
3708
  `);
3717
3709
  expect(std.err).toMatchInlineSnapshot(`""`);
3718
3710
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -3864,7 +3856,7 @@ addEventListener('fetch', event => {});`
3864
3856
  Uploaded test-name (TIMINGS)
3865
3857
  Published test-name (TIMINGS)
3866
3858
  https://test-name.test-sub-domain.workers.dev
3867
- Current Deployment ID: undefined"
3859
+ Current Deployment ID: Galaxy-Class"
3868
3860
  `);
3869
3861
  expect(std.err).toMatchInlineSnapshot(`""`);
3870
3862
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -3890,7 +3882,7 @@ addEventListener('fetch', event => {});`
3890
3882
  Uploaded test-name (TIMINGS)
3891
3883
  Published test-name (TIMINGS)
3892
3884
  https://test-name.test-sub-domain.workers.dev
3893
- Current Deployment ID: undefined"
3885
+ Current Deployment ID: Galaxy-Class"
3894
3886
  `);
3895
3887
  expect(std.err).toMatchInlineSnapshot(`""`);
3896
3888
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -3997,7 +3989,7 @@ addEventListener('fetch', event => {});`
3997
3989
  Uploaded test-name (TIMINGS)
3998
3990
  Published test-name (TIMINGS)
3999
3991
  https://test-name.test-sub-domain.workers.dev
4000
- Current Deployment ID: undefined"
3992
+ Current Deployment ID: Galaxy-Class"
4001
3993
  `);
4002
3994
  expect(std.err).toMatchInlineSnapshot(`""`);
4003
3995
  });
@@ -4037,7 +4029,7 @@ addEventListener('fetch', event => {});`
4037
4029
  Uploaded test-name (testEnv) (TIMINGS)
4038
4030
  Published test-name (testEnv) (TIMINGS)
4039
4031
  https://testEnv.test-name.test-sub-domain.workers.dev
4040
- Current Deployment ID: undefined"
4032
+ Current Deployment ID: Galaxy-Class"
4041
4033
  `);
4042
4034
  expect(std.err).toMatchInlineSnapshot(`""`);
4043
4035
  });
@@ -4065,7 +4057,7 @@ addEventListener('fetch', event => {});`
4065
4057
  Uploaded test-name (TIMINGS)
4066
4058
  Published test-name (TIMINGS)
4067
4059
  https://test-name.test-sub-domain.workers.dev
4068
- Current Deployment ID: undefined"
4060
+ Current Deployment ID: Galaxy-Class"
4069
4061
  `);
4070
4062
  expect(std.err).toMatchInlineSnapshot(`""`);
4071
4063
  expect(std.warn).toMatchInlineSnapshot(`
@@ -4116,7 +4108,7 @@ addEventListener('fetch', event => {});`
4116
4108
  Uploaded test-name (TIMINGS)
4117
4109
  Published test-name (TIMINGS)
4118
4110
  https://test-name.test-sub-domain.workers.dev
4119
- Current Deployment ID: undefined"
4111
+ Current Deployment ID: Galaxy-Class"
4120
4112
  `);
4121
4113
  expect(std.err).toMatchInlineSnapshot(`""`);
4122
4114
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -4161,7 +4153,7 @@ addEventListener('fetch', event => {});`
4161
4153
  Uploaded test-name (TIMINGS)
4162
4154
  Published test-name (TIMINGS)
4163
4155
  https://test-name.test-sub-domain.workers.dev
4164
- Current Deployment ID: undefined"
4156
+ Current Deployment ID: Galaxy-Class"
4165
4157
  `);
4166
4158
  expect(std.err).toMatchInlineSnapshot(`""`);
4167
4159
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -4213,7 +4205,7 @@ addEventListener('fetch', event => {});`
4213
4205
  Uploaded test-name (TIMINGS)
4214
4206
  Published test-name (TIMINGS)
4215
4207
  https://test-name.test-sub-domain.workers.dev
4216
- Current Deployment ID: undefined",
4208
+ Current Deployment ID: Galaxy-Class",
4217
4209
  "warn": "",
4218
4210
  }
4219
4211
  `);
@@ -4258,7 +4250,7 @@ addEventListener('fetch', event => {});`
4258
4250
  Uploaded test-name (TIMINGS)
4259
4251
  Published test-name (TIMINGS)
4260
4252
  https://test-name.test-sub-domain.workers.dev
4261
- Current Deployment ID: undefined",
4253
+ Current Deployment ID: Galaxy-Class",
4262
4254
  "warn": "",
4263
4255
  }
4264
4256
  `);
@@ -4305,7 +4297,7 @@ addEventListener('fetch', event => {});`
4305
4297
  Uploaded test-name (TIMINGS)
4306
4298
  Published test-name (TIMINGS)
4307
4299
  https://test-name.test-sub-domain.workers.dev
4308
- Current Deployment ID: undefined"
4300
+ Current Deployment ID: Galaxy-Class"
4309
4301
  `);
4310
4302
  expect(std.err).toMatchInlineSnapshot(`""`);
4311
4303
  expect(std.warn).toMatchInlineSnapshot(`
@@ -4369,7 +4361,7 @@ addEventListener('fetch', event => {});`
4369
4361
  Uploaded test-name (xyz) (TIMINGS)
4370
4362
  Published test-name (xyz) (TIMINGS)
4371
4363
  https://xyz.test-name.test-sub-domain.workers.dev
4372
- Current Deployment ID: undefined"
4364
+ Current Deployment ID: Galaxy-Class"
4373
4365
  `);
4374
4366
  expect(std.err).toMatchInlineSnapshot(`""`);
4375
4367
  expect(std.warn).toMatchInlineSnapshot(`
@@ -4383,7 +4375,6 @@ addEventListener('fetch', event => {});`
4383
4375
  });
4384
4376
 
4385
4377
  it("should use a script's current migration tag when publishing migrations", async () => {
4386
- unsetAllMocks();
4387
4378
  writeWranglerToml({
4388
4379
  durable_objects: {
4389
4380
  bindings: [
@@ -4402,26 +4393,22 @@ addEventListener('fetch', event => {});`
4402
4393
  );
4403
4394
  mockSubDomainRequest();
4404
4395
  mockServiceScriptData({
4405
- script: { id: "test-name", migration_tag: "v1" },
4396
+ script: { id: "test-name", migration_tag: "v2" },
4406
4397
  });
4407
4398
  mockUploadWorkerRequest({
4408
4399
  legacyEnv: false,
4409
4400
  expectedMigrations: {
4410
- old_tag: "v1",
4411
4401
  new_tag: "v2",
4412
4402
  steps: [
4403
+ {
4404
+ new_classes: ["SomeClass"],
4405
+ },
4413
4406
  {
4414
4407
  new_classes: ["SomeOtherClass"],
4415
4408
  },
4416
4409
  ],
4417
4410
  },
4418
4411
  });
4419
- setMockResponse(
4420
- "/accounts/:accountId/workers/deployments/by-script/:scriptTag",
4421
- () => ({
4422
- latest: { number: "2" },
4423
- })
4424
- );
4425
4412
 
4426
4413
  await runWrangler("publish index.js --legacy-env false");
4427
4414
  expect(std).toMatchInlineSnapshot(`
@@ -4436,7 +4423,7 @@ addEventListener('fetch', event => {});`
4436
4423
  Uploaded test-name (TIMINGS)
4437
4424
  Published test-name (TIMINGS)
4438
4425
  https://test-name.test-sub-domain.workers.dev
4439
- Current Deployment ID: undefined",
4426
+ Current Deployment ID: Galaxy-Class",
4440
4427
  "warn": "▲ [WARNING] Processing wrangler.toml configuration:
4441
4428
 
4442
4429
  - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in
@@ -4506,7 +4493,7 @@ addEventListener('fetch', event => {});`
4506
4493
  Uploaded test-name (xyz) (TIMINGS)
4507
4494
  Published test-name (xyz) (TIMINGS)
4508
4495
  https://xyz.test-name.test-sub-domain.workers.dev
4509
- Current Deployment ID: undefined",
4496
+ Current Deployment ID: Galaxy-Class",
4510
4497
  "warn": "▲ [WARNING] Processing wrangler.toml configuration:
4511
4498
 
4512
4499
  - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in
@@ -4742,7 +4729,7 @@ addEventListener('fetch', event => {});`
4742
4729
  Uploaded test-name (TIMINGS)
4743
4730
  Published test-name (TIMINGS)
4744
4731
  https://test-name.test-sub-domain.workers.dev
4745
- Current Deployment ID: undefined"
4732
+ Current Deployment ID: Galaxy-Class"
4746
4733
  `);
4747
4734
  expect(std.err).toMatchInlineSnapshot(`""`);
4748
4735
  expect(std.warn).toMatchInlineSnapshot(`
@@ -5163,7 +5150,7 @@ addEventListener('fetch', event => {});`
5163
5150
  Uploaded test-name (TIMINGS)
5164
5151
  Published test-name (TIMINGS)
5165
5152
  https://test-name.test-sub-domain.workers.dev
5166
- Current Deployment ID: undefined"
5153
+ Current Deployment ID: Galaxy-Class"
5167
5154
  `);
5168
5155
  expect(std.err).toMatchInlineSnapshot(`""`);
5169
5156
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -5234,7 +5221,7 @@ addEventListener('fetch', event => {});`
5234
5221
  Uploaded test-name (TIMINGS)
5235
5222
  Published test-name (TIMINGS)
5236
5223
  https://test-name.test-sub-domain.workers.dev
5237
- Current Deployment ID: undefined"
5224
+ Current Deployment ID: Galaxy-Class"
5238
5225
  `);
5239
5226
  expect(std.err).toMatchInlineSnapshot(`""`);
5240
5227
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -5268,7 +5255,7 @@ addEventListener('fetch', event => {});`
5268
5255
  Uploaded test-name (TIMINGS)
5269
5256
  Published test-name (TIMINGS)
5270
5257
  https://test-name.test-sub-domain.workers.dev
5271
- Current Deployment ID: undefined"
5258
+ Current Deployment ID: Galaxy-Class"
5272
5259
  `);
5273
5260
  expect(std.err).toMatchInlineSnapshot(`""`);
5274
5261
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -5306,7 +5293,7 @@ addEventListener('fetch', event => {});`
5306
5293
  Uploaded test-name (TIMINGS)
5307
5294
  Published test-name (TIMINGS)
5308
5295
  https://test-name.test-sub-domain.workers.dev
5309
- Current Deployment ID: undefined"
5296
+ Current Deployment ID: Galaxy-Class"
5310
5297
  `);
5311
5298
  expect(std.err).toMatchInlineSnapshot(`""`);
5312
5299
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -5381,7 +5368,7 @@ addEventListener('fetch', event => {});`
5381
5368
  Uploaded test-name (TIMINGS)
5382
5369
  Published test-name (TIMINGS)
5383
5370
  https://test-name.test-sub-domain.workers.dev
5384
- Current Deployment ID: undefined"
5371
+ Current Deployment ID: Galaxy-Class"
5385
5372
  `);
5386
5373
  expect(std.err).toMatchInlineSnapshot(`""`);
5387
5374
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -5419,7 +5406,7 @@ addEventListener('fetch', event => {});`
5419
5406
  Uploaded test-name (TIMINGS)
5420
5407
  Published test-name (TIMINGS)
5421
5408
  https://test-name.test-sub-domain.workers.dev
5422
- Current Deployment ID: undefined"
5409
+ Current Deployment ID: Galaxy-Class"
5423
5410
  `);
5424
5411
  expect(std.err).toMatchInlineSnapshot(`""`);
5425
5412
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -5494,7 +5481,7 @@ addEventListener('fetch', event => {});`
5494
5481
  Uploaded test-name (TIMINGS)
5495
5482
  Published test-name (TIMINGS)
5496
5483
  https://test-name.test-sub-domain.workers.dev
5497
- Current Deployment ID: undefined"
5484
+ Current Deployment ID: Galaxy-Class"
5498
5485
  `);
5499
5486
  expect(std.err).toMatchInlineSnapshot(`""`);
5500
5487
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -5538,7 +5525,7 @@ addEventListener('fetch', event => {});`
5538
5525
  Uploaded test-name (TIMINGS)
5539
5526
  Published test-name (TIMINGS)
5540
5527
  https://test-name.test-sub-domain.workers.dev
5541
- Current Deployment ID: undefined"
5528
+ Current Deployment ID: Galaxy-Class"
5542
5529
  `);
5543
5530
  expect(std.err).toMatchInlineSnapshot(`""`);
5544
5531
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -5562,7 +5549,7 @@ addEventListener('fetch', event => {});`
5562
5549
  Uploaded test-name (TIMINGS)
5563
5550
  Published test-name (TIMINGS)
5564
5551
  https://test-name.test-sub-domain.workers.dev
5565
- Current Deployment ID: undefined",
5552
+ Current Deployment ID: Galaxy-Class",
5566
5553
  "warn": "",
5567
5554
  }
5568
5555
  `);
@@ -5591,7 +5578,7 @@ addEventListener('fetch', event => {});`
5591
5578
  Uploaded test-name (TIMINGS)
5592
5579
  Published test-name (TIMINGS)
5593
5580
  https://test-name.test-sub-domain.workers.dev
5594
- Current Deployment ID: undefined"
5581
+ Current Deployment ID: Galaxy-Class"
5595
5582
  `);
5596
5583
  expect(std.err).toMatchInlineSnapshot(`""`);
5597
5584
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -5644,7 +5631,7 @@ addEventListener('fetch', event => {});`
5644
5631
  Uploaded test-name (TIMINGS)
5645
5632
  Published test-name (TIMINGS)
5646
5633
  https://test-name.test-sub-domain.workers.dev
5647
- Current Deployment ID: undefined"
5634
+ Current Deployment ID: Galaxy-Class"
5648
5635
  `);
5649
5636
  expect(std.err).toMatchInlineSnapshot(`""`);
5650
5637
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -5691,7 +5678,7 @@ addEventListener('fetch', event => {});`
5691
5678
  Uploaded test-name (TIMINGS)
5692
5679
  Published test-name (TIMINGS)
5693
5680
  https://test-name.test-sub-domain.workers.dev
5694
- Current Deployment ID: undefined"
5681
+ Current Deployment ID: Galaxy-Class"
5695
5682
  `);
5696
5683
  expect(std.err).toMatchInlineSnapshot(`""`);
5697
5684
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -5732,7 +5719,7 @@ addEventListener('fetch', event => {});`
5732
5719
  Uploaded test-name (TIMINGS)
5733
5720
  Published test-name (TIMINGS)
5734
5721
  https://test-name.test-sub-domain.workers.dev
5735
- Current Deployment ID: undefined"
5722
+ Current Deployment ID: Galaxy-Class"
5736
5723
  `);
5737
5724
  expect(std.err).toMatchInlineSnapshot(`""`);
5738
5725
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -5778,12 +5765,83 @@ addEventListener('fetch', event => {});`
5778
5765
  Uploaded test-name (TIMINGS)
5779
5766
  Published test-name (TIMINGS)
5780
5767
  https://test-name.test-sub-domain.workers.dev
5781
- Current Deployment ID: undefined"
5768
+ Current Deployment ID: Galaxy-Class"
5782
5769
  `);
5783
5770
  expect(std.err).toMatchInlineSnapshot(`""`);
5784
5771
  expect(std.warn).toMatchInlineSnapshot(`""`);
5785
5772
  });
5786
5773
 
5774
+ it("should support durable objects and D1", async () => {
5775
+ writeWranglerToml({
5776
+ main: "index.js",
5777
+ durable_objects: {
5778
+ bindings: [
5779
+ {
5780
+ name: "EXAMPLE_DO_BINDING",
5781
+ class_name: "ExampleDurableObject",
5782
+ },
5783
+ ],
5784
+ },
5785
+ migrations: [{ tag: "v1", new_classes: ["ExampleDurableObject"] }],
5786
+ d1_databases: [
5787
+ {
5788
+ binding: "DB",
5789
+ database_name: "test-d1-db",
5790
+ database_id: "UUID-1-2-3-4",
5791
+ preview_database_id: "UUID-1-2-3-4",
5792
+ },
5793
+ ],
5794
+ });
5795
+ const scriptContent = `export class ExampleDurableObject {}; export default{};`;
5796
+ fs.writeFileSync("index.js", scriptContent);
5797
+ mockSubDomainRequest();
5798
+ mockLegacyScriptData({
5799
+ scripts: [{ id: "test-name", migration_tag: "v1" }],
5800
+ });
5801
+ mockUploadWorkerRequest({
5802
+ expectedType: "esm",
5803
+ expectedBindings: [
5804
+ {
5805
+ name: "EXAMPLE_DO_BINDING",
5806
+ class_name: "ExampleDurableObject",
5807
+ type: "durable_object_namespace",
5808
+ },
5809
+ { name: "DB", type: "d1_database" },
5810
+ ],
5811
+ });
5812
+
5813
+ await runWrangler("publish index.js --outdir tmp --dry-run");
5814
+ expect(std.out).toMatchInlineSnapshot(`
5815
+ "Total Upload: xx KiB / gzip: xx KiB
5816
+ Your worker has access to the following bindings:
5817
+ - Durable Objects:
5818
+ - EXAMPLE_DO_BINDING: ExampleDurableObject
5819
+ - D1 Databases:
5820
+ - DB: test-d1-db (UUID-1-2-3-4), Preview: (UUID-1-2-3-4)
5821
+ --dry-run: exiting now."
5822
+ `);
5823
+ expect(std.err).toMatchInlineSnapshot(`""`);
5824
+ expect(std.warn).toMatchInlineSnapshot(`
5825
+ "▲ [WARNING] Processing wrangler.toml configuration:
5826
+
5827
+ - D1 Bindings are currently in alpha to allow the API to evolve before general availability.
5828
+ Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose
5829
+ Note: Run this command with the environment variable NO_D1_WARNING=true to hide this message
5830
+
5831
+ For example: \`export NO_D1_WARNING=true && wrangler <YOUR COMMAND HERE>\`
5832
+
5833
+ "
5834
+ `);
5835
+ const output = fs.readFileSync("tmp/d1-beta-facade.entry.js", "utf-8");
5836
+ expect(output).toContain(
5837
+ `var ExampleDurableObject2 = maskDurableObjectDefinition(ExampleDurableObject);`
5838
+ );
5839
+ expect(output).toContain(
5840
+ `ExampleDurableObject2 as ExampleDurableObject,`
5841
+ );
5842
+ expect(output).toContain(`shim_default as default`);
5843
+ });
5844
+
5787
5845
  it("should error when detecting a service-worker worker implementing durable objects", async () => {
5788
5846
  writeWranglerToml({
5789
5847
  durable_objects: {
@@ -5842,7 +5900,7 @@ addEventListener('fetch', event => {});`
5842
5900
  Uploaded test-name (TIMINGS)
5843
5901
  Published test-name (TIMINGS)
5844
5902
  https://test-name.test-sub-domain.workers.dev
5845
- Current Deployment ID: undefined"
5903
+ Current Deployment ID: Galaxy-Class"
5846
5904
  `);
5847
5905
  expect(std.err).toMatchInlineSnapshot(`""`);
5848
5906
  expect(std.warn).toMatchInlineSnapshot(`
@@ -5879,7 +5937,7 @@ addEventListener('fetch', event => {});`
5879
5937
  Uploaded test-name (TIMINGS)
5880
5938
  Published test-name (TIMINGS)
5881
5939
  https://test-name.test-sub-domain.workers.dev
5882
- Current Deployment ID: undefined"
5940
+ Current Deployment ID: Galaxy-Class"
5883
5941
  `);
5884
5942
  expect(std.err).toMatchInlineSnapshot(`""`);
5885
5943
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -5916,7 +5974,7 @@ addEventListener('fetch', event => {});`
5916
5974
  Uploaded test-name (TIMINGS)
5917
5975
  Published test-name (TIMINGS)
5918
5976
  https://test-name.test-sub-domain.workers.dev
5919
- Current Deployment ID: undefined"
5977
+ Current Deployment ID: Galaxy-Class"
5920
5978
  `);
5921
5979
  expect(std.err).toMatchInlineSnapshot(`""`);
5922
5980
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -5957,7 +6015,7 @@ addEventListener('fetch', event => {});`
5957
6015
  Uploaded test-name (TIMINGS)
5958
6016
  Published test-name (TIMINGS)
5959
6017
  https://test-name.test-sub-domain.workers.dev
5960
- Current Deployment ID: undefined"
6018
+ Current Deployment ID: Galaxy-Class"
5961
6019
  `);
5962
6020
  expect(std.err).toMatchInlineSnapshot(`""`);
5963
6021
  expect(std.warn).toMatchInlineSnapshot(`
@@ -6001,7 +6059,7 @@ addEventListener('fetch', event => {});`
6001
6059
  Uploaded test-name (TIMINGS)
6002
6060
  Published test-name (TIMINGS)
6003
6061
  https://test-name.test-sub-domain.workers.dev
6004
- Current Deployment ID: undefined"
6062
+ Current Deployment ID: Galaxy-Class"
6005
6063
  `);
6006
6064
  expect(std.err).toMatchInlineSnapshot(`""`);
6007
6065
  expect(std.warn).toMatchInlineSnapshot(`
@@ -6048,7 +6106,7 @@ addEventListener('fetch', event => {});`
6048
6106
  Uploaded test-name (TIMINGS)
6049
6107
  Published test-name (TIMINGS)
6050
6108
  https://test-name.test-sub-domain.workers.dev
6051
- Current Deployment ID: undefined"
6109
+ Current Deployment ID: Galaxy-Class"
6052
6110
  `);
6053
6111
  expect(std.err).toMatchInlineSnapshot(`""`);
6054
6112
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -6078,7 +6136,7 @@ addEventListener('fetch', event => {});`
6078
6136
  Uploaded test-name (TIMINGS)
6079
6137
  Published test-name (TIMINGS)
6080
6138
  https://test-name.test-sub-domain.workers.dev
6081
- Current Deployment ID: undefined"
6139
+ Current Deployment ID: Galaxy-Class"
6082
6140
  `);
6083
6141
  expect(std.err).toMatchInlineSnapshot(`""`);
6084
6142
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -6112,7 +6170,7 @@ addEventListener('fetch', event => {});`
6112
6170
  Uploaded test-name (TIMINGS)
6113
6171
  Published test-name (TIMINGS)
6114
6172
  https://test-name.test-sub-domain.workers.dev
6115
- Current Deployment ID: undefined"
6173
+ Current Deployment ID: Galaxy-Class"
6116
6174
  `);
6117
6175
  expect(std.err).toMatchInlineSnapshot(`""`);
6118
6176
  expect(std.warn).toMatchInlineSnapshot(`
@@ -6162,7 +6220,7 @@ addEventListener('fetch', event => {});`
6162
6220
  Uploaded test-name (TIMINGS)
6163
6221
  Published test-name (TIMINGS)
6164
6222
  https://test-name.test-sub-domain.workers.dev
6165
- Current Deployment ID: undefined"
6223
+ Current Deployment ID: Galaxy-Class"
6166
6224
  `);
6167
6225
  expect(std.err).toMatchInlineSnapshot(`""`);
6168
6226
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -6260,7 +6318,7 @@ addEventListener('fetch', event => {});`
6260
6318
  Uploaded test-name (TIMINGS)
6261
6319
  Published test-name (TIMINGS)
6262
6320
  https://test-name.test-sub-domain.workers.dev
6263
- Current Deployment ID: undefined"
6321
+ Current Deployment ID: Galaxy-Class"
6264
6322
  `);
6265
6323
  expect(std.err).toMatchInlineSnapshot(`""`);
6266
6324
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -6291,7 +6349,7 @@ addEventListener('fetch', event => {});`
6291
6349
  Uploaded test-name (TIMINGS)
6292
6350
  Published test-name (TIMINGS)
6293
6351
  https://test-name.test-sub-domain.workers.dev
6294
- Current Deployment ID: undefined"
6352
+ Current Deployment ID: Galaxy-Class"
6295
6353
  `);
6296
6354
  expect(std.err).toMatchInlineSnapshot(`""`);
6297
6355
  expect(std.warn).toMatchInlineSnapshot(`
@@ -6321,7 +6379,7 @@ addEventListener('fetch', event => {});`
6321
6379
  Uploaded test-name (TIMINGS)
6322
6380
  Published test-name (TIMINGS)
6323
6381
  https://test-name.test-sub-domain.workers.dev
6324
- Current Deployment ID: undefined"
6382
+ Current Deployment ID: Galaxy-Class"
6325
6383
  `);
6326
6384
  expect(std.err).toMatchInlineSnapshot(`""`);
6327
6385
  expect(std.warn).toMatchInlineSnapshot(`
@@ -6353,7 +6411,7 @@ addEventListener('fetch', event => {});`
6353
6411
  Uploaded test-name (TIMINGS)
6354
6412
  Published test-name (TIMINGS)
6355
6413
  https://test-name.test-sub-domain.workers.dev
6356
- Current Deployment ID: undefined"
6414
+ Current Deployment ID: Galaxy-Class"
6357
6415
  `);
6358
6416
  expect(std.err).toMatchInlineSnapshot(`""`);
6359
6417
  expect(std.warn).toMatchInlineSnapshot(`
@@ -6383,7 +6441,7 @@ addEventListener('fetch', event => {});`
6383
6441
  Uploaded test-name (TIMINGS)
6384
6442
  Published test-name (TIMINGS)
6385
6443
  https://test-name.test-sub-domain.workers.dev
6386
- Current Deployment ID: undefined"
6444
+ Current Deployment ID: Galaxy-Class"
6387
6445
  `);
6388
6446
  expect(std.err).toMatchInlineSnapshot(`""`);
6389
6447
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -6425,7 +6483,7 @@ addEventListener('fetch', event => {});`
6425
6483
  Uploaded test-name (TIMINGS)
6426
6484
  Published test-name (TIMINGS)
6427
6485
  https://test-name.test-sub-domain.workers.dev
6428
- Current Deployment ID: undefined",
6486
+ Current Deployment ID: Galaxy-Class",
6429
6487
  "warn": "",
6430
6488
  }
6431
6489
  `);
@@ -6456,7 +6514,7 @@ addEventListener('fetch', event => {});`
6456
6514
  Uploaded test-name (TIMINGS)
6457
6515
  Published test-name (TIMINGS)
6458
6516
  https://test-name.test-sub-domain.workers.dev
6459
- Current Deployment ID: undefined",
6517
+ Current Deployment ID: Galaxy-Class",
6460
6518
  "warn": "",
6461
6519
  }
6462
6520
  `);
@@ -6480,7 +6538,62 @@ addEventListener('fetch', event => {});`
6480
6538
  Uploaded test-name (TIMINGS)
6481
6539
  Published test-name (TIMINGS)
6482
6540
  https://test-name.test-sub-domain.workers.dev
6483
- Current Deployment ID: undefined",
6541
+ Current Deployment ID: Galaxy-Class",
6542
+ "warn": "",
6543
+ }
6544
+ `);
6545
+ });
6546
+
6547
+ it("should copy any module imports related assets at --outdir if specified", async () => {
6548
+ writeWranglerToml();
6549
+ fs.writeFileSync(
6550
+ "./index.js",
6551
+ `
6552
+ import txt from './textfile.txt';
6553
+ import hello from './hello.wasm';
6554
+ export default{
6555
+ async fetch(){
6556
+ const module = await WebAssembly.instantiate(hello);
6557
+ return new Response(txt + module.exports.hello);
6558
+ }
6559
+ }
6560
+ `
6561
+ );
6562
+ fs.writeFileSync("./textfile.txt", "Hello, World!");
6563
+ fs.writeFileSync("./hello.wasm", "Hello wasm World!");
6564
+ mockSubDomainRequest();
6565
+ mockUploadWorkerRequest({
6566
+ expectedModules: {
6567
+ "./0a0a9f2a6772942557ab5355d76af442f8f65e01-textfile.txt":
6568
+ "Hello, World!",
6569
+ "./d025a03cd31e98e96fb5bd5bce87f9bca4e8ce2c-hello.wasm":
6570
+ "Hello wasm World!",
6571
+ },
6572
+ });
6573
+ await runWrangler("publish index.js --outdir some-dir");
6574
+
6575
+ expect(fs.existsSync("some-dir/index.js")).toBe(true);
6576
+ expect(fs.existsSync("some-dir/index.js.map")).toBe(true);
6577
+ expect(fs.existsSync("some-dir/README.md")).toBe(true);
6578
+ expect(
6579
+ fs.existsSync(
6580
+ "some-dir/0a0a9f2a6772942557ab5355d76af442f8f65e01-textfile.txt"
6581
+ )
6582
+ ).toBe(true);
6583
+ expect(
6584
+ fs.existsSync(
6585
+ "some-dir/d025a03cd31e98e96fb5bd5bce87f9bca4e8ce2c-hello.wasm"
6586
+ )
6587
+ ).toBe(true);
6588
+ expect(std).toMatchInlineSnapshot(`
6589
+ Object {
6590
+ "debug": "",
6591
+ "err": "",
6592
+ "out": "Total Upload: xx KiB / gzip: xx KiB
6593
+ Uploaded test-name (TIMINGS)
6594
+ Published test-name (TIMINGS)
6595
+ https://test-name.test-sub-domain.workers.dev
6596
+ Current Deployment ID: Galaxy-Class",
6484
6597
  "warn": "",
6485
6598
  }
6486
6599
  `);
@@ -6617,6 +6730,7 @@ addEventListener('fetch', event => {});`
6617
6730
  mockSubDomainRequest();
6618
6731
  mockUploadWorkerRequest();
6619
6732
  await runWrangler("publish");
6733
+
6620
6734
  expect(std).toMatchInlineSnapshot(`
6621
6735
  Object {
6622
6736
  "debug": "",
@@ -6625,26 +6739,35 @@ addEventListener('fetch', event => {});`
6625
6739
  Uploaded test-name (TIMINGS)
6626
6740
  Published test-name (TIMINGS)
6627
6741
  https://test-name.test-sub-domain.workers.dev
6628
- Current Deployment ID: undefined",
6742
+ Current Deployment ID: Galaxy-Class",
6629
6743
  "warn": "",
6630
6744
  }
6631
6745
  `);
6632
6746
  });
6633
6747
 
6634
6748
  it("should print the bundle size, with API errors", async () => {
6635
- setMockRawResponse(
6636
- "/accounts/:accountId/workers/scripts/:scriptName",
6637
- "PUT",
6638
- () => {
6639
- return createFetchResult({}, false, [
6640
- {
6641
- code: 11337,
6642
- message:
6643
- "Script startup timed out. This could be due to script exceeding size limits or expensive code in the global scope.",
6644
- },
6645
- ]);
6646
- }
6749
+ mockSubDomainRequest();
6750
+ mockUploadWorkerRequest();
6751
+ // Override PUT call to error out from previous helper functions
6752
+ msw.use(
6753
+ rest.put(
6754
+ "*/accounts/:accountId/workers/scripts/:scriptName",
6755
+ (_, res, ctx) => {
6756
+ return res(
6757
+ ctx.json(
6758
+ createFetchResult(null, false, [
6759
+ {
6760
+ code: 11337,
6761
+ message:
6762
+ "Script startup timed out. This could be due to script exceeding size limits or expensive code in the global scope.",
6763
+ },
6764
+ ])
6765
+ )
6766
+ );
6767
+ }
6768
+ )
6647
6769
  );
6770
+
6648
6771
  fs.writeFileSync(
6649
6772
  "./hello.html",
6650
6773
  `<!DOCTYPE html>
@@ -6665,11 +6788,11 @@ addEventListener('fetch', event => {});`
6665
6788
  },
6666
6789
  };`
6667
6790
  );
6791
+
6668
6792
  writeWranglerToml({
6669
6793
  main: "index.js",
6670
6794
  });
6671
- mockSubDomainRequest();
6672
- mockUploadWorkerRequest();
6795
+
6673
6796
  await expect(runWrangler("publish")).rejects.toMatchInlineSnapshot(
6674
6797
  `[ParseError: A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name) failed.]`
6675
6798
  );
@@ -6694,6 +6817,27 @@ addEventListener('fetch', event => {});`
6694
6817
  });
6695
6818
 
6696
6819
  test("should check biggest dependencies when upload fails with script size error", async () => {
6820
+ mockSubDomainRequest();
6821
+ mockUploadWorkerRequest();
6822
+ // Override PUT call to error out from previous helper functions
6823
+ msw.use(
6824
+ rest.put(
6825
+ "*/accounts/:accountId/workers/scripts/:scriptName",
6826
+ (req, res, ctx) => {
6827
+ return res(
6828
+ ctx.json(
6829
+ createFetchResult({}, false, [
6830
+ {
6831
+ code: 10027,
6832
+ message: "workers.api.error.script_too_large",
6833
+ },
6834
+ ])
6835
+ )
6836
+ );
6837
+ }
6838
+ )
6839
+ );
6840
+
6697
6841
  fs.writeFileSync("dependency.js", `export const thing = "a string dep";`);
6698
6842
 
6699
6843
  fs.writeFileSync(
@@ -6706,23 +6850,15 @@ addEventListener('fetch', event => {});`
6706
6850
  }
6707
6851
  }`
6708
6852
  );
6709
- setMockRawResponse(
6710
- "/accounts/:accountId/workers/scripts/:scriptName",
6711
- "PUT",
6712
- () => {
6713
- return createFetchResult({}, false, [
6714
- { code: 10027, message: "workers.api.error.script_too_large" },
6715
- ]);
6716
- }
6717
- );
6853
+
6718
6854
  writeWranglerToml({
6719
6855
  main: "index.js",
6720
6856
  });
6721
- mockSubDomainRequest();
6722
- mockUploadWorkerRequest();
6857
+
6723
6858
  await expect(runWrangler("publish")).rejects.toMatchInlineSnapshot(
6724
6859
  `[ParseError: A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name) failed.]`
6725
6860
  );
6861
+
6726
6862
  expect(std).toMatchInlineSnapshot(`
6727
6863
  Object {
6728
6864
  "debug": "",
@@ -6748,7 +6884,27 @@ addEventListener('fetch', event => {});`
6748
6884
  `);
6749
6885
  });
6750
6886
 
6751
- test("should check biggest dependencies when upload fails with script startup error", async () => {
6887
+ test("should offer some helpful advice when upload fails with script startup error", async () => {
6888
+ mockSubDomainRequest();
6889
+ mockUploadWorkerRequest();
6890
+ // Override PUT call to error out from previous helper functions
6891
+ msw.use(
6892
+ rest.put(
6893
+ "*/accounts/:accountId/workers/scripts/:scriptName",
6894
+ (req, res, ctx) => {
6895
+ return res(
6896
+ ctx.json(
6897
+ createFetchResult({}, false, [
6898
+ {
6899
+ code: 10021,
6900
+ message: "Error: Script startup exceeded CPU time limit.",
6901
+ },
6902
+ ])
6903
+ )
6904
+ );
6905
+ }
6906
+ )
6907
+ );
6752
6908
  fs.writeFileSync("dependency.js", `export const thing = "a string dep";`);
6753
6909
 
6754
6910
  fs.writeFileSync(
@@ -6761,23 +6917,11 @@ addEventListener('fetch', event => {});`
6761
6917
  }
6762
6918
  }`
6763
6919
  );
6764
- setMockRawResponse(
6765
- "/accounts/:accountId/workers/scripts/:scriptName",
6766
- "PUT",
6767
- () => {
6768
- return createFetchResult({}, false, [
6769
- {
6770
- code: 10021,
6771
- message: "Error: Script startup exceeded CPU time limit.",
6772
- },
6773
- ]);
6774
- }
6775
- );
6920
+
6776
6921
  writeWranglerToml({
6777
6922
  main: "index.js",
6778
6923
  });
6779
- mockSubDomainRequest();
6780
- mockUploadWorkerRequest();
6924
+
6781
6925
  await expect(runWrangler("publish")).rejects.toMatchInlineSnapshot(
6782
6926
  `[ParseError: A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name) failed.]`
6783
6927
  );
@@ -6795,11 +6939,13 @@ addEventListener('fetch', event => {});`
6795
6939
  https://github.com/cloudflare/wrangler2/issues/new/choose
6796
6940
 
6797
6941
  ",
6798
- "warn": "▲ [WARNING] Here are the 2 largest dependencies included in your script:
6942
+ "warn": "▲ [WARNING] Your Worker failed validation because it exceeded startup limits.
6799
6943
 
6800
- - index.js - xx KiB
6801
- - dependency.js - xx KiB
6802
- If these are unnecessary, consider removing them
6944
+ To ensure fast responses, we place constraints on Worker startup -- like how much CPU it can use,
6945
+ or how long it can take.
6946
+ Your Worker failed validation, which means it hit one of these startup limits.
6947
+ Try reducing the amount of work done during startup (outside the event handler), either by
6948
+ removing code or relocating it inside the event handler.
6803
6949
 
6804
6950
  ",
6805
6951
  }
@@ -6991,25 +7137,35 @@ addEventListener('fetch', event => {});`
6991
7137
  });
6992
7138
 
6993
7139
  it("should publish if the last deployed source check fails", async () => {
6994
- unsetAllMocks();
6995
7140
  writeWorkerSource();
6996
7141
  writeWranglerToml();
6997
7142
  mockSubDomainRequest();
6998
7143
  mockUploadWorkerRequest();
6999
- setMockResponse(
7000
- "/accounts/:accountId/workers/deployments/by-script/:scriptTag",
7001
- () => ({
7002
- latest: { number: "2" },
7003
- })
7004
- );
7005
- setMockRawResponse(
7006
- "/accounts/:accountId/workers/services/:scriptName",
7007
- "GET",
7008
- () => {
7009
- return createFetchResult(null, false, [
7010
- { code: 10090, message: "workers.api.error.service_not_found" },
7011
- ]);
7012
- }
7144
+ msw.use(
7145
+ rest.get(
7146
+ "*/accounts/:accountId/workers/deployments/by-script/:scriptTag",
7147
+ (_, res, ctx) => {
7148
+ return res(
7149
+ ctx.json(
7150
+ createFetchResult({
7151
+ latest: { number: "2" },
7152
+ })
7153
+ )
7154
+ );
7155
+ }
7156
+ ),
7157
+ rest.get(
7158
+ "*/accounts/:accountId/workers/services/:scriptName",
7159
+ (_, res, ctx) => {
7160
+ return res(
7161
+ ctx.json(
7162
+ createFetchResult(null, false, [
7163
+ { code: 10090, message: "workers.api.error.service_not_found" },
7164
+ ])
7165
+ )
7166
+ );
7167
+ }
7168
+ )
7013
7169
  );
7014
7170
 
7015
7171
  await runWrangler("publish index.js");
@@ -7028,25 +7184,36 @@ addEventListener('fetch', event => {});`
7028
7184
  });
7029
7185
 
7030
7186
  it("should not publish if there's any other kind of error when checking deployment source", async () => {
7031
- unsetAllMocks();
7032
7187
  writeWorkerSource();
7033
7188
  writeWranglerToml();
7034
7189
  mockSubDomainRequest();
7035
7190
  mockUploadWorkerRequest();
7036
- setMockRawResponse(
7037
- "/accounts/:accountId/workers/services/:scriptName",
7038
- "GET",
7039
- () => {
7040
- return createFetchResult(null, false, [
7041
- { code: 10000, message: "Authentication error" },
7042
- ]);
7043
- }
7044
- );
7045
- setMockResponse(
7046
- "/accounts/:accountId/workers/deployments/by-script/:scriptTag",
7047
- () => ({
7048
- latest: { number: "2" },
7049
- })
7191
+
7192
+ msw.use(
7193
+ rest.get(
7194
+ "*/accounts/:accountId/workers/services/:scriptName",
7195
+ (_, res, ctx) => {
7196
+ return res(
7197
+ ctx.json(
7198
+ createFetchResult(null, false, [
7199
+ { code: 10000, message: "Authentication error" },
7200
+ ])
7201
+ )
7202
+ );
7203
+ }
7204
+ ),
7205
+ rest.get(
7206
+ "*/accounts/:accountId/workers/deployments/by-script/:scriptTag",
7207
+ (_, res, ctx) => {
7208
+ return res(
7209
+ ctx.json(
7210
+ createFetchResult({
7211
+ latest: { number: "2" },
7212
+ })
7213
+ )
7214
+ );
7215
+ }
7216
+ )
7050
7217
  );
7051
7218
 
7052
7219
  await runWrangler("publish index.js");
@@ -7084,7 +7251,7 @@ addEventListener('fetch', event => {});`
7084
7251
  Uploaded test-name (TIMINGS)
7085
7252
  Published test-name (TIMINGS)
7086
7253
  https://test-name.test-sub-domain.workers.dev
7087
- Current Deployment ID: undefined"
7254
+ Current Deployment ID: Galaxy-Class"
7088
7255
  `);
7089
7256
  });
7090
7257
 
@@ -7121,7 +7288,7 @@ addEventListener('fetch', event => {});`
7121
7288
  Published test-name (TIMINGS)
7122
7289
  https://test-name.test-sub-domain.workers.dev
7123
7290
  Consumer for queue1
7124
- Current Deployment ID: undefined"
7291
+ Current Deployment ID: Galaxy-Class"
7125
7292
  `);
7126
7293
  });
7127
7294
 
@@ -7193,7 +7360,7 @@ addEventListener('fetch', event => {});`
7193
7360
  Uploaded test-name (TIMINGS)
7194
7361
  Published test-name (TIMINGS)
7195
7362
  https://test-name.test-sub-domain.workers.dev
7196
- Current Deployment ID: undefined"
7363
+ Current Deployment ID: Galaxy-Class"
7197
7364
  `);
7198
7365
  expect(std.err).toMatchInlineSnapshot(`""`);
7199
7366
  });
@@ -7218,7 +7385,7 @@ addEventListener('fetch', event => {});`
7218
7385
  Uploaded test-name (TIMINGS)
7219
7386
  Published test-name (TIMINGS)
7220
7387
  https://test-name.test-sub-domain.workers.dev
7221
- Current Deployment ID: undefined"
7388
+ Current Deployment ID: Galaxy-Class"
7222
7389
  `);
7223
7390
  expect(std.err).toMatchInlineSnapshot(`""`);
7224
7391
  });
@@ -7238,6 +7405,13 @@ function writeAssets(
7238
7405
  fs.writeFileSync(filePathDestination, asset.content);
7239
7406
  }
7240
7407
  }
7408
+ function mockDeploymentsListRequest() {
7409
+ msw.use(...mswSuccessDeployments);
7410
+ }
7411
+
7412
+ function mockLastDeploymentRequest() {
7413
+ msw.use(...mswSuccessLastDeployment);
7414
+ }
7241
7415
 
7242
7416
  /** Create a mock handler for the request to upload a worker script. */
7243
7417
  function mockUploadWorkerRequest(
@@ -7273,73 +7447,90 @@ function mockUploadWorkerRequest(
7273
7447
  sendScriptIds,
7274
7448
  keepVars,
7275
7449
  } = options;
7276
- setMockResponse(
7277
- env && !legacyEnv
7278
- ? "/accounts/:accountId/workers/services/:scriptName/environments/:envName"
7279
- : "/accounts/:accountId/workers/scripts/:scriptName",
7280
- "PUT",
7281
- async ([_url, accountId, scriptName, envName], { body }, queryParams) => {
7282
- expect(accountId).toEqual("some-account-id");
7283
- expect(scriptName).toEqual(
7284
- legacyEnv && env ? `test-name-${env}` : "test-name"
7285
- );
7286
- if (!legacyEnv) {
7287
- expect(envName).toEqual(env);
7288
- }
7289
- expect(queryParams.get("include_subdomain_availability")).toEqual("true");
7290
- expect(queryParams.get("excludeScript")).toEqual("true");
7291
- const formBody = body as FormData;
7292
- if (expectedEntry !== undefined) {
7293
- expect(await (formBody.get("index.js") as File).text()).toMatch(
7294
- expectedEntry
7295
- );
7296
- }
7297
- const metadata = JSON.parse(
7298
- formBody.get("metadata") as string
7299
- ) as WorkerMetadata;
7300
- if (expectedType === "esm") {
7301
- expect(metadata.main_module).toEqual(expectedMainModule);
7302
- } else {
7303
- expect(metadata.body_part).toEqual("index.js");
7304
- }
7450
+ if (env && !legacyEnv) {
7451
+ msw.use(
7452
+ rest.put(
7453
+ "*/accounts/:accountId/workers/services/:scriptName/environments/:envName",
7454
+ handleUpload
7455
+ )
7456
+ );
7457
+ } else {
7458
+ msw.use(
7459
+ rest.put(
7460
+ "*/accounts/:accountId/workers/scripts/:scriptName",
7461
+ handleUpload
7462
+ )
7463
+ );
7464
+ }
7305
7465
 
7306
- if (keepVars) {
7307
- expect(metadata.keep_bindings).toEqual(["plain_text", "json"]);
7308
- } else {
7309
- expect(metadata.keep_bindings).toBeFalsy();
7310
- }
7466
+ async function handleUpload(
7467
+ req: RestRequest,
7468
+ res: ResponseComposition,
7469
+ ctx: RestContext
7470
+ ) {
7471
+ expect(req.params.accountId).toEqual("some-account-id");
7472
+ expect(req.params.scriptName).toEqual(
7473
+ legacyEnv && env ? `test-name-${env}` : "test-name"
7474
+ );
7475
+ if (!legacyEnv) {
7476
+ expect(req.params.envName).toEqual(env);
7477
+ }
7478
+ expect(req.url.searchParams.get("include_subdomain_availability")).toEqual(
7479
+ "true"
7480
+ );
7481
+ expect(req.url.searchParams.get("excludeScript")).toEqual("true");
7311
7482
 
7312
- if ("expectedBindings" in options) {
7313
- expect(metadata.bindings).toEqual(expectedBindings);
7314
- }
7315
- if ("expectedCompatibilityDate" in options) {
7316
- expect(metadata.compatibility_date).toEqual(expectedCompatibilityDate);
7317
- }
7318
- if ("expectedCompatibilityFlags" in options) {
7319
- expect(metadata.compatibility_flags).toEqual(
7320
- expectedCompatibilityFlags
7321
- );
7322
- }
7323
- if ("expectedMigrations" in options) {
7324
- expect(metadata.migrations).toEqual(expectedMigrations);
7325
- }
7326
- for (const [name, content] of Object.entries(expectedModules)) {
7327
- expect(await (formBody.get(name) as File).text()).toEqual(content);
7328
- }
7483
+ const formBody = await (
7484
+ req as MockedRequest as RestRequestWithFormData
7485
+ ).formData();
7486
+ if (expectedEntry !== undefined) {
7487
+ expect(formBody.get("index.js")).toMatch(expectedEntry);
7488
+ }
7489
+ const metadata = JSON.parse(
7490
+ formBody.get("metadata") as string
7491
+ ) as WorkerMetadata;
7492
+ if (expectedType === "esm") {
7493
+ expect(metadata.main_module).toEqual(expectedMainModule);
7494
+ } else {
7495
+ expect(metadata.body_part).toEqual("index.js");
7496
+ }
7329
7497
 
7330
- return {
7331
- available_on_subdomain,
7332
- ...(sendScriptIds
7333
- ? {
7334
- id: "abc12345",
7335
- etag: "etag98765",
7336
- pipeline_hash: "hash9999",
7337
- tag: "sample-tag",
7338
- }
7339
- : {}),
7340
- };
7498
+ if (keepVars) {
7499
+ expect(metadata.keep_bindings).toEqual(["plain_text", "json"]);
7500
+ } else {
7501
+ expect(metadata.keep_bindings).toBeFalsy();
7341
7502
  }
7342
- );
7503
+
7504
+ if ("expectedBindings" in options) {
7505
+ expect(metadata.bindings).toEqual(expectedBindings);
7506
+ }
7507
+ if ("expectedCompatibilityDate" in options) {
7508
+ expect(metadata.compatibility_date).toEqual(expectedCompatibilityDate);
7509
+ }
7510
+ if ("expectedCompatibilityFlags" in options) {
7511
+ expect(metadata.compatibility_flags).toEqual(expectedCompatibilityFlags);
7512
+ }
7513
+ if ("expectedMigrations" in options) {
7514
+ expect(metadata.migrations).toEqual(expectedMigrations);
7515
+ }
7516
+ for (const [name, content] of Object.entries(expectedModules)) {
7517
+ expect(formBody.get(name)).toEqual(content);
7518
+ }
7519
+
7520
+ return res(
7521
+ ctx.json(
7522
+ createFetchResult({
7523
+ available_on_subdomain,
7524
+ ...(sendScriptIds && {
7525
+ id: "abc12345",
7526
+ etag: "etag98765",
7527
+ pipeline_hash: "hash9999",
7528
+ tag: "sample-tag",
7529
+ }),
7530
+ })
7531
+ )
7532
+ );
7533
+ }
7343
7534
  }
7344
7535
 
7345
7536
  /** Create a mock handler for the request to get the account's subdomain. */
@@ -7348,18 +7539,30 @@ function mockSubDomainRequest(
7348
7539
  registeredWorkersDev = true
7349
7540
  ) {
7350
7541
  if (registeredWorkersDev) {
7351
- setMockResponse("/accounts/:accountId/workers/subdomain", "GET", () => {
7352
- return { subdomain };
7353
- });
7542
+ msw.use(
7543
+ rest.get("*/accounts/:accountId/workers/subdomain", (req, res, ctx) => {
7544
+ return res.once(ctx.json(createFetchResult({ subdomain })));
7545
+ })
7546
+ );
7354
7547
  } else {
7355
- setMockRawResponse("/accounts/:accountId/workers/subdomain", "GET", () => {
7356
- return createFetchResult(null, false, [
7357
- { code: 10007, message: "haven't registered workers.dev" },
7358
- ]);
7359
- });
7548
+ msw.use(
7549
+ rest.get("*/accounts/:accountId/workers/subdomain", (req, res, ctx) => {
7550
+ return res.once(
7551
+ ctx.json(
7552
+ createFetchResult(null, false, [
7553
+ { code: 10007, message: "haven't registered workers.dev" },
7554
+ ])
7555
+ )
7556
+ );
7557
+ })
7558
+ );
7360
7559
  }
7361
7560
  }
7362
-
7561
+ //
7562
+ //
7563
+ //
7564
+ //
7565
+ //
7363
7566
  /** Create a mock handler to toggle a <script>.<user>.workers.dev subdomain */
7364
7567
  function mockUpdateWorkerRequest({
7365
7568
  env,
@@ -7373,20 +7576,22 @@ function mockUpdateWorkerRequest({
7373
7576
  const requests = { count: 0 };
7374
7577
  const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
7375
7578
  const environment = env && !legacyEnv ? "/environments/:envName" : "";
7376
- setMockResponse(
7377
- `/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/subdomain`,
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);
7579
+ msw.use(
7580
+ rest.post(
7581
+ `*/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/subdomain`,
7582
+ async (req, res, ctx) => {
7583
+ expect(req.params.accountId).toEqual("some-account-id");
7584
+ expect(req.params.scriptName).toEqual(
7585
+ legacyEnv && env ? `test-name-${env}` : "test-name"
7586
+ );
7587
+ if (!legacyEnv) {
7588
+ expect(req.params.envName).toEqual(env);
7589
+ }
7590
+ const body = await req.json();
7591
+ expect(body).toEqual({ enabled });
7592
+ return res.once(ctx.json(createFetchResult(null)));
7386
7593
  }
7387
- expect(JSON.parse(body as string)).toEqual({ enabled });
7388
- return null;
7389
- }
7594
+ )
7390
7595
  );
7391
7596
  return requests;
7392
7597
  }
@@ -7403,25 +7608,26 @@ function mockPublishRoutesRequest({
7403
7608
  const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
7404
7609
  const environment = env && !legacyEnv ? "/environments/:envName" : "";
7405
7610
 
7406
- setMockResponse(
7407
- `/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/routes`,
7408
- "PUT",
7409
- ([_url, accountId, scriptName, envName], { body }) => {
7410
- expect(accountId).toEqual("some-account-id");
7411
- expect(scriptName).toEqual(
7412
- legacyEnv && env ? `test-name-${env}` : "test-name"
7413
- );
7414
- if (!legacyEnv) {
7415
- expect(envName).toEqual(env);
7611
+ msw.use(
7612
+ rest.put(
7613
+ `*/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/routes`,
7614
+ async (req, res, ctx) => {
7615
+ expect(req.params.accountId).toEqual("some-account-id");
7616
+ expect(req.params.scriptName).toEqual(
7617
+ legacyEnv && env ? `test-name-${env}` : "test-name"
7618
+ );
7619
+ if (!legacyEnv) {
7620
+ expect(req.params.envName).toEqual(env);
7621
+ }
7622
+ const body = await req.json();
7623
+ expect(body).toEqual(
7624
+ routes.map((route) =>
7625
+ typeof route !== "object" ? { pattern: route } : route
7626
+ )
7627
+ );
7628
+ return res.once(ctx.json(createFetchResult(null)));
7416
7629
  }
7417
-
7418
- expect(JSON.parse(body as string)).toEqual(
7419
- routes.map((route) =>
7420
- typeof route !== "object" ? { pattern: route } : route
7421
- )
7422
- );
7423
- return null;
7424
- }
7630
+ )
7425
7631
  );
7426
7632
  }
7427
7633
 
@@ -7435,13 +7641,19 @@ function mockUnauthorizedPublishRoutesRequest({
7435
7641
  const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
7436
7642
  const environment = env && !legacyEnv ? "/environments/:envName" : "";
7437
7643
 
7438
- setMockRawResponse(
7439
- `/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/routes`,
7440
- "PUT",
7441
- () =>
7442
- createFetchResult(null, false, [
7443
- { message: "Authentication error", code: 10000 },
7444
- ])
7644
+ msw.use(
7645
+ rest.put(
7646
+ `*/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/routes`,
7647
+ (req, res, ctx) => {
7648
+ return res.once(
7649
+ ctx.json(
7650
+ createFetchResult(null, false, [
7651
+ { message: "Authentication error", code: 10000 },
7652
+ ])
7653
+ )
7654
+ );
7655
+ }
7656
+ )
7445
7657
  );
7446
7658
  }
7447
7659
 
@@ -7449,22 +7661,27 @@ function mockPublishRoutesFallbackRequest(route: {
7449
7661
  pattern: string;
7450
7662
  script: string;
7451
7663
  }) {
7452
- setMockResponse(`/zones/:zoneId/workers/routes`, "POST", (_url, { body }) => {
7453
- expect(JSON.parse(body as string)).toEqual(route);
7454
- return route.pattern;
7455
- });
7664
+ msw.use(
7665
+ rest.post(`*/zones/:zoneId/workers/routes`, async (req, res, ctx) => {
7666
+ const body = await req.json();
7667
+ expect(body).toEqual(route);
7668
+ return res.once(ctx.json(createFetchResult(route.pattern)));
7669
+ })
7670
+ );
7456
7671
  }
7457
7672
 
7458
7673
  function mockCustomDomainLookup(origin: CustomDomain) {
7459
- setMockResponse(
7460
- `/accounts/:accountId/workers/domains/records/:domainTag`,
7461
- "GET",
7462
- ([_url, accountId, domainTag]) => {
7463
- expect(accountId).toEqual("some-account-id");
7464
- expect(domainTag).toEqual(origin.id);
7465
-
7466
- return origin;
7467
- }
7674
+ msw.use(
7675
+ rest.get(
7676
+ `*/accounts/:accountId/workers/domains/records/:domainTag`,
7677
+
7678
+ (req, res, ctx) => {
7679
+ expect(req.params.accountId).toEqual("some-account-id");
7680
+ expect(req.params.domainTag).toEqual(origin.id);
7681
+
7682
+ return res.once(ctx.json(createFetchResult(origin)));
7683
+ }
7684
+ )
7468
7685
  );
7469
7686
  }
7470
7687
 
@@ -7481,47 +7698,47 @@ function mockCustomDomainsChangesetRequest({
7481
7698
  }) {
7482
7699
  const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
7483
7700
  const environment = env && !legacyEnv ? "/environments/:envName" : "";
7701
+ msw.use(
7702
+ rest.post(
7703
+ `*/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/domains/changeset`,
7704
+ async (req, res, ctx) => {
7705
+ expect(req.params.accountId).toEqual("some-account-id");
7706
+ expect(req.params.scriptName).toEqual(
7707
+ legacyEnv && env ? `test-name-${env}` : "test-name"
7708
+ );
7709
+ if (!legacyEnv) {
7710
+ expect(req.params.envName).toEqual(env);
7711
+ }
7484
7712
 
7485
- setMockResponse(
7486
- `/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/domains/changeset`,
7487
- "POST",
7488
- ([_url, accountId, scriptName, envName], { body }) => {
7489
- expect(accountId).toEqual("some-account-id");
7490
- expect(scriptName).toEqual(
7491
- legacyEnv && env ? `test-name-${env}` : "test-name"
7492
- );
7493
- if (!legacyEnv) {
7494
- expect(envName).toEqual(env);
7495
- }
7713
+ const domains: Array<
7714
+ { hostname: string } & ({ zone_id?: string } | { zone_name?: string })
7715
+ > = await req.json();
7496
7716
 
7497
- const domains: Array<
7498
- { hostname: string } & ({ zone_id?: string } | { zone_name?: string })
7499
- > = JSON.parse(body as string);
7500
-
7501
- const changeset: CustomDomainChangeset = {
7502
- added: domains.map((domain) => {
7503
- return {
7504
- ...domain,
7505
- id: "",
7506
- service: scriptName,
7507
- environment: envName,
7508
- zone_name: "",
7509
- zone_id: "",
7510
- };
7511
- }),
7512
- removed: [],
7513
- updated:
7514
- originConflicts?.map((domain) => {
7717
+ const changeset: CustomDomainChangeset = {
7718
+ added: domains.map((domain) => {
7515
7719
  return {
7516
7720
  ...domain,
7517
- modified: true,
7721
+ id: "",
7722
+ service: req.params.scriptName as string,
7723
+ environment: req.params.envName as string,
7724
+ zone_name: "",
7725
+ zone_id: "",
7518
7726
  };
7519
- }) ?? [],
7520
- conflicting: dnsRecordConflicts,
7521
- };
7727
+ }),
7728
+ removed: [],
7729
+ updated:
7730
+ originConflicts?.map((domain) => {
7731
+ return {
7732
+ ...domain,
7733
+ modified: true,
7734
+ };
7735
+ }) ?? [],
7736
+ conflicting: dnsRecordConflicts,
7737
+ };
7522
7738
 
7523
- return changeset;
7524
- }
7739
+ return res.once(ctx.json(createFetchResult(changeset)));
7740
+ }
7741
+ )
7525
7742
  );
7526
7743
  }
7527
7744
 
@@ -7545,37 +7762,36 @@ function mockPublishCustomDomainsRequest({
7545
7762
  const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
7546
7763
  const environment = env && !legacyEnv ? "/environments/:envName" : "";
7547
7764
 
7548
- setMockResponse(
7549
- `/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/domains/records`,
7550
- "PUT",
7551
- ([_url, accountId, scriptName, envName], { body }) => {
7552
- expect(accountId).toEqual("some-account-id");
7553
- expect(scriptName).toEqual(
7554
- legacyEnv && env ? `test-name-${env}` : "test-name"
7555
- );
7556
- if (!legacyEnv) {
7557
- expect(envName).toEqual(env);
7558
- }
7559
-
7560
- expect(JSON.parse(body as string)).toEqual({
7561
- ...publishFlags,
7562
- origins: domains,
7563
- });
7765
+ msw.use(
7766
+ rest.put(
7767
+ `*/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/domains/records`,
7768
+ async (req, res, ctx) => {
7769
+ expect(req.params.accountId).toEqual("some-account-id");
7770
+ expect(req.params.scriptName).toEqual(
7771
+ legacyEnv && env ? `test-name-${env}` : "test-name"
7772
+ );
7773
+ if (!legacyEnv) {
7774
+ expect(req.params.envName).toEqual(env);
7775
+ }
7776
+ const body = await req.json();
7777
+ expect(body).toEqual({
7778
+ ...publishFlags,
7779
+ origins: domains,
7780
+ });
7564
7781
 
7565
- return null;
7566
- }
7782
+ return res.once(ctx.json(createFetchResult(null)));
7783
+ }
7784
+ )
7567
7785
  );
7568
7786
  }
7569
7787
 
7570
7788
  /** Create a mock handler for the request to get a list of all KV namespaces. */
7571
7789
  function mockListKVNamespacesRequest(...namespaces: KVNamespaceInfo[]) {
7572
- setMockResponse(
7573
- "/accounts/:accountId/storage/kv/namespaces",
7574
- "GET",
7575
- ([_url, accountId]) => {
7576
- expect(accountId).toEqual("some-account-id");
7577
- return namespaces;
7578
- }
7790
+ msw.use(
7791
+ rest.get("*/accounts/:accountId/storage/kv/namespaces", (req, res, ctx) => {
7792
+ expect(req.params.accountId).toEqual("some-account-id");
7793
+ return res.once(ctx.json(createFetchResult(namespaces)));
7794
+ })
7579
7795
  );
7580
7796
  }
7581
7797
 
@@ -7594,6 +7810,7 @@ interface StaticAssetUpload {
7594
7810
  }
7595
7811
 
7596
7812
  /** Create a mock handler for the request that tries to do a bulk upload of assets to a KV namespace. */
7813
+ //TODO: This is getting called multiple times in the test, we need to check if that is happening in Production --Jacob 2021-03-02
7597
7814
  function mockUploadAssetsToKVRequest(
7598
7815
  expectedNamespaceId: string,
7599
7816
  assets?: ExpectedAsset[]
@@ -7601,22 +7818,24 @@ function mockUploadAssetsToKVRequest(
7601
7818
  const requests: {
7602
7819
  uploads: StaticAssetUpload[];
7603
7820
  }[] = [];
7604
- setMockResponse(
7605
- "/accounts/:accountId/storage/kv/namespaces/:namespaceId/bulk",
7606
- "PUT",
7607
- ([_url, accountId, namespaceId], { body }) => {
7608
- expect(accountId).toEqual("some-account-id");
7609
- expect(namespaceId).toEqual(expectedNamespaceId);
7610
- const uploads = JSON.parse(body as string);
7611
- if (assets) {
7612
- expect(assets.length).toEqual(uploads.length);
7613
- for (let i = 0; i < uploads.length; i++) {
7614
- checkAssetUpload(assets[i], uploads[i]);
7821
+ msw.use(
7822
+ rest.put(
7823
+ "*/accounts/:accountId/storage/kv/namespaces/:namespaceId/bulk",
7824
+ async (req, res, ctx) => {
7825
+ expect(req.params.accountId).toEqual("some-account-id");
7826
+ expect(req.params.namespaceId).toEqual(expectedNamespaceId);
7827
+ const uploads = await req.json();
7828
+ if (assets) {
7829
+ expect(assets.length).toEqual(uploads.length);
7830
+ for (let i = 0; i < uploads.length; i++) {
7831
+ checkAssetUpload(assets[i], uploads[i]);
7832
+ }
7615
7833
  }
7616
- } else {
7834
+
7617
7835
  requests.push({ uploads });
7836
+ return res(ctx.json(createFetchResult([])));
7618
7837
  }
7619
- }
7838
+ )
7620
7839
  );
7621
7840
  return requests;
7622
7841
  }
@@ -7640,16 +7859,24 @@ function mockDeleteUnusedAssetsRequest(
7640
7859
  expectedNamespaceId: string,
7641
7860
  assets: string[]
7642
7861
  ) {
7643
- setMockResponse(
7644
- "/accounts/:accountId/storage/kv/namespaces/:namespaceId/bulk",
7645
- "DELETE",
7646
- ([_url, accountId, namespaceId], { body }) => {
7647
- expect(accountId).toEqual("some-account-id");
7648
- expect(namespaceId).toEqual(expectedNamespaceId);
7649
- const deletes = JSON.parse(body as string);
7650
- expect(assets).toEqual(deletes);
7651
- return null;
7652
- }
7862
+ msw.use(
7863
+ rest.delete(
7864
+ "*/accounts/:accountId/storage/kv/namespaces/:namespaceId/bulk",
7865
+ async (req, res, ctx) => {
7866
+ expect(req.params.accountId).toEqual("some-account-id");
7867
+ expect(req.params.namespaceId).toEqual(expectedNamespaceId);
7868
+ const deletes = await req.json();
7869
+ expect(assets).toEqual(deletes);
7870
+ return res.once(
7871
+ ctx.json({
7872
+ success: true,
7873
+ errors: [],
7874
+ messages: [],
7875
+ result: null,
7876
+ })
7877
+ );
7878
+ }
7879
+ )
7653
7880
  );
7654
7881
  }
7655
7882
 
@@ -7657,13 +7884,18 @@ type LegacyScriptInfo = { id: string; migration_tag?: string };
7657
7884
 
7658
7885
  function mockLegacyScriptData(options: { scripts: LegacyScriptInfo[] }) {
7659
7886
  const { scripts } = options;
7660
- setMockResponse(
7661
- "/accounts/:accountId/workers/scripts",
7662
- "GET",
7663
- ([_url, accountId]) => {
7664
- expect(accountId).toEqual("some-account-id");
7665
- return scripts;
7666
- }
7887
+ msw.use(
7888
+ rest.get("*/accounts/:accountId/workers/scripts", (req, res, ctx) => {
7889
+ expect(req.params.accountId).toEqual("some-account-id");
7890
+ return res.once(
7891
+ ctx.json({
7892
+ success: true,
7893
+ errors: [],
7894
+ messages: [],
7895
+ result: scripts,
7896
+ })
7897
+ );
7898
+ })
7667
7899
  );
7668
7900
  }
7669
7901
 
@@ -7677,74 +7909,140 @@ function mockServiceScriptData(options: {
7677
7909
  const { script } = options;
7678
7910
  if (options.env) {
7679
7911
  if (!script) {
7680
- setMockRawResponse(
7681
- "/accounts/:accountId/workers/services/:scriptName/environments/:envName",
7682
- "GET",
7683
- () => {
7684
- return createFetchResult(null, false, [
7685
- { code: 10092, message: "workers.api.error.environment_not_found" },
7686
- ]);
7687
- }
7912
+ msw.use(
7913
+ rest.get(
7914
+ "*/accounts/:accountId/workers/services/:scriptName/environments/:envName",
7915
+ (_, res, ctx) => {
7916
+ return res.once(
7917
+ ctx.json({
7918
+ success: false,
7919
+ errors: [
7920
+ {
7921
+ code: 10092,
7922
+ message: "workers.api.error.environment_not_found",
7923
+ },
7924
+ ],
7925
+ messages: [],
7926
+ result: null,
7927
+ })
7928
+ );
7929
+ }
7930
+ )
7688
7931
  );
7689
7932
  return;
7690
7933
  }
7691
- setMockResponse(
7692
- "/accounts/:accountId/workers/services/:scriptName/environments/:envName",
7693
- "GET",
7694
- ([_url, accountId, scriptName, envName]) => {
7695
- expect(accountId).toEqual("some-account-id");
7696
- expect(scriptName).toEqual(options.scriptName || "test-name");
7697
- expect(envName).toEqual(options.env);
7698
- return { script };
7699
- }
7934
+ msw.use(
7935
+ rest.get(
7936
+ "*/accounts/:accountId/workers/services/:scriptName/environments/:envName",
7937
+ (req, res, ctx) => {
7938
+ expect(req.params.accountId).toEqual("some-account-id");
7939
+ expect(req.params.scriptName).toEqual(
7940
+ options.scriptName || "test-name"
7941
+ );
7942
+ expect(req.params.envName).toEqual(options.env);
7943
+ return res.once(
7944
+ ctx.json({
7945
+ success: true,
7946
+ errors: [],
7947
+ messages: [],
7948
+ result: { script },
7949
+ })
7950
+ );
7951
+ }
7952
+ )
7700
7953
  );
7701
7954
  } else {
7702
7955
  if (!script) {
7703
- setMockRawResponse(
7704
- "/accounts/:accountId/workers/services/:scriptName",
7705
- "GET",
7706
- () => {
7707
- return createFetchResult(null, false, [
7708
- { code: 10090, message: "workers.api.error.service_not_found" },
7709
- ]);
7710
- }
7956
+ msw.use(
7957
+ rest.get(
7958
+ "*/accounts/:accountId/workers/services/:scriptName",
7959
+ (req, res, ctx) => {
7960
+ return res.once(
7961
+ ctx.json({
7962
+ success: false,
7963
+ errors: [
7964
+ {
7965
+ code: 10090,
7966
+ message: "workers.api.error.service_not_found",
7967
+ },
7968
+ ],
7969
+ messages: [],
7970
+ result: null,
7971
+ })
7972
+ );
7973
+ }
7974
+ )
7711
7975
  );
7712
7976
  return;
7713
7977
  }
7714
- setMockResponse(
7715
- "/accounts/:accountId/workers/services/:scriptName",
7716
- "GET",
7717
- ([_url, accountId, scriptName]) => {
7718
- expect(accountId).toEqual("some-account-id");
7719
- expect(scriptName).toEqual(options.scriptName || "test-name");
7720
- return { default_environment: { script } };
7721
- }
7978
+ msw.use(
7979
+ rest.get(
7980
+ "*/accounts/:accountId/workers/services/:scriptName",
7981
+ (req, res, ctx) => {
7982
+ expect(req.params.accountId).toEqual("some-account-id");
7983
+ expect(req.params.scriptName).toEqual(
7984
+ options.scriptName || "test-name"
7985
+ );
7986
+ return res.once(
7987
+ ctx.json({
7988
+ success: true,
7989
+ errors: [],
7990
+ messages: [],
7991
+ result: { default_environment: { script } },
7992
+ })
7993
+ );
7994
+ }
7995
+ )
7722
7996
  );
7723
7997
  }
7724
7998
  }
7725
7999
 
7726
8000
  function mockGetQueue(expectedQueueName: string) {
7727
8001
  const requests = { count: 0 };
7728
- setMockResponse(
7729
- `/accounts/:accountId/workers/queues/${expectedQueueName}`,
7730
- "GET",
7731
- ([_url, accountId]) => {
7732
- expect(accountId).toEqual("some-account-id");
7733
- requests.count += 1;
7734
- return { queue: expectedQueueName };
7735
- }
8002
+ msw.use(
8003
+ rest.get(
8004
+ `*/accounts/:accountId/workers/queues/${expectedQueueName}`,
8005
+ (req, res, ctx) => {
8006
+ expect(req.params.accountId).toEqual("some-account-id");
8007
+ requests.count += 1;
8008
+ return res(
8009
+ ctx.json({
8010
+ success: true,
8011
+ errors: [],
8012
+ messages: [],
8013
+ result: { queue: expectedQueueName },
8014
+ })
8015
+ );
8016
+ }
8017
+ )
7736
8018
  );
7737
8019
  return requests;
7738
8020
  }
7739
8021
 
7740
8022
  function mockGetQueueMissing(expectedQueueName: string) {
7741
8023
  const requests = { count: 0 };
7742
- setMockResponse(
7743
- `/accounts/:accountId/workers/queues/${expectedQueueName}`,
7744
- "GET",
7745
- ([_url, _accountId]) => {
7746
- throw { code: 11000 };
7747
- }
8024
+ msw.use(
8025
+ rest.get(
8026
+ `*/accounts/:accountId/workers/queues/${expectedQueueName}`,
8027
+ (req, res, ctx) => {
8028
+ requests.count += 1;
8029
+ expect(req.params.accountId).toEqual("some-account-id");
8030
+
8031
+ return res(
8032
+ ctx.json({
8033
+ success: false,
8034
+ errors: [
8035
+ {
8036
+ code: 11000,
8037
+ message: "workers.api.error.queue_not_found",
8038
+ },
8039
+ ],
8040
+ messages: [],
8041
+ result: null,
8042
+ })
8043
+ );
8044
+ }
8045
+ )
7748
8046
  );
7749
8047
  return requests;
7750
8048
  }
@@ -7755,15 +8053,65 @@ function mockPutQueueConsumer(
7755
8053
  expectedBody: PutConsumerBody
7756
8054
  ) {
7757
8055
  const requests = { count: 0 };
7758
- setMockResponse(
7759
- `/accounts/:accountId/workers/queues/${expectedQueueName}/consumers/${expectedConsumerName}`,
7760
- "PUT",
7761
- ([_url, accountId], { body }) => {
7762
- expect(accountId).toEqual("some-account-id");
7763
- expect(JSON.parse(body as string)).toEqual(expectedBody);
7764
- requests.count += 1;
7765
- return { queue: expectedQueueName };
7766
- }
8056
+ msw.use(
8057
+ rest.put(
8058
+ `*/accounts/:accountId/workers/queues/${expectedQueueName}/consumers/${expectedConsumerName}`,
8059
+ async (req, res, ctx) => {
8060
+ const body = await req.json();
8061
+ expect(req.params.accountId).toEqual("some-account-id");
8062
+ expect(body).toEqual(expectedBody);
8063
+ requests.count += 1;
8064
+ return res(
8065
+ ctx.json({
8066
+ success: true,
8067
+ errors: [],
8068
+ messages: [],
8069
+ result: { queue: expectedQueueName },
8070
+ })
8071
+ );
8072
+ }
8073
+ )
7767
8074
  );
7768
8075
  return requests;
7769
8076
  }
8077
+
8078
+ // MSW FormData & Blob polyfills to test FormData requests
8079
+ function mockFormDataToString(this: FormData) {
8080
+ const entries = [];
8081
+ for (const [key, value] of this.entries()) {
8082
+ if (value instanceof Blob) {
8083
+ const reader = new FileReaderSync();
8084
+ reader.readAsText(value);
8085
+ const result = reader.result;
8086
+ entries.push([key, result]);
8087
+ } else {
8088
+ entries.push([key, value]);
8089
+ }
8090
+ }
8091
+ return JSON.stringify({
8092
+ __formdata: entries,
8093
+ });
8094
+ }
8095
+
8096
+ async function mockFormDataFromString(this: MockedRequest): Promise<FormData> {
8097
+ const { __formdata } = await this.json();
8098
+ expect(__formdata).toBeInstanceOf(Array);
8099
+
8100
+ const form = new FormData();
8101
+ for (const [key, value] of __formdata) {
8102
+ form.set(key, value);
8103
+ }
8104
+ return form;
8105
+ }
8106
+
8107
+ // The following two functions workaround the fact that MSW does not yet support FormData in requests.
8108
+ // We use the fact that MSW relies upon `node-fetch` internally, which will call `toString()` on the FormData object,
8109
+ // rather than passing it through or serializing it as a proper FormData object.
8110
+ // The hack is to serialize FormData to a JSON string by overriding `FormData.toString()`.
8111
+ // And then to deserialize back to a FormData object by monkey-patching a `formData()` helper onto `MockedRequest`.
8112
+ FormData.prototype.toString = mockFormDataToString;
8113
+ export interface RestRequestWithFormData extends MockedRequest, RestRequest {
8114
+ formData(): Promise<FormData>;
8115
+ }
8116
+ (MockedRequest.prototype as RestRequestWithFormData).formData =
8117
+ mockFormDataFromString;