wrangler 2.12.2 → 2.12.3

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 (33) hide show
  1. package/package.json +4 -3
  2. package/src/__tests__/d1/execute.test.ts +2 -0
  3. package/src/__tests__/d1/migrate.test.ts +2 -0
  4. package/src/__tests__/delete.test.ts +6 -0
  5. package/src/__tests__/dev.test.tsx +71 -56
  6. package/src/__tests__/helpers/mock-console.ts +6 -0
  7. package/src/__tests__/helpers/worker-scripts/parent-worker.js +4 -1
  8. package/src/__tests__/init.test.ts +127 -96
  9. package/src/__tests__/kv.test.ts +9 -9
  10. package/src/__tests__/middleware.scheduled.test.ts +2 -2
  11. package/src/__tests__/middleware.test.ts +2 -2
  12. package/src/__tests__/pages/deployment-list.test.ts +2 -0
  13. package/src/__tests__/pages/project-list.test.ts +2 -0
  14. package/src/__tests__/pages/project-upload.test.ts +43 -24
  15. package/src/__tests__/pages/publish.test.ts +69 -69
  16. package/src/__tests__/publish.test.ts +138 -97
  17. package/src/__tests__/pubsub.test.ts +3 -0
  18. package/src/__tests__/tsconfig.tsbuildinfo +1 -1
  19. package/src/__tests__/worker-namespace.test.ts +1 -0
  20. package/src/d1/backups.tsx +15 -11
  21. package/src/d1/create.tsx +20 -16
  22. package/src/d1/execute.tsx +21 -18
  23. package/src/d1/list.tsx +2 -2
  24. package/src/d1/migrations/apply.tsx +33 -28
  25. package/src/d1/migrations/create.tsx +15 -12
  26. package/src/d1/migrations/list.tsx +10 -7
  27. package/src/pages/deployments.tsx +3 -5
  28. package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
  29. package/src/pages/projects.tsx +2 -5
  30. package/src/pages/upload.tsx +29 -9
  31. package/src/utils/render.ts +93 -0
  32. package/templates/d1-beta-facade.js +3 -0
  33. package/wrangler-dist/cli.js +225 -146
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wrangler",
3
- "version": "2.12.2",
3
+ "version": "2.12.3",
4
4
  "description": "Command-line interface for all things Cloudflare Workers",
5
5
  "keywords": [
6
6
  "wrangler",
@@ -63,9 +63,10 @@
63
63
  "emit-types": "tsc -p tsconfig.emit.json && node -r esbuild-register scripts/emit-types.ts",
64
64
  "prepublishOnly": "SOURCEMAPS=false npm run build",
65
65
  "start": "npm run bundle && cross-env NODE_OPTIONS=--enable-source-maps ./bin/wrangler.js",
66
- "test": "npm run assert-git-version && jest --silent=false --verbose=true --forceExit",
66
+ "test": "npm run assert-git-version && jest",
67
67
  "test-watch": "npm run test -- --runInBand --testTimeout=50000 --watch",
68
- "test:ci": "npm run test -- --verbose=true --coverage"
68
+ "test:ci": "npm run test -- --coverage",
69
+ "test:debug": "npm run test -- --silent=false --verbose=true"
69
70
  },
