wrangler 0.0.0-e6e1daba → 0.0.0-e7cf0caa

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/bin/wrangler.js +1 -1
  2. package/miniflare-dist/index.mjs +1 -1
  3. package/package.json +14 -9
  4. package/src/__tests__/api-devregistry.test.ts +121 -0
  5. package/src/__tests__/api.test.ts +27 -5
  6. package/src/__tests__/configuration.test.ts +294 -18
  7. package/src/__tests__/d1/execute.test.ts +3 -1
  8. package/src/__tests__/d1/migrate.test.ts +2 -0
  9. package/src/__tests__/delete.test.ts +6 -0
  10. package/src/__tests__/deployments.test.ts +335 -95
  11. package/src/__tests__/dev.test.tsx +87 -57
  12. package/src/__tests__/generate.test.ts +3 -4
  13. package/src/__tests__/helpers/mock-console.ts +6 -0
  14. package/src/__tests__/helpers/msw/handlers/deployments.ts +70 -3
  15. package/src/__tests__/helpers/msw/index.ts +4 -2
  16. package/src/__tests__/helpers/worker-scripts/parent-worker.js +4 -1
  17. package/src/__tests__/index.test.ts +10 -4
  18. package/src/__tests__/init.test.ts +136 -104
  19. package/src/__tests__/jest.setup.ts +4 -0
  20. package/src/__tests__/kv.test.ts +9 -9
  21. package/src/__tests__/logger.test.ts +68 -2
  22. package/src/__tests__/middleware.scheduled.test.ts +2 -2
  23. package/src/__tests__/middleware.test.ts +4 -3
  24. package/src/__tests__/mtls-certificates.test.ts +5 -2
  25. package/src/__tests__/pages/deployment-list.test.ts +2 -0
  26. package/src/__tests__/pages/functions-build.test.ts +91 -41
  27. package/src/__tests__/pages/project-list.test.ts +2 -0
  28. package/src/__tests__/pages/project-upload.test.ts +43 -24
  29. package/src/__tests__/pages/publish.test.ts +267 -148
  30. package/src/__tests__/publish.test.ts +420 -164
  31. package/src/__tests__/pubsub.test.ts +3 -0
  32. package/src/__tests__/queues.test.ts +5 -2
  33. package/src/__tests__/test-old-node-version.js +3 -3
  34. package/src/__tests__/traverse-module-graph.test.ts +220 -0
  35. package/src/__tests__/tsconfig.tsbuildinfo +1 -1
  36. package/src/__tests__/type-generation.test.ts +1 -0
  37. package/src/__tests__/user.test.ts +1 -1
  38. package/src/__tests__/worker-namespace.test.ts +1 -0
  39. package/src/api/dev.ts +10 -22
  40. package/src/api/pages/create-worker-bundle-contents.ts +1 -0
  41. package/src/api/pages/publish.tsx +38 -51
  42. package/src/bundle.ts +44 -13
  43. package/src/config/environment.ts +36 -4
  44. package/src/config/index.ts +30 -2
  45. package/src/config/validation-helpers.ts +1 -1
  46. package/src/config/validation.ts +149 -5
  47. package/src/create-worker-upload-form.ts +28 -3
  48. package/src/d1/backups.tsx +15 -11
  49. package/src/d1/create.tsx +20 -16
  50. package/src/d1/execute.tsx +22 -19
  51. package/src/d1/list.tsx +2 -2
  52. package/src/d1/migrations/apply.tsx +35 -29
  53. package/src/d1/migrations/create.tsx +15 -12
  54. package/src/d1/migrations/list.tsx +10 -7
  55. package/src/deployments.ts +260 -8
  56. package/src/dev/dev.tsx +4 -4
  57. package/src/dev/local.tsx +14 -16
  58. package/src/dev/start-server.ts +12 -16
  59. package/src/dev/use-esbuild.ts +11 -13
  60. package/src/dev/validate-dev-props.ts +9 -0
  61. package/src/dev-registry.ts +2 -1
  62. package/src/dev.tsx +28 -13
  63. package/src/entry.ts +18 -8
  64. package/src/generate/index.ts +2 -2
  65. package/src/index.ts +76 -23
  66. package/src/init.ts +144 -134
  67. package/src/logger.ts +18 -3
  68. package/src/metrics/send-event.ts +2 -1
  69. package/src/miniflare-cli/index.ts +1 -1
  70. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -1
  71. package/src/module-collection.ts +91 -25
  72. package/src/pages/build.ts +277 -99
  73. package/src/pages/buildFunctions.ts +20 -10
  74. package/src/pages/deployments.tsx +3 -5
  75. package/src/pages/dev.ts +21 -21
  76. package/src/pages/errors.ts +1 -0
  77. package/src/pages/functions/buildPlugin.ts +57 -34
  78. package/src/pages/functions/buildWorker.ts +34 -31
  79. package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
  80. package/src/pages/projects.tsx +2 -5
  81. package/src/pages/publish.tsx +1 -10
  82. package/src/pages/upload.tsx +29 -9
  83. package/src/paths.ts +1 -1
  84. package/src/publish/index.ts +1 -1
  85. package/src/publish/publish.ts +29 -34
  86. package/src/queues/cli/commands/consumer/add.ts +6 -0
  87. package/src/queues/client.ts +1 -0
  88. package/src/secret/index.ts +2 -1
  89. package/src/traverse-module-graph.ts +53 -0
  90. package/src/type-generation.ts +1 -1
  91. package/src/user/user.ts +1 -1
  92. package/src/utils/render.ts +93 -0
  93. package/src/worker.ts +18 -1
  94. package/templates/d1-beta-facade.js +5 -2
  95. package/templates/gitignore +1 -0
  96. package/templates/middleware/middleware-miniflare3-json-error.ts +17 -5
  97. package/templates/tsconfig.init.json +1 -2
  98. package/templates/tsconfig.tsbuildinfo +1 -1
  99. package/wrangler-dist/cli.d.ts +33 -13
  100. package/wrangler-dist/cli.js +20732 -19984
  101. package/src/__tests__/api-devregistry.test.js +0 -64
