wrangler 2.8.0 → 2.9.0

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 (95) hide show
  1. package/package.json +1 -1
  2. package/src/__tests__/d1/d1.test.ts +24 -62
  3. package/src/__tests__/d1/migrate.test.ts +48 -0
  4. package/src/__tests__/deployments.test.ts +4 -4
  5. package/src/__tests__/dev.test.tsx +5 -4
  6. package/src/__tests__/helpers/msw/handlers/deployments.ts +10 -18
  7. package/src/__tests__/helpers/msw/handlers/namespaces.ts +18 -41
  8. package/src/__tests__/helpers/msw/handlers/r2.ts +14 -34
  9. package/src/__tests__/helpers/msw/handlers/script.ts +9 -28
  10. package/src/__tests__/helpers/msw/handlers/user.ts +13 -24
  11. package/src/__tests__/helpers/msw/handlers/zones.ts +6 -8
  12. package/src/__tests__/index.test.ts +35 -28
  13. package/src/__tests__/kv.test.ts +55 -44
  14. package/src/__tests__/pages.test.ts +61 -57
  15. package/src/__tests__/parse.test.ts +106 -0
  16. package/src/__tests__/publish.test.ts +126 -0
  17. package/src/__tests__/pubsub.test.ts +15 -12
  18. package/src/__tests__/queues.test.ts +35 -28
  19. package/src/__tests__/r2.test.ts +36 -55
  20. package/src/__tests__/tail.test.ts +6 -18
  21. package/src/__tests__/tsconfig.tsbuildinfo +1 -1
  22. package/src/__tests__/user.test.ts +0 -1
  23. package/src/__tests__/whoami.test.tsx +6 -17
  24. package/src/__tests__/worker-namespace.test.ts +81 -68
  25. package/src/api/dev.ts +80 -11
  26. package/src/api/index.ts +1 -0
  27. package/src/api/pages/index.ts +5 -0
  28. package/src/api/pages/publish.tsx +324 -0
  29. package/src/bundle.ts +63 -11
  30. package/src/cli.ts +2 -2
  31. package/src/config/config.ts +7 -0
  32. package/src/config/environment.ts +12 -10
  33. package/src/config/index.ts +24 -20
  34. package/src/d1/backups.tsx +20 -24
  35. package/src/d1/create.tsx +6 -5
  36. package/src/d1/delete.ts +7 -10
  37. package/src/d1/execute.tsx +82 -84
  38. package/src/d1/index.ts +5 -6
  39. package/src/d1/list.tsx +21 -9
  40. package/src/d1/migrations/apply.tsx +7 -5
  41. package/src/d1/migrations/create.tsx +7 -10
  42. package/src/d1/migrations/list.tsx +7 -5
  43. package/src/d1/migrations/options.ts +2 -2
  44. package/src/d1/options.ts +3 -3
  45. package/src/d1/utils.ts +1 -1
  46. package/src/delete.ts +5 -8
  47. package/src/deployments.ts +16 -6
  48. package/src/deprecated/index.ts +7 -8
  49. package/src/dev/local.tsx +1 -10
  50. package/src/dev/start-server.ts +5 -10
  51. package/src/dev/use-esbuild.ts +1 -0
  52. package/src/dev.tsx +42 -80
  53. package/src/dispatch-namespace.ts +20 -16
  54. package/src/docs/index.ts +7 -8
  55. package/src/entry.ts +1 -2
  56. package/src/generate/index.ts +5 -7
  57. package/src/index.ts +23 -22
  58. package/src/init.ts +5 -7
  59. package/src/kv/index.ts +15 -17
  60. package/src/metrics/send-event.ts +2 -1
  61. package/src/pages/build.ts +9 -127
  62. package/src/pages/buildFunctions.ts +129 -0
  63. package/src/pages/deployment-tails.ts +7 -10
  64. package/src/pages/deployments.tsx +6 -4
  65. package/src/pages/dev.ts +27 -19
  66. package/src/pages/functions/buildPlugin.ts +1 -0
  67. package/src/pages/functions/buildWorker.ts +8 -2
  68. package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
  69. package/src/pages/functions.ts +8 -4
  70. package/src/pages/index.ts +3 -3
  71. package/src/pages/projects.tsx +7 -12
  72. package/src/pages/publish.tsx +15 -239
  73. package/src/pages/types.ts +5 -0
  74. package/src/pages/upload.tsx +6 -4
  75. package/src/parse.ts +23 -1
  76. package/src/publish/index.ts +19 -15
  77. package/src/publish/publish.ts +3 -2
  78. package/src/pubsub/pubsub-commands.ts +18 -19
  79. package/src/queues/cli/commands/consumer/add.ts +18 -24
  80. package/src/queues/cli/commands/consumer/index.ts +3 -6
  81. package/src/queues/cli/commands/consumer/remove.ts +11 -18
  82. package/src/queues/cli/commands/create.ts +8 -8
  83. package/src/queues/cli/commands/delete.ts +8 -8
  84. package/src/queues/cli/commands/index.ts +3 -4
  85. package/src/queues/cli/commands/list.ts +8 -8
  86. package/src/r2/index.ts +28 -28
  87. package/src/secret/index.ts +9 -14
  88. package/src/tail/index.ts +6 -8
  89. package/src/yargs-types.ts +18 -5
  90. package/templates/checked-fetch.js +9 -1
  91. package/templates/d1-beta-facade.js +1 -1
  92. package/templates/middleware/loader-modules.ts +2 -0
  93. package/templates/tsconfig.tsbuildinfo +1 -1
  94. package/wrangler-dist/cli.d.ts +132 -10
  95. package/wrangler-dist/cli.js +2474 -1635