70
71
  "jest": {
71
72
  "coverageReporters": [
@@ -1,9 +1,11 @@
1
+ import { mockConsoleMethods } from "../helpers/mock-console";
1
2
  import { useMockIsTTY } from "../helpers/mock-istty";
2
3
  import { runInTempDir } from "../helpers/run-in-tmp";
3
4
  import { runWrangler } from "../helpers/run-wrangler";
4
5
  import writeWranglerToml from "../helpers/write-wrangler-toml";
5
6
 
6
7
  describe("execute", () => {
8
+ mockConsoleMethods();
7
9
  runInTempDir();
8
10
  const { setIsTTY } = useMockIsTTY();
9
11
 
@@ -1,6 +1,7 @@
1
1
  import { cwd } from "process";
2
2
  import { reinitialiseAuthTokens } from "../../user";
3
3
  import { mockAccountId, mockApiToken } from "../helpers/mock-account-id";
4
+ import { mockConsoleMethods } from "../helpers/mock-console";
4
5
  import { useMockIsTTY } from "../helpers/mock-istty";
5
6
  import { runInTempDir } from "../helpers/run-in-tmp";
6
7
  import { runWrangler } from "../helpers/run-wrangler";
@@ -8,6 +9,7 @@ import writeWranglerToml from "../helpers/write-wrangler-toml";
8
9
 
9
10
  describe("migrate", () => {
10
11
  runInTempDir();
12
+ mockConsoleMethods();
11
13
  const { setIsTTY } = useMockIsTTY();
12
14
 
13
15
  describe("create", () => {
@@ -31,6 +31,7 @@ describe("delete", () => {
31
31
  Object {
32
32
  "debug": "",
33
33
  "err": "",
34
+ "info": "",
34
35
  "out": "Successfully deleted my-script",
35
36
  "warn": "",
36
37
  }
@@ -51,6 +52,7 @@ describe("delete", () => {
51
52
  Object {
52
53
  "debug": "",
53
54
  "err": "",
55
+ "info": "",
54
56
  "out": "Successfully deleted test-name",
55
57
  "warn": "",
56
58
  }
@@ -64,6 +66,7 @@ describe("delete", () => {
64
66
  Object {
65
67
  "debug": "",
66
68
  "err": "",
69
+ "info": "",
67
70
  "out": "--dry-run: exiting now.",
68
71
  "warn": "",
69
72
  }
@@ -82,6 +85,7 @@ describe("delete", () => {
82
85
  Object {
83
86
  "debug": "",
84
87
  "err": "",
88
+ "info": "",
85
89
  "out": "",
86
90
  "warn": "",
87
91
  }
@@ -126,6 +130,7 @@ describe("delete", () => {
126
130
  Object {
127
131
  "debug": "",
128
132
  "err": "",
133
+ "info": "",
129
134
  "out": "🌀 Deleted asset namespace for Workers Site \\"__my-script-workers_sites_assets\\"
130
135
  Successfully deleted my-script",
131
136
  "warn": "",
@@ -202,6 +207,7 @@ describe("delete", () => {
202
207
  Object {
203
208
  "debug": "",
204
209
  "err": "",
210
+ "info": "",
205
211
  "out": "🌀 Deleted asset namespace for Workers Site \\"__my-script-workers_sites_assets\\"
206
212
  🌀 Deleted asset namespace for Workers Site \\"__my-script-workers_sites_assets_preview\\"
207
213
  Successfully deleted my-script",
@@ -635,7 +635,7 @@ describe("wrangler dev", () => {
635
635
  it("should run a custom build before starting `dev`", async () => {
636
636
  writeWranglerToml({
637
637
  build: {
638
- command: `node -e "console.log('custom build'); require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')"`,
638
+ command: `node -e "4+4; require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')"`,
639
639
  },
640
640
  });
641
641
 
@@ -648,12 +648,12 @@ describe("wrangler dev", () => {
648
648
  // and the command would pass through
649
649
  expect((Dev as jest.Mock).mock.calls[0][0].build).toEqual({
650
650
  command:
651
- "node -e \"console.log('custom build'); require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')\"",
651
+ "node -e \"4+4; require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')\"",
652
652
  cwd: undefined,
653
653
  watch_dir: "src",
654
654
  });
655
655
  expect(std.out).toMatchInlineSnapshot(
656
- `"Running custom build: node -e \\"console.log('custom build'); require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')\\""`
656
+ `"Running custom build: node -e \\"4+4; require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')\\""`
657
657
  );
658
658
  expect(std.err).toMatchInlineSnapshot(`""`);
659
659
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -663,7 +663,7 @@ describe("wrangler dev", () => {
663
663
  it("should run a custom build of multiple steps combined by && before starting `dev`", async () => {
664
664
  writeWranglerToml({
665
665
  build: {
666
- command: `echo "custom build" && echo "export default { fetch(){ return new Response(123) } }" > index.js`,
666
+ command: `echo "export default { fetch(){ return new Response(123) } }" > index.js`,
667
667
  },
668
668
  });
669
669
 
@@ -675,7 +675,7 @@ describe("wrangler dev", () => {
675
675
  `);
676
676
 
677
677
  expect(std.out).toMatchInlineSnapshot(
678
- `"Running custom build: echo \\"custom build\\" && echo \\"export default { fetch(){ return new Response(123) } }\\" > index.js"`
678
+ `"Running custom build: echo \\"export default { fetch(){ return new Response(123) } }\\" > index.js"`
679
679
  );
680
680
  expect(std.err).toMatchInlineSnapshot(`""`);
681
681
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -686,27 +686,27 @@ describe("wrangler dev", () => {
686
686
  writeWranglerToml({
687
687
  main: "index.js",
688
688
  build: {
689
- command: `node -e "console.log('custom build');"`,
689
+ command: `node -e "4+4;"`,
690
690
  },
691
691
  });
692
692
 
693
693
  await expect(runWrangler("dev")).rejects
694
694
  .toThrowErrorMatchingInlineSnapshot(`
695
- "The expected output file at \\"index.js\\" was not found after running custom build: node -e \\"console.log('custom build');\\".
696
- The \`main\` property in wrangler.toml should point to the file generated by the custom build."
697
- `);
695
+ "The expected output file at \\"index.js\\" was not found after running custom build: node -e \\"4+4;\\".
696
+ The \`main\` property in wrangler.toml should point to the file generated by the custom build."
697
+ `);
698
698
  expect(std.out).toMatchInlineSnapshot(`
699
- "Running custom build: node -e \\"console.log('custom build');\\"
699
+ "Running custom build: node -e \\"4+4;\\"
700
700
 
701
- If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
702
- `);
701
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
702
+ `);
703
703
  expect(std.err).toMatchInlineSnapshot(`
704
- "X [ERROR] The expected output file at \\"index.js\\" was not found after running custom build: node -e \\"console.log('custom build');\\".
704
+ "X [ERROR] The expected output file at \\"index.js\\" was not found after running custom build: node -e \\"4+4;\\".
705
705
 
706
- The \`main\` property in wrangler.toml should point to the file generated by the custom build.
706
+ The \`main\` property in wrangler.toml should point to the file generated by the custom build.
707
707
 
708
- "
709
- `);
708
+ "
709
+ `);
710
710
  expect(std.warn).toMatchInlineSnapshot(`""`);
711
711
  });
712
712
 
@@ -894,6 +894,7 @@ describe("wrangler dev", () => {
894
894
  Object {
895
895
  "debug": "",
896
896
  "err": "",
897
+ "info": "",
897
898
  "out": "",
898
899
  "warn": "",
899
900
  }
@@ -911,6 +912,7 @@ describe("wrangler dev", () => {
911
912
  Object {
912
913
  "debug": "",
913
914
  "err": "",
915
+ "info": "",
914
916
  "out": "",
915
917
  "warn": "",
916
918
  }
@@ -928,6 +930,7 @@ describe("wrangler dev", () => {
928
930
  Object {
929
931
  "debug": "",
930
932
  "err": "",
933
+ "info": "",
931
934
  "out": "",
932
935
  "warn": "",
933
936
  }
@@ -948,6 +951,7 @@ describe("wrangler dev", () => {
948
951
  Object {
949
952
  "debug": "",
950
953
  "err": "",
954
+ "info": "",
951
955
  "out": "",
952
956
  "warn": "",
953
957
  }
@@ -1209,6 +1213,7 @@ describe("wrangler dev", () => {
1209
1213
  "err": "X [ERROR] Not enough arguments following: site
1210
1214
 
1211
1215
  ",
1216
+ "info": "",
1212
1217
  "out": "
1213
1218
  wrangler dev [script]
1214
1219
 
@@ -1343,15 +1348,16 @@ describe("wrangler dev", () => {
1343
1348
 
1344
1349
  await runWrangler('dev --assets "./assets"');
1345
1350
  expect(std).toMatchInlineSnapshot(`
1346
- Object {
1347
- "debug": "",
1348
- "err": "",
1349
- "out": "",
1350
- "warn": "▲ [WARNING] The --assets argument is experimental and may change or break at any time
1351
-
1352
- ",
1353
- }
1354
- `);
1351
+ Object {
1352
+ "debug": "",
1353
+ "err": "",
1354
+ "info": "",
1355
+ "out": "",
1356
+ "warn": "▲ [WARNING] The --assets argument is experimental and may change or break at any time
1357
+
1358
+ ",
1359
+ }
1360
+ `);
1355
1361
  });
1356
1362
 
1357
1363
  it("should warn if config.assets is used", async () => {
@@ -1364,17 +1370,18 @@ describe("wrangler dev", () => {
1364
1370
 
1365
1371
  await runWrangler("dev");
1366
1372
  expect(std).toMatchInlineSnapshot(`
1367
- Object {
1368
- "debug": "",
1369
- "err": "",
1370
- "out": "",
1371
- "warn": "▲ [WARNING] Processing wrangler.toml configuration:
1373
+ Object {
1374
+ "debug": "",
1375
+ "err": "",
1376
+ "info": "",
1377
+ "out": "",
1378
+ "warn": "▲ [WARNING] Processing wrangler.toml configuration:
1372
1379
 
1373
- - \\"assets\\" fields are experimental and may change or break at any time.
1380
+ - \\"assets\\" fields are experimental and may change or break at any time.
1374
1381
 
1375
- ",
1376
- }
1377
- `);
1382
+ ",
1383
+ }
1384
+ `);
1378
1385
  });
1379
1386
  });
1380
1387
 
@@ -1383,15 +1390,16 @@ describe("wrangler dev", () => {
1383
1390
  fs.writeFileSync("index.js", `export default {};`);
1384
1391
  await runWrangler("dev index.js --inspect");
1385
1392
  expect(std).toMatchInlineSnapshot(`
1386
- Object {
1387
- "debug": "",
1388
- "err": "",
1389
- "out": "",
1390
- "warn": "▲ [WARNING] Passing --inspect is unnecessary, now you can always connect to devtools.
1391
-
1392
- ",
1393
- }
1394
- `);
1393
+ Object {
1394
+ "debug": "",
1395
+ "err": "",
1396
+ "info": "",
1397
+ "out": "",
1398
+ "warn": "▲ [WARNING] Passing --inspect is unnecessary, now you can always connect to devtools.
1399
+
1400
+ ",
1401
+ }
1402
+ `);
1395
1403
  });
1396
1404
 
1397
1405
  it("should default to true, without a warning", async () => {
@@ -1402,6 +1410,7 @@ describe("wrangler dev", () => {
1402
1410
  Object {
1403
1411
  "debug": "",
1404
1412
  "err": "",
1413
+ "info": "",
1405
1414
  "out": "",
1406
1415
  "warn": "",
1407
1416
  }
@@ -1416,6 +1425,7 @@ describe("wrangler dev", () => {
1416
1425
  Object {
1417
1426
  "debug": "",
1418
1427
  "err": "",
1428
+ "info": "",
1419
1429
  "out": "",
1420
1430
  "warn": "▲ [WARNING] Passing --inspect is unnecessary, now you can always connect to devtools.
1421
1431
 
@@ -1432,6 +1442,7 @@ describe("wrangler dev", () => {
1432
1442
  Object {
1433
1443
  "debug": "",
1434
1444
  "err": "",
1445
+ "info": "",
1435
1446
  "out": "",
1436
1447
  "warn": "",
1437
1448
  }
@@ -1447,6 +1458,7 @@ describe("wrangler dev", () => {
1447
1458
  Object {
1448
1459
  "debug": "",
1449
1460
  "err": "",
1461
+ "info": "",
1450
1462
  "out": "",
1451
1463
  "warn": "",
1452
1464
  }
@@ -1460,6 +1472,7 @@ describe("wrangler dev", () => {
1460
1472
  Object {
1461
1473
  "debug": "",
1462
1474
  "err": "",
1475
+ "info": "",
1463
1476
  "out": "",
1464
1477
  "warn": "▲ [WARNING] Passing --inspect is unnecessary, now you can always connect to devtools.
1465
1478
 
@@ -1516,23 +1529,24 @@ describe("wrangler dev", () => {
1516
1529
  fs.writeFileSync("index.js", `export default {};`);
1517
1530
  await runWrangler("dev index.js");
1518
1531
  expect(std).toMatchInlineSnapshot(`
1519
- Object {
1520
- "debug": "",
1521
- "err": "",
1522
- "out": "Your worker has access to the following bindings:
1523
- - Services:
1524
- - WorkerA: A
1525
- - WorkerB: B - staging",
1526
- "warn": "▲ [WARNING] Processing wrangler.toml configuration:
1532
+ Object {
1533
+ "debug": "",
1534
+ "err": "",
1535
+ "info": "",
1536
+ "out": "Your worker has access to the following bindings:
1537
+ - Services:
1538
+ - WorkerA: A
1539
+ - WorkerB: B - staging",
1540
+ "warn": "▲ [WARNING] Processing wrangler.toml configuration:
1527
1541
 
1528
- - \\"services\\" fields are experimental and may change or break at any time.
1542
+ - \\"services\\" fields are experimental and may change or break at any time.
1529
1543
 
1530
1544
 
1531
- ▲ [WARNING] This worker is bound to live services: WorkerA (A), WorkerB (B@staging)
1545
+ ▲ [WARNING] This worker is bound to live services: WorkerA (A), WorkerB (B@staging)
1532
1546
 
1533
- ",
1534
- }
1535
- `);
1547
+ ",
1548
+ }
1549
+ `);
1536
1550
  });
1537
1551
 
1538
1552
  it("should mask vars that were overriden in .dev.vars", async () => {
@@ -1555,6 +1569,7 @@ describe("wrangler dev", () => {
1555
1569
  Object {
1556
1570
  "debug": "",
1557
1571
  "err": "",
1572
+ "info": "",
1558
1573
  "out": "Using vars defined in .dev.vars
1559
1574
  Your worker has access to the following bindings:
1560
1575
  - Vars:
@@ -8,6 +8,7 @@ import { logger } from "../../logger";
8
8
 
9
9
  let debugSpy: jest.SpyInstance,
10
10
  logSpy: jest.SpyInstance,
11
+ infoSpy: jest.SpyInstance,
11
12
  errorSpy: jest.SpyInstance,
12
13
  warnSpy: jest.SpyInstance;
13
14
 
@@ -18,6 +19,9 @@ const std = {
18
19
  get out() {
19
20
  return normalizeOutput(logSpy);
20
21
  },
22
+ get info() {
23
+ return normalizeOutput(infoSpy);
24
+ },
21
25
  get err() {
22
26
  return normalizeOutput(errorSpy);
23
27
  },
@@ -47,12 +51,14 @@ export function mockConsoleMethods() {
47
51
  logger.columns = 100;
48
52
  debugSpy = jest.spyOn(console, "debug").mockImplementation();
49
53
  logSpy = jest.spyOn(console, "log").mockImplementation();
54
+ infoSpy = jest.spyOn(console, "info").mockImplementation();
50
55
  errorSpy = jest.spyOn(console, "error").mockImplementation();
51
56
  warnSpy = jest.spyOn(console, "warn").mockImplementation();
52
57
  });
53
58
  afterEach(() => {
54
59
  debugSpy.mockRestore();
55
60
  logSpy.mockRestore();
61
+ infoSpy.mockRestore();
56
62
  errorSpy.mockRestore();
57
63
  warnSpy.mockRestore();
58
64
  });
@@ -2,7 +2,10 @@ export default {
2
2
  async fetch(req, env) {
3
3
  const resp = await env.CHILD.fetch(req);
4
4
  const text = await resp.text();
5
- console.log("text: ", text);
5
+ // TODO: we should capture console logs when running `dev` programmatically
6
+ // (and locally) and expose it on the DevWorker object instead of allowing
7
+ // the log to appear in the output of the test runner.
8
+ // console.log("text: ", text);
6
9
  return new Response(`Parent worker sees: ${text}`);
7
10
  },
8
11
  };