@@ -51,7 +51,7 @@ describe("workers change behaviour with middleware with wrangler dev", () => {
51
51
  export default {
52
52
  middleware: [middleware],
53
53
  scheduled(controller, env, ctx) {
54
- console.log("Scheduled worker called");
54
+ // Scheduled worker called
55
55
  }
56
56
  }
57
57
  `;
@@ -178,7 +178,7 @@ describe("workers change behaviour with middleware with wrangler dev", () => {
178
178
  addMiddleware(middleware);
179
179
 
180
180
  addEventListener("scheduled", (event) => {
181
- console.log("Scheduled worker called");
181
+ // Scheduled worker called
182
182
  });
183
183
  `;
184
184
 
@@ -750,6 +750,7 @@ describe("unchanged functionality when wrapping with middleware", () => {
750
750
  });
751
751
 
752
752
  describe("multiple middleware", () => {
753
+ runInTempDir();
753
754
  it("should respond correctly with D1 databases, scheduled testing, and formatted dev errors", async () => {
754
755
  // Kitchen sink test to check interaction between multiple middlewares
755
756
  const scriptContent = `
@@ -769,7 +770,7 @@ describe("multiple middleware", () => {
769
770
  const stmt = await env.DB.prepare("INSERT INTO test (id, value) VALUES (?, ?)");
770
771
  await stmt.bind(1, "one").run();
771
772
  }
772
- }
773
+ }
773
774
  `;
774
775
  fs.writeFileSync("index.js", scriptContent);
775
776
 
@@ -385,14 +385,17 @@ describe("wrangler", () => {
385
385
  wrangler logout 🚪 Logout from Cloudflare
386
386
  wrangler whoami 🕵️ Retrieve your user info and test your auth config
387
387
  wrangler types 📝 Generate types from bindings & module rules in config
388
- wrangler deployments 🚢 Displays the 10 most recent deployments for a worker
388
+ wrangler deployments 🚢 List and view details for deployments
389
+ wrangler rollback [deployment-id] 🔙 Rollback a deployment
389
390
 
390
391
  Flags:
391
392
  -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
392
393
  -c, --config Path to .toml configuration file [string]
393
394
  -e, --env Environment to use for operations and .env files [string]
394
395
  -h, --help Show help [boolean]
395
- -v, --version Show version number [boolean]"
396
+ -v, --version Show version number [boolean]
397
+
398
+ 🚧\`wrangler rollback\` is a beta command. Please report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose"
396
399
  `);
397
400
  });
398
401
  });
@@ -1,5 +1,6 @@
1
1
  import { rest } from "msw";
2
2
  import { endEventLoop } from "../helpers/end-event-loop";
3
+ import { mockConsoleMethods } from "../helpers/mock-console";
3
4
  import { mockAccountId, mockApiToken } from "./../helpers/mock-account-id";
4
5
  import { msw } from "./../helpers/msw";
5
6
  import { runInTempDir } from "./../helpers/run-in-tmp";
@@ -10,6 +11,7 @@ describe("deployment list", () => {
10
11
  runInTempDir();
11
12
  mockAccountId();
12
13
  mockApiToken();
14
+ mockConsoleMethods();
13
15
 
14
16
  afterEach(async () => {
15
17
  // Force a tick to ensure that all promises resolve
@@ -1,3 +1,4 @@
1
+ import { execSync } from "node:child_process";
1
2
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
3
  import { endEventLoop } from "../helpers/end-event-loop";
3
4
  import { mockConsoleMethods } from "../helpers/mock-console";
@@ -39,7 +40,7 @@ describe("functions build", () => {
39
40
  /* --------------------------------- */
40
41
  await runWrangler(`pages functions build`);
41
42
 
42
- expect(existsSync("_worker.js")).toBe(true);
43
+ expect(existsSync("_worker.bundle")).toBe(true);
43
44
  expect(std.out).toMatchInlineSnapshot(`
44
45
  "🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose
45
46
  ✨ Compiled Worker successfully"
@@ -47,7 +48,7 @@ describe("functions build", () => {
47
48
  expect(std.err).toMatchInlineSnapshot(`""`);
48
49
  });
49
50
 
50
- it("should include any external modules imported by functions in the output bundle when the [--experimental-worker-bundle] flag is set", async () => {
51
+ it("should include any external modules imported by functions in the output bundle", async () => {
51
52
  /* ---------------------------- */
52
53
  /* Set up wasm files */
53
54
  /* ---------------------------- */
@@ -76,9 +77,7 @@ describe("functions build", () => {
76
77
  /* --------------------------------- */
77
78
  /* Run cmd & make assertions */
78
79
  /* --------------------------------- */
79
- await runWrangler(
80
- `pages functions build --outfile=_worker.bundle --experimental-worker-bundle=true`
81
- );
80
+ await runWrangler(`pages functions build --outfile=_worker.bundle`);
82
81
 
83
82
  expect(existsSync("_worker.bundle")).toBe(true);
84
83
  expect(std.out).toMatchInlineSnapshot(`
@@ -126,12 +125,13 @@ describe("functions build", () => {
126
125
  expect(std.err).toMatchInlineSnapshot(`""`);
127
126
  });
128
127
 
129
- it("should fail building if functions use external module imports, but the [--experimental-worker-bundle] flag is not set", async () => {
128
+ it("should output a directory with --outdir", async () => {
130
129
  /* ---------------------------- */
131
130
  /* Set up wasm files */
132
131
  /* ---------------------------- */
133
132
  mkdirSync("wasm");
134
- writeFileSync("wasm/greeting.wasm", "Hello wasm Functions!");
133
+ writeFileSync("wasm/greeting.wasm", "Hello");
134
+ writeFileSync("wasm/name.wasm", "wasm Functions");
135
135
 
136
136
  /* ---------------------------- */
137
137
  /* Set up Functions */
@@ -141,10 +141,12 @@ describe("functions build", () => {
141
141
  "functions/hello.js",
142
142
  `
143
143
  import hello from "./../wasm/greeting.wasm";
144
+ import name from "./../wasm/name.wasm";
144
145
 
145
146
  export async function onRequest() {
146
- const module = await WebAssembly.instantiate(greeting);
147
- return new Response(module.exports.hello);
147
+ const greetingModule = await WebAssembly.instantiate(greeting);
148
+ const nameModule = await WebAssembly.instantiate(name);
149
+ return new Response(greetingModule.exports.hello + " " + nameModule.exports.name);
148
150
  }
149
151
  `
150
152
  );
@@ -152,13 +154,23 @@ describe("functions build", () => {
152
154
  /* --------------------------------- */
153
155
  /* Run cmd & make assertions */
154
156
  /* --------------------------------- */
155
- await expect(runWrangler(`pages functions build`)).rejects.toThrowError();
156
- expect(std.err).toContain(
157
- `ERROR: No loader is configured for ".wasm" files: ../wasm/greeting.wasm`
158
- );
157
+ await runWrangler(`pages functions build --outdir=dist`);
158
+
159
+ expect(existsSync("dist")).toBe(true);
160
+ expect(std.out).toMatchInlineSnapshot(`
161
+ "🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose
162
+ ✨ Compiled Worker successfully"
163
+ `);
164
+
165
+ expect(execSync("ls dist", { encoding: "utf-8" })).toMatchInlineSnapshot(`
166
+ "e8f0f80fe25d71a0fc2b9a08c877020211192308-name.wasm
167
+ f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0-greeting.wasm
168
+ index.js
169
+ "
170
+ `);
159
171
  });
160
172
 
161
- it("should build _worker.js if the [--experimental-worker-bundle] flag is set", async () => {
173
+ it("should build _worker.js", async () => {
162
174
  /* ---------------------------- */
163
175
  /* Set up js files */
164
176
  /* ---------------------------- */
@@ -190,7 +202,7 @@ export default {
190
202
  /* Run cmd & make assertions */
191
203
  /* --------------------------------- */
192
204
  await runWrangler(
193
- `pages functions build --build-output-directory=public --outfile=_worker.bundle --experimental-worker-bundle=true`
205
+ `pages functions build --build-output-directory=public --outfile=_worker.bundle`
194
206
  );
195
207
  expect(existsSync("_worker.bundle")).toBe(true);
196
208
  expect(std.out).toMatchInlineSnapshot(`
@@ -206,7 +218,7 @@ export default {
206
218
  workerBundleContents,
207
219
  [
208
220
  [/------formdata-undici-0.[0-9]*/g, "------formdata-undici-0.test"],
209
- [/bundledWorker-0.[0-9]*.mjs/g, "bundledWorker-0.test.mjs"],
221
+ [/functionsWorker-0.[0-9]*.js/g, "functionsWorker-0.test.js"],
210
222
  ]
211
223
  );
212
224
 
@@ -214,9 +226,9 @@ export default {
214
226
  "------formdata-undici-0.test
215
227
  Content-Disposition: form-data; name=\\"metadata\\"
216
228
 
217
- {\\"main_module\\":\\"bundledWorker-0.test.mjs\\"}
229
+ {\\"main_module\\":\\"functionsWorker-0.test.js\\"}
218
230
  ------formdata-undici-0.test
219
- Content-Disposition: form-data; name=\\"bundledWorker-0.test.mjs\\"; filename=\\"bundledWorker-0.test.mjs\\"
231
+ Content-Disposition: form-data; name=\\"functionsWorker-0.test.js\\"; filename=\\"functionsWorker-0.test.js\\"
220
232
  Content-Type: application/javascript+module
221
233
 
222
234
  // ../utils/meaning-of-life.js
@@ -231,18 +243,10 @@ export default {
231
243
  export {
232
244
  worker_default as default
233
245
  };
234
- //# sourceMappingURL=bundledWorker-0.test.mjs.map
235
246
 
236
247
  ------formdata-undici-0.test--"
237
248
  `);
238
249
  expect(std.err).toMatchInlineSnapshot(`""`);
239
-
240
- await expect(
241
- runWrangler(`pages functions build --build-output-directory=public`)
242
- ).rejects.toThrowError();
243
- expect(std.err).toMatch(
244
- /ENOENT: no such file or directory, scandir '.*functions'/
245
- );
246
250
  });
247
251
 
248
252
  it("should include all external modules imported by _worker.js in the output bundle, when bundling _worker.js", async () => {
@@ -275,12 +279,10 @@ export default {
275
279
  /* --------------------------------- */
276
280
  /* Run cmd & make assertions */
277
281
  /* --------------------------------- */
278
- await runWrangler(
279
- `pages functions build --build-output-directory=public --experimental-worker-bundle=true`
280
- );
282
+ await runWrangler(`pages functions build --build-output-directory=public`);
281
283
 
282
284
  // built to _worker.js by default
283
- expect(existsSync("_worker.js")).toBe(true);
285
+ expect(existsSync("_worker.bundle")).toBe(true);
284
286
  expect(std.out).toMatchInlineSnapshot(`
285
287
  "🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose
286
288
  ✨ Compiled Worker successfully"
@@ -289,12 +291,12 @@ export default {
289
291
  // some values in workerBundleContents, such as the undici form boundary
290
292
  // or the file hashes, are randomly generated. Let's replace them
291
293
  // with static values so we can test the file contents
292
- const workerBundleContents = readFileSync("_worker.js", "utf-8");
294
+ const workerBundleContents = readFileSync("_worker.bundle", "utf-8");
293
295
  const workerBundleWithConstantData = replaceRandomWithConstantData(
294
296
  workerBundleContents,
295
297
  [
296
298
  [/------formdata-undici-0.[0-9]*/g, "------formdata-undici-0.test"],
297
- [/bundledWorker-0.[0-9]*.mjs/g, "bundledWorker-0.test.mjs"],
299
+ [/functionsWorker-0.[0-9]*.js/g, "functionsWorker-0.test.js"],
298
300
  [/[0-9a-z]*-greeting.wasm/g, "test-greeting.wasm"],
299
301
  [/[0-9a-z]*-name.wasm/g, "test-name.wasm"],
300
302
  ]
@@ -305,7 +307,7 @@ export default {
305
307
  `Content-Disposition: form-data; name="metadata"`
306
308
  );
307
309
  expect(workerBundleWithConstantData).toContain(
308
- `{"main_module":"bundledWorker-0.test.mjs"}`
310
+ `{"main_module":"functionsWorker-0.test.js"}`
309
311
  );
310
312
 
311
313
  // check we appended the wasm modules
@@ -321,7 +323,7 @@ export default {
321
323
  expect(std.err).toMatchInlineSnapshot(`""`);
322
324
  });
323
325
 
324
- it("should build _worker.js over /functions, if both are present and the [--experimental-worker-bundle] flag is set", async () => {
326
+ it("should build _worker.js over /functions, if both are present", async () => {
325
327
  /* ---------------------------- */
326
328
  /* Set up _worker.js */
327
329
  /* ---------------------------- */
@@ -352,9 +354,7 @@ export default {
352
354
  /* --------------------------------- */
353
355
  /* Run cmd & make assertions */
354
356
  /* --------------------------------- */
355
- await runWrangler(
356
- `pages functions build --outfile=public/_worker.bundle --experimental-worker-bundle=true`
357
- );
357
+ await runWrangler(`pages functions build --outfile=public/_worker.bundle`);
358
358
 
359
359
  expect(existsSync("public/_worker.bundle")).toBe(true);
360
360
  expect(std.out).toMatchInlineSnapshot(`
@@ -370,7 +370,7 @@ export default {
370
370
  workerBundleContents,
371
371
  [
372
372
  [/------formdata-undici-0.[0-9]*/g, "------formdata-undici-0.test"],
373
- [/bundledWorker-0.[0-9]*.mjs/g, "bundledWorker-0.test.mjs"],
373
+ [/functionsWorker-0.[0-9]*.js/g, "functionsWorker-0.test.js"],
374
374
  ]
375
375
  );
376
376
 
@@ -378,9 +378,9 @@ export default {
378
378
  "------formdata-undici-0.test
379
379
  Content-Disposition: form-data; name=\\"metadata\\"
380
380
 
381
- {\\"main_module\\":\\"bundledWorker-0.test.mjs\\"}
381
+ {\\"main_module\\":\\"functionsWorker-0.test.js\\"}
382
382
  ------formdata-undici-0.test
383
- Content-Disposition: form-data; name=\\"bundledWorker-0.test.mjs\\"; filename=\\"bundledWorker-0.test.mjs\\"
383
+ Content-Disposition: form-data; name=\\"functionsWorker-0.test.js\\"; filename=\\"functionsWorker-0.test.js\\"
384
384
  Content-Type: application/javascript+module
385
385
 
386
386
  // _worker.js
@@ -392,11 +392,61 @@ export default {
392
392
  export {
393
393
  worker_default as default
394
394
  };
395
- //# sourceMappingURL=bundledWorker-0.test.mjs.map
396
395
 
397
396
  ------formdata-undici-0.test--"
398
397
  `);
399
398
 
400
399
  expect(std.err).toMatchInlineSnapshot(`""`);
401
400
  });
401
+
402
+ it("should leave Node.js imports when the `nodejs_compat` compatibility flag is set", async () => {
403
+ mkdirSync("functions");
404
+ writeFileSync(
405
+ "functions/hello.js",
406
+ `
407
+ import { AsyncLocalStorage } from 'node:async_hooks';
408
+
409
+ export async function onRequest() {
410
+ console.log(AsyncLocalStorage);
411
+ return new Response("Hello from Pages Functions");
412
+ }
413
+ `
414
+ );
415
+
416
+ await runWrangler(
417
+ `pages functions build --outfile=public/_worker.bundle --compatibility-flag=nodejs_compat`
418
+ );
419
+
420
+ expect(existsSync("public/_worker.bundle")).toBe(true);
421
+ expect(std.out).toMatchInlineSnapshot(`
422
+ "🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose
423
+ ✨ Compiled Worker successfully"
424
+ `);
425
+
426
+ expect(readFileSync("public/_worker.bundle", "utf-8")).toContain(
427
+ `import { AsyncLocalStorage } from "node:async_hooks";`
428
+ );
429
+ });
430
+
431
+ it("should error at Node.js imports when the `nodejs_compat` compatibility flag is not set", async () => {
432
+ mkdirSync("functions");
433
+ writeFileSync(
434
+ "functions/hello.js",
435
+ `
436
+ import { AsyncLocalStorage } from 'node:async_hooks';
437
+
438
+ export async function onRequest() {
439
+ console.log(AsyncLocalStorage);
440
+ return new Response("Hello from Pages Functions");
441
+ }
442
+ `
443
+ );
444
+
445
+ await expect(
446
+ runWrangler(`pages functions build --outfile=public/_worker.bundle`)
447
+ ).rejects.toThrowErrorMatchingInlineSnapshot(`
448
+ "Build failed with 1 error:
449
+ hello.js:2:36: ERROR: Could not resolve \\"node:async_hooks\\""
450
+ `);
451
+ });
402
452
  });
@@ -1,5 +1,6 @@
1
1
  import { rest } from "msw";
2
2
  import { endEventLoop } from "../helpers/end-event-loop";
3
+ import { mockConsoleMethods } from "../helpers/mock-console";
3
4
  import { mockAccountId, mockApiToken } from "./../helpers/mock-account-id";
4
5
  import { msw } from "./../helpers/msw";
5
6
  import { runInTempDir } from "./../helpers/run-in-tmp";
@@ -8,6 +9,7 @@ import type { Project } from "./../../pages/types";
8
9
 
9
10
  describe("project list", () => {
10
11
  runInTempDir();
12
+ mockConsoleMethods();
11
13
  mockAccountId();
12
14
  mockApiToken();
13
15
 
@@ -1,15 +1,15 @@
1
- /* eslint-disable no-shadow */
1
+ // /* eslint-disable no-shadow */
2
2
  import { mkdirSync, writeFileSync } from "node:fs";
3
3
  import { rest } from "msw";
4
4
  import { endEventLoop } from "../helpers/end-event-loop";
5
+ import { mockAccountId, mockApiToken } from "../helpers/mock-account-id";
6
+ import { mockConsoleMethods } from "../helpers/mock-console";
5
7
  import { mockGetUploadTokenRequest } from "../helpers/mock-get-pages-upload-token";
6
8
  import { mockSetTimeout } from "../helpers/mock-set-timeout";
7
- import { mockAccountId, mockApiToken } from "./../helpers/mock-account-id";
8
- import { mockConsoleMethods } from "./../helpers/mock-console";
9
- import { msw } from "./../helpers/msw";
10
- import { runInTempDir } from "./../helpers/run-in-tmp";
11
- import { runWrangler } from "./../helpers/run-wrangler";
12
- import type { UploadPayloadFile } from "./../../pages/types";
9
+ import { msw } from "../helpers/msw";
10
+ import { runInTempDir } from "../helpers/run-in-tmp";
11
+ import { runWrangler } from "../helpers/run-wrangler";
12
+ import type { UploadPayloadFile } from "../../pages/types";
13
13
  import type { RestRequest } from "msw";
14
14
 
15
15
  describe("project upload", () => {
@@ -92,11 +92,11 @@ describe("project upload", () => {
92
92
 
93
93
  await runWrangler("pages project upload .");
94
94
 
95
- expect(std.out).toMatchInlineSnapshot(`
96
- "✨ Success! Uploaded 1 files (TIMINGS)
95
+ expect(normalizeProgressSteps(std.out)).toMatchInlineSnapshot(`
96
+ "✨ Success! Uploaded 1 files (TIMINGS)
97
97
 
98
- ✨ Upload complete!"
99
- `);
98
+ ✨ Upload complete!"
99
+ `);
100
100
  });
101
101
 
102
102
  it("should avoid uploading some files", async () => {
@@ -172,7 +172,7 @@ describe("project upload", () => {
172
172
 
173
173
  const requestMap = resolvedRequests.reduce<{
174
174
  [key: string]: UploadPayloadFile;
175
- }>((requestMap, req) => Object.assign(requestMap, { [req.key]: req }), {});
175
+ }>((map, req) => Object.assign(map, { [req.key]: req }), {});
176
176
 
177
177
  for (const req of requests) {
178
178
  expect(req.headers.get("Authorization")).toBe(
@@ -209,11 +209,11 @@ describe("project upload", () => {
209
209
  value: "ZnVuYw==",
210
210
  });
211
211
 
212
- expect(std.out).toMatchInlineSnapshot(`
213
- "✨ Success! Uploaded 3 files (TIMINGS)
212
+ expect(normalizeProgressSteps(std.out)).toMatchInlineSnapshot(`
213
+ "✨ Success! Uploaded 3 files (TIMINGS)
214
214
 
215
- ✨ Upload complete!"
216
- `);
215
+ ✨ Upload complete!"
216
+ `);
217
217
  });
218
218
 
219
219
  it("should retry uploads", async () => {
@@ -296,11 +296,11 @@ describe("project upload", () => {
296
296
  ]);
297
297
  }
298
298
 
299
- expect(std.out).toMatchInlineSnapshot(`
300
- "✨ Success! Uploaded 1 files (TIMINGS)
299
+ expect(normalizeProgressSteps(std.out)).toMatchInlineSnapshot(`
300
+ "✨ Success! Uploaded 1 files (TIMINGS)
301
301
 
302
- ✨ Upload complete!"
303
- `);
302
+ ✨ Upload complete!"
303
+ `);
304
304
  });
305
305
 
306
306
  it("should try to use multiple buckets (up to the max concurrency)", async () => {
@@ -402,11 +402,11 @@ describe("project upload", () => {
402
402
  ])
403
403
  );
404
404
 
405
- expect(std.out).toMatchInlineSnapshot(`
406
- "✨ Success! Uploaded 4 files (TIMINGS)
405
+ expect(normalizeProgressSteps(std.out)).toMatchInlineSnapshot(`
406
+ "✨ Success! Uploaded 4 files (TIMINGS)
407
407
 
408
- ✨ Upload complete!"
409
- `);
408
+ ✨ Upload complete!"
409
+ `);
410
410
  });
411
411
 
412
412
  it("should not error when directory names contain periods and houses a extensionless file", async () => {
@@ -479,3 +479,22 @@ describe("project upload", () => {
479
479
  expect(std.err).toMatchInlineSnapshot(`""`);
480
480
  });
481
481
  });
482
+
483
+ /**
484
+ * When uploading assets we print out progress messages that look like:
485
+ *
486
+ * Uploading... (1/4)
487
+ * Uploading... (2/4)
488
+ * Uploading... (4/4)
489
+ *
490
+ * Note that we don't always get a progress message for every item uploaded.
491
+ * These upload counts are not deterministic and can change from test run to test run.
492
+ *
493
+ * Also if you run the tests in --runInBand mode then we never see any of
494
+ * these progress messages in the tests!!
495
+ *
496
+ * So this helper removes these message from the snapshots to keep them consistent.
497
+ */
498
+ export function normalizeProgressSteps(str: string): string {
499
+ return str.replace(/Uploading... \(\d\/\d\)\r?\n?/g, "");
500
+ }