@@ -56,10 +56,11 @@ describe("wrangler", () => {
56
56
  wrangler deployments 🚢 Displays the 10 most recent deployments for a worker
57
57
 
58
58
  Flags:
59
- -c, --config Path to .toml configuration file [string]
60
- -e, --env Environment to use for operations and .env files [string]
61
- -h, --help Show help [boolean]
62
- -v, --version Show version number [boolean]"
59
+ -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
60
+ -c, --config Path to .toml configuration file [string]
61
+ -e, --env Environment to use for operations and .env files [string]
62
+ -h, --help Show help [boolean]
63
+ -v, --version Show version number [boolean]"
63
64
  `);
64
65
 
65
66
  expect(std.err).toMatchInlineSnapshot(`""`);
@@ -104,10 +105,11 @@ describe("wrangler", () => {
104
105
  wrangler deployments 🚢 Displays the 10 most recent deployments for a worker
105
106
 
106
107
  Flags:
107
- -c, --config Path to .toml configuration file [string]
108
- -e, --env Environment to use for operations and .env files [string]
109
- -h, --help Show help [boolean]
110
- -v, --version Show version number [boolean]"
108
+ -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
109
+ -c, --config Path to .toml configuration file [string]
110
+ -e, --env Environment to use for operations and .env files [string]
111
+ -h, --help Show help [boolean]
112
+ -v, --version Show version number [boolean]"
111
113
  `);
112
114
  expect(std.err).toMatchInlineSnapshot(`
113
115
  "X [ERROR] Unknown argument: invalid-command
@@ -151,10 +153,11 @@ describe("wrangler", () => {
151
153
  wrangler secret list List all secrets for a Worker
152
154
 
153
155
  Flags:
154
- -c, --config Path to .toml configuration file [string]
155
- -e, --env Environment to use for operations and .env files [string]
156
- -h, --help Show help [boolean]
157
- -v, --version Show version number [boolean]"
156
+ -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
157
+ -c, --config Path to .toml configuration file [string]
158
+ -e, --env Environment to use for operations and .env files [string]
159
+ -h, --help Show help [boolean]
160
+ -v, --version Show version number [boolean]"
158
161
  `);
159
162
  });
160
163
 
@@ -172,10 +175,11 @@ describe("wrangler", () => {
172
175
  wrangler kv:namespace delete Deletes a given namespace.
173
176
 
174
177
  Flags:
175
- -c, --config Path to .toml configuration file [string]
176
- -e, --env Environment to use for operations and .env files [string]
177
- -h, --help Show help [boolean]
178
- -v, --version Show version number [boolean]"
178
+ -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
179
+ -c, --config Path to .toml configuration file [string]
180
+ -e, --env Environment to use for operations and .env files [string]
181
+ -h, --help Show help [boolean]
182
+ -v, --version Show version number [boolean]"
179
183
  `);
180
184
  });
181
185
 
@@ -194,10 +198,11 @@ describe("wrangler", () => {
194
198
  wrangler kv:key delete <key> Removes a single key value pair from the given namespace.
195
199
 
196
200
  Flags:
197
- -c, --config Path to .toml configuration file [string]
198
- -e, --env Environment to use for operations and .env files [string]
199
- -h, --help Show help [boolean]
200
- -v, --version Show version number [boolean]"
201
+ -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
202
+ -c, --config Path to .toml configuration file [string]
203
+ -e, --env Environment to use for operations and .env files [string]
204
+ -h, --help Show help [boolean]
205
+ -v, --version Show version number [boolean]"
201
206
  `);
202
207
  });
203
208
 
@@ -214,10 +219,11 @@ describe("wrangler", () => {
214
219
  wrangler kv:bulk delete <filename> Delete multiple key-value pairs from a namespace
215
220
 
216
221
  Flags:
217
- -c, --config Path to .toml configuration file [string]
218
- -e, --env Environment to use for operations and .env files [string]
219
- -h, --help Show help [boolean]
220
- -v, --version Show version number [boolean]"
222
+ -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
223
+ -c, --config Path to .toml configuration file [string]
224
+ -e, --env Environment to use for operations and .env files [string]
225
+ -h, --help Show help [boolean]
226
+ -v, --version Show version number [boolean]"
221
227
  `);
222
228
  });
223
229
 
@@ -234,10 +240,11 @@ describe("wrangler", () => {
234
240
  wrangler r2 bucket Manage R2 buckets
235
241
 
236
242
  Flags:
237
- -c, --config Path to .toml configuration file [string]
238
- -e, --env Environment to use for operations and .env files [string]
239
- -h, --help Show help [boolean]
240
- -v, --version Show version number [boolean]"
243
+ -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
244
+ -c, --config Path to .toml configuration file [string]
245
+ -e, --env Environment to use for operations and .env files [string]
246
+ -h, --help Show help [boolean]
247
+ -v, --version Show version number [boolean]"
241
248
  `);
242
249
  });
243
250
  });
@@ -63,10 +63,11 @@ describe("wrangler", () => {
63
63
  namespace The name of the new namespace [string] [required]
64
64
 
65
65
  Flags:
66
- -c, --config Path to .toml configuration file [string]
67
- -e, --env Environment to use for operations and .env files [string]
68
- -h, --help Show help [boolean]
69
- -v, --version Show version number [boolean]
66
+ -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
67
+ -c, --config Path to .toml configuration file [string]
68
+ -e, --env Environment to use for operations and .env files [string]
69
+ -h, --help Show help [boolean]
70
+ -v, --version Show version number [boolean]
70
71
 
71
72
  Options:
72
73
  --preview Interact with a preview namespace [boolean]"
@@ -94,10 +95,11 @@ describe("wrangler", () => {
94
95
  namespace The name of the new namespace [string] [required]
95
96
 
96
97
  Flags:
97
- -c, --config Path to .toml configuration file [string]
98
- -e, --env Environment to use for operations and .env files [string]
99
- -h, --help Show help [boolean]
100
- -v, --version Show version number [boolean]
98
+ -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
99
+ -c, --config Path to .toml configuration file [string]
100
+ -e, --env Environment to use for operations and .env files [string]
101
+ -h, --help Show help [boolean]
102
+ -v, --version Show version number [boolean]
101
103
 
102
104
  Options:
103
105
  --preview Interact with a preview namespace [boolean]"
@@ -126,10 +128,11 @@ describe("wrangler", () => {
126
128
  namespace The name of the new namespace [string] [required]
127
129
 
128
130
  Flags:
129
- -c, --config Path to .toml configuration file [string]
130
- -e, --env Environment to use for operations and .env files [string]
131
- -h, --help Show help [boolean]
132
- -v, --version Show version number [boolean]
131
+ -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
132
+ -c, --config Path to .toml configuration file [string]
133
+ -e, --env Environment to use for operations and .env files [string]
134
+ -h, --help Show help [boolean]
135
+ -v, --version Show version number [boolean]
133
136
 
134
137
  Options:
135
138
  --preview Interact with a preview namespace [boolean]"
@@ -552,10 +555,11 @@ describe("wrangler", () => {
552
555
  value The value to write [string]
553
556
 
554
557
  Flags:
555
- -c, --config Path to .toml configuration file [string]
556
- -e, --env Environment to use for operations and .env files [string]
557
- -h, --help Show help [boolean]
558
- -v, --version Show version number [boolean]
558
+ -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
559
+ -c, --config Path to .toml configuration file [string]
560
+ -e, --env Environment to use for operations and .env files [string]
561
+ -h, --help Show help [boolean]
562
+ -v, --version Show version number [boolean]
559
563
 
560
564
  Options:
561
565
  --binding The binding of the namespace to write to [string]
@@ -591,10 +595,11 @@ describe("wrangler", () => {
591
595
  value The value to write [string]
592
596
 
593
597
  Flags:
594
- -c, --config Path to .toml configuration file [string]
595
- -e, --env Environment to use for operations and .env files [string]
596
- -h, --help Show help [boolean]
597
- -v, --version Show version number [boolean]
598
+ -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
599
+ -c, --config Path to .toml configuration file [string]
600
+ -e, --env Environment to use for operations and .env files [string]
601
+ -h, --help Show help [boolean]
602
+ -v, --version Show version number [boolean]
598
603
 
599
604
  Options:
600
605
  --binding The binding of the namespace to write to [string]
@@ -630,10 +635,11 @@ describe("wrangler", () => {
630
635
  value The value to write [string]
631
636
 
632
637
  Flags:
633
- -c, --config Path to .toml configuration file [string]
634
- -e, --env Environment to use for operations and .env files [string]
635
- -h, --help Show help [boolean]
636
- -v, --version Show version number [boolean]
638
+ -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
639
+ -c, --config Path to .toml configuration file [string]
640
+ -e, --env Environment to use for operations and .env files [string]
641
+ -h, --help Show help [boolean]
642
+ -v, --version Show version number [boolean]
637
643
 
638
644
  Options:
639
645
  --binding The binding of the namespace to write to [string]
@@ -669,10 +675,11 @@ describe("wrangler", () => {
669
675
  value The value to write [string]
670
676
 
671
677
  Flags:
672
- -c, --config Path to .toml configuration file [string]
673
- -e, --env Environment to use for operations and .env files [string]
674
- -h, --help Show help [boolean]
675
- -v, --version Show version number [boolean]
678
+ -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
679
+ -c, --config Path to .toml configuration file [string]
680
+ -e, --env Environment to use for operations and .env files [string]
681
+ -h, --help Show help [boolean]
682
+ -v, --version Show version number [boolean]
676
683
 
677
684
  Options:
678
685
  --binding The binding of the namespace to write to [string]
@@ -708,10 +715,11 @@ describe("wrangler", () => {
708
715
  value The value to write [string]
709
716
 
710
717
  Flags:
711
- -c, --config Path to .toml configuration file [string]
712
- -e, --env Environment to use for operations and .env files [string]
713
- -h, --help Show help [boolean]
714
- -v, --version Show version number [boolean]
718
+ -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
719
+ -c, --config Path to .toml configuration file [string]
720
+ -e, --env Environment to use for operations and .env files [string]
721
+ -h, --help Show help [boolean]
722
+ -v, --version Show version number [boolean]
715
723
 
716
724
  Options:
717
725
  --binding The binding of the namespace to write to [string]
@@ -1083,10 +1091,11 @@ describe("wrangler", () => {
1083
1091
  key The key value to get. [string] [required]
1084
1092
 
1085
1093
  Flags:
1086
- -c, --config Path to .toml configuration file [string]
1087
- -e, --env Environment to use for operations and .env files [string]
1088
- -h, --help Show help [boolean]
1089
- -v, --version Show version number [boolean]
1094
+ -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
1095
+ -c, --config Path to .toml configuration file [string]
1096
+ -e, --env Environment to use for operations and .env files [string]
1097
+ -h, --help Show help [boolean]
1098
+ -v, --version Show version number [boolean]
1090
1099
 
1091
1100
  Options:
1092
1101
  --binding The name of the namespace to get from [string]
@@ -1117,10 +1126,11 @@ describe("wrangler", () => {
1117
1126
  key The key value to get. [string] [required]
1118
1127
 
1119
1128
  Flags:
1120
- -c, --config Path to .toml configuration file [string]
1121
- -e, --env Environment to use for operations and .env files [string]
1122
- -h, --help Show help [boolean]
1123
- -v, --version Show version number [boolean]
1129
+ -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
1130
+ -c, --config Path to .toml configuration file [string]
1131
+ -e, --env Environment to use for operations and .env files [string]
1132
+ -h, --help Show help [boolean]
1133
+ -v, --version Show version number [boolean]
1124
1134
 
1125
1135
  Options:
1126
1136
  --binding The name of the namespace to get from [string]
@@ -1152,10 +1162,11 @@ describe("wrangler", () => {
1152
1162
  key The key value to get. [string] [required]
1153
1163
 
1154
1164
  Flags:
1155
- -c, --config Path to .toml configuration file [string]
1156
- -e, --env Environment to use for operations and .env files [string]
1157
- -h, --help Show help [boolean]
1158
- -v, --version Show version number [boolean]
1165
+ -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
1166
+ -c, --config Path to .toml configuration file [string]
1167
+ -e, --env Environment to use for operations and .env files [string]
1168
+ -h, --help Show help [boolean]
1169
+ -v, --version Show version number [boolean]
1159
1170
 
1160
1171
  Options:
1161
1172
  --binding The name of the namespace to get from [string]
@@ -69,10 +69,11 @@ describe("pages", () => {
69
69
  wrangler pages publish [directory] 🆙 Publish a directory of static assets as a Pages deployment
70
70
 
71
71
  Flags:
72
- -c, --config Path to .toml configuration file [string]
73
- -e, --env Environment to use for operations and .env files [string]
74
- -h, --help Show help [boolean]
75
- -v, --version Show version number [boolean]
72
+ -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
73
+ -c, --config Path to .toml configuration file [string]
74
+ -e, --env Environment to use for operations and .env files [string]
75
+ -h, --help Show help [boolean]
76
+ -v, --version Show version number [boolean]
76
77
 
77
78
  🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose"
78
79
  `);
@@ -340,9 +341,10 @@ describe("pages", () => {
340
341
  directory The directory of static files to upload [string]
341
342
 
342
343
  Flags:
343
- -e, --env Environment to use for operations and .env files [string]
344
- -h, --help Show help [boolean]
345
- -v, --version Show version number [boolean]
344
+ -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
345
+ -e, --env Environment to use for operations and .env files [string]
346
+ -h, --help Show help [boolean]
347
+ -v, --version Show version number [boolean]
346
348
 
347
349
  Options:
348
350
  --project-name The name of the project you want to deploy to [string]
@@ -1468,6 +1470,8 @@ describe("pages", () => {
1468
1470
  expect(std.err).toMatchInlineSnapshot('""');
1469
1471
  });
1470
1472
 
1473
+ const workerHasD1Shim = (contents: string) => contents.includes("D1_ERROR");
1474
+
1471
1475
  it("should upload an Advanced Mode project", async () => {
1472
1476
  // set up the directory of static files to upload.
1473
1477
  mkdirSync("public");
@@ -1480,6 +1484,7 @@ describe("pages", () => {
1480
1484
  export default {
1481
1485
  async fetch(request, env) {
1482
1486
  const url = new URL(request.url);
1487
+ console.log("SOMETHING FROM WITHIN THE WORKER");
1483
1488
  return url.pathname.startsWith('/api/') ? new Response('Ok') : env.ASSETS.fetch(request);
1484
1489
  }
1485
1490
  };
@@ -1555,16 +1560,11 @@ describe("pages", () => {
1555
1560
  }
1556
1561
  `);
1557
1562
 
1558
- expect(customWorkerJS).toMatchInlineSnapshot(`
1559
- "
1560
- export default {
1561
- async fetch(request, env) {
1562
- const url = new URL(request.url);
1563
- return url.pathname.startsWith('/api/') ? new Response('Ok') : env.ASSETS.fetch(request);
1564
- }
1565
- };
1566
- "
1567
- `);
1563
+ expect(workerHasD1Shim(customWorkerJS as string)).toBeTruthy();
1564
+ expect(customWorkerJS).toContain(
1565
+ `console.log("SOMETHING FROM WITHIN THE WORKER");`
1566
+ );
1567
+
1568
1568
  return res.once(
1569
1569
  ctx.status(200),
1570
1570
  ctx.json({
@@ -1590,15 +1590,22 @@ describe("pages", () => {
1590
1590
  errors: [],
1591
1591
  messages: [],
1592
1592
  result: {
1593
- deployment_configs: { production: {}, preview: {} },
1594
- },
1593
+ deployment_configs: {
1594
+ production: {
1595
+ d1_databases: { MY_D1_DB: { id: "fake-db" } },
1596
+ },
1597
+ preview: {
1598
+ d1_databases: { MY_D1_DB: { id: "fake-db" } },
1599
+ },
1600
+ },
1601
+ } as Partial<Project>,
1595
1602
  })
1596
1603
  );
1597
1604
  }
1598
1605
  )
1599
1606
  );
1600
1607
 
1601
- await runWrangler("pages publish public --project-name=foo");
1608
+ await runWrangler("pages publish public --project-name=foo --bundle");
1602
1609
 
1603
1610
  expect(std.out).toMatchInlineSnapshot(`
1604
1611
  "✨ Success! Uploaded 1 files (TIMINGS)
@@ -2543,19 +2550,20 @@ and that at least one include rule is provided.
2543
2550
  );
2544
2551
 
2545
2552
  await runWrangler("pages project upload .");
2546
-
2547
2553
  expect(requests.length).toBe(3);
2548
2554
 
2549
- const resolvedRequests = await Promise.all(
2550
- requests.map(async (req) => await req.json<UploadPayloadFile>())
2551
- );
2552
-
2553
- const sortedRequests = resolvedRequests.sort((a, b) => {
2554
- const aKey = a.key as string;
2555
- const bKey = b.key as string;
2555
+ const resolvedRequests = (
2556
+ await Promise.all(
2557
+ requests.map(async (req) => await req.json<UploadPayloadFile[]>())
2558
+ )
2559
+ ).flat();
2556
2560
 
2557
- return aKey?.localeCompare(bKey);
2558
- });
2561
+ const requestMap = resolvedRequests.reduce<{
2562
+ [key: string]: UploadPayloadFile;
2563
+ }>(
2564
+ (requestMap, req) => Object.assign(requestMap, { [req.key]: req }),
2565
+ {}
2566
+ );
2559
2567
 
2560
2568
  for (const req of requests) {
2561
2569
  expect(req.headers.get("Authorization")).toBe(
@@ -2563,38 +2571,34 @@ and that at least one include rule is provided.
2563
2571
  );
2564
2572
  }
2565
2573
 
2566
- expect(sortedRequests[0]).toMatchObject([
2567
- {
2568
- base64: true,
2569
- key: "95dedb64e6d4940fc2e0f11f711cc2f4",
2570
- metadata: {
2571
- contentType: "application/octet-stream",
2572
- },
2573
- value: "aGVhZGVyc2ZpbGU=",
2574
+ expect(Object.keys(requestMap).length).toBe(3);
2575
+
2576
+ expect(requestMap["95dedb64e6d4940fc2e0f11f711cc2f4"]).toMatchObject({
2577
+ base64: true,
2578
+ key: "95dedb64e6d4940fc2e0f11f711cc2f4",
2579
+ metadata: {
2580
+ contentType: "application/octet-stream",
2574
2581
  },
2575
- ]);
2582
+ value: "aGVhZGVyc2ZpbGU=",
2583
+ });
2576
2584
 
2577
- expect(sortedRequests[1]).toMatchObject([
2578
- {
2579
- base64: true,
2580
- key: "2082190357cfd3617ccfe04f340c6247",
2581
- metadata: {
2582
- contentType: "image/png",
2583
- },
2584
- value: "Zm9vYmFy",
2585
+ expect(requestMap["2082190357cfd3617ccfe04f340c6247"]).toMatchObject({
2586
+ base64: true,
2587
+ key: "2082190357cfd3617ccfe04f340c6247",
2588
+ metadata: {
2589
+ contentType: "image/png",
2585
2590
  },
2586
- ]);
2591
+ value: "Zm9vYmFy",
2592
+ });
2587
2593
 
2588
- expect(sortedRequests[2]).toMatchObject([
2589
- {
2590
- base64: true,
2591
- key: "09a79777abda8ccc8bdd51dd3ff8e9e9",
2592
- metadata: {
2593
- contentType: "application/javascript",
2594
- },
2595
- value: "ZnVuYw==",
2594
+ expect(requestMap["09a79777abda8ccc8bdd51dd3ff8e9e9"]).toMatchObject({
2595
+ base64: true,
2596
+ key: "09a79777abda8ccc8bdd51dd3ff8e9e9",
2597
+ metadata: {
2598
+ contentType: "application/javascript",
2596
2599
  },
2597
- ]);
2600
+ value: "ZnVuYw==",
2601
+ });
2598
2602
 
2599
2603
  expect(std.out).toMatchInlineSnapshot(`
2600
2604
  "✨ Success! Uploaded 3 files (TIMINGS)
@@ -4,6 +4,7 @@ import {
4
4
  indexLocation,
5
5
  parseJSON,
6
6
  parseTOML,
7
+ parseJSONC,
7
8
  } from "../parse";
8
9
  import type { Message } from "../parse";
9
10
 
@@ -257,7 +258,112 @@ describe("parseJSON", () => {
257
258
  }
258
259
  });
259
260
  });
261
+ describe("parseJSONC", () => {
262
+ it("should parse jsonc that is empty", () => {
263
+ expect(parseJSONC("{}")).toStrictEqual({});
264
+ });
265
+
266
+ it("should parse jsonc with basic values", () => {
267
+ expect(
268
+ parseJSONC(`
269
+ {
270
+ "name" : "basic",
271
+ "version": 1
272
+ }`)
273
+ ).toStrictEqual({
274
+ name: "basic",
275
+ version: 1,
276
+ });
277
+ });
278
+
279
+ it("should parse jsonc with complex values", () => {
280
+ expect(
281
+ parseJSONC(
282
+ `{
283
+ "name":"complex",
284
+ "spec":{
285
+ "uptime":[1,2.5,3],
286
+ "ok":true
287
+ }
288
+ }`
289
+ )
290
+ ).toStrictEqual({
291
+ name: "complex",
292
+ spec: {
293
+ uptime: [1, 2.5, 3],
294
+ ok: true,
295
+ },
296
+ });
297
+ });
260
298
 
299
+ it("should parse jsonc with comments", () => {
300
+ expect(
301
+ parseJSONC(
302
+ `{
303
+ // Comment A
304
+ "name":"complex",
305
+ "spec":{
306
+ // Nested comment
307
+ "uptime":[1,2.5,3],
308
+ "ok":true
309
+ }
310
+ }`
311
+ )
312
+ ).toStrictEqual({
313
+ name: "complex",
314
+ spec: {
315
+ uptime: [1, 2.5, 3],
316
+ ok: true,
317
+ },
318
+ });
319
+ });
320
+
321
+ it("should fail to parse jsonc with invalid string", () => {
322
+ try {
323
+ parseJSONC(`\n{\n"version" "1\n}\n`);
324
+ fail("parseJSONC did not throw");
325
+ } catch (err) {
326
+ expect({ ...(err as Error) }).toStrictEqual({
327
+ name: "ParseError",
328
+ text: "UnexpectedEndOfString",
329
+ kind: "error",
330
+ location: {
331
+ length: 2,
332
+ line: 3,
333
+ column: 10,
334
+ lineText: '"version" "1',
335
+ file: undefined,
336
+ fileText: `\n{\n"version" "1\n}\n`,
337
+ },
338
+ notes: [],
339
+ });
340
+ }
341
+ });
342
+
343
+ it("should fail to parse jsonc with invalid number", () => {
344
+ const file = "config.json",
345
+ fileText = `{\n\t"a":{\n\t\t"b":{\n\t\t\t"c":[012345]\n}\n}\n}`;
346
+ try {
347
+ parseJSONC(fileText, file);
348
+ fail("parseJSONC did not throw");
349
+ } catch (err) {
350
+ expect({ ...(err as Error) }).toStrictEqual({
351
+ name: "ParseError",
352
+ text: "CommaExpected",
353
+ kind: "error",
354
+ location: {
355
+ file,
356
+ fileText,
357
+ length: 5,
358
+ line: 4,
359
+ column: 9,
360
+ lineText: `\t\t\t"c":[012345]`,
361
+ },
362
+ notes: [],
363
+ });
364
+ }
365
+ });
366
+ });
261
367
  describe("indexLocation", () => {
262
368
  it("should calculate location from one-line input", () => {
263
369
  const fileText = "";