wrangler 2.0.25 → 2.0.28

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 (66) hide show
  1. package/bin/wrangler.js +1 -1
  2. package/miniflare-dist/index.mjs +15 -3
  3. package/package.json +8 -6
  4. package/src/__tests__/configuration.test.ts +33 -29
  5. package/src/__tests__/dev.test.tsx +8 -6
  6. package/src/__tests__/generate.test.ts +2 -4
  7. package/src/__tests__/helpers/mock-cfetch.ts +33 -0
  8. package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -0
  9. package/src/__tests__/helpers/mock-known-routes.ts +7 -0
  10. package/src/__tests__/index.test.ts +30 -30
  11. package/src/__tests__/init.test.ts +537 -359
  12. package/src/__tests__/jest.setup.ts +7 -0
  13. package/src/__tests__/metrics.test.ts +1 -1
  14. package/src/__tests__/pages.test.ts +14 -0
  15. package/src/__tests__/publish.test.ts +59 -18
  16. package/src/__tests__/r2.test.ts +4 -3
  17. package/src/__tests__/tail.test.ts +53 -3
  18. package/src/__tests__/test-old-node-version.js +3 -3
  19. package/src/__tests__/user.test.ts +11 -0
  20. package/src/__tests__/worker-namespace.test.ts +37 -35
  21. package/src/api/dev.ts +1 -0
  22. package/src/bundle.ts +1 -1
  23. package/src/cfetch/internal.ts +118 -1
  24. package/src/config/environment.ts +1 -1
  25. package/src/config/index.ts +4 -4
  26. package/src/config/validation-helpers.ts +19 -6
  27. package/src/config/validation.ts +11 -5
  28. package/src/config-cache.ts +2 -1
  29. package/src/create-worker-upload-form.ts +29 -26
  30. package/src/dev/dev.tsx +4 -0
  31. package/src/dev/remote.tsx +10 -1
  32. package/src/dev.tsx +36 -8
  33. package/src/{worker-namespace.ts → dispatch-namespace.ts} +18 -18
  34. package/src/generate.ts +1 -1
  35. package/src/index.tsx +54 -8
  36. package/src/init.ts +111 -38
  37. package/src/{metrics/is-ci.ts → is-ci.ts} +0 -0
  38. package/src/metrics/metrics-config.ts +1 -1
  39. package/src/metrics/send-event.ts +5 -5
  40. package/src/miniflare-cli/assets.ts +8 -0
  41. package/src/miniflare-cli/index.ts +6 -3
  42. package/src/pages/build.tsx +41 -15
  43. package/src/pages/constants.ts +1 -0
  44. package/src/pages/dev.tsx +93 -37
  45. package/src/pages/errors.ts +22 -0
  46. package/src/pages/functions/routes-consolidation.test.ts +185 -1
  47. package/src/pages/functions/routes-consolidation.ts +46 -2
  48. package/src/pages/functions/routes-transformation.ts +0 -3
  49. package/src/pages/functions.tsx +96 -0
  50. package/src/pages/index.tsx +65 -55
  51. package/src/pages/publish.tsx +27 -16
  52. package/src/proxy.ts +10 -0
  53. package/src/publish.ts +19 -4
  54. package/src/r2.ts +4 -4
  55. package/src/tail/filters.ts +3 -1
  56. package/src/tail/printing.ts +2 -0
  57. package/src/user/user.tsx +6 -4
  58. package/src/whoami.tsx +5 -5
  59. package/src/worker.ts +3 -2
  60. package/src/zones.ts +91 -0
  61. package/templates/pages-template-plugin.ts +16 -4
  62. package/templates/pages-template-worker.ts +16 -5
  63. package/templates/service-bindings-module-facade.js +10 -7
  64. package/templates/service-bindings-sw-facade.js +10 -7
  65. package/wrangler-dist/cli.d.ts +8 -3
  66. package/wrangler-dist/cli.js +6757 -1639
package/bin/wrangler.js CHANGED
@@ -4,7 +4,7 @@ const path = require("path");
4
4
  const fs = require("fs");
5
5
  const os = require("os");
6
6
 
7
- const MIN_NODE_VERSION = "16.7.0";
7
+ const MIN_NODE_VERSION = "16.13.0";
8
8
  const debug =
9
9
  process.env["WRANGLER_LOG"] === "debug"
10
10
  ? (...args) => console.log(...args)
@@ -5277,6 +5277,14 @@ async function generateAssetsFetch(directory, log) {
5277
5277
  return deconstructedResponse;
5278
5278
  }
5279
5279
  } else if (hasFileExtension(assetName)) {
5280
+ if (asset = getAsset(assetName + ".html")) {
5281
+ deconstructedResponse.body = serveAsset(asset);
5282
+ deconstructedResponse.headers.set(
5283
+ "Content-Type",
5284
+ (0, import_mime.getType)(asset) || "application/octet-stream"
5285
+ );
5286
+ return deconstructedResponse;
5287
+ }
5280
5288
  notFound();
5281
5289
  return deconstructedResponse;
5282
5290
  }
@@ -5409,10 +5417,14 @@ async function main() {
5409
5417
  namespace.get = (id) => {
5410
5418
  const stub = new DurableObjectStub(factory, id);
5411
5419
  stub.fetch = (...reqArgs) => {
5412
- const url = `http://${host}${port ? `:${port}` : ""}`;
5420
+ const requestFromArgs = new MiniflareRequest(...reqArgs);
5421
+ const url = new URL(requestFromArgs.url);
5422
+ url.host = host;
5423
+ if (port !== void 0)
5424
+ url.port = port.toString();
5413
5425
  const request = new MiniflareRequest(
5414
- url,
5415
- new MiniflareRequest(...reqArgs)
5426
+ url.toString(),
5427
+ requestFromArgs
5416
5428
  );
5417
5429
  request.headers.set("x-miniflare-durable-object-name", name);
5418
5430
  request.headers.set("x-miniflare-durable-object-id", id.toString());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wrangler",
3
- "version": "2.0.25",
3
+ "version": "2.0.28",
4
4
  "description": "Command-line interface for all things Cloudflare Workers",
5
5
  "keywords": [
6
6
  "wrangler",
@@ -52,11 +52,11 @@
52
52
  "build": "npm run clean && npm run bundle && npm run emit-types",
53
53
  "bundle": "node -r esbuild-register scripts/bundle.ts",
54
54
  "check:type": "tsc",
55
- "clean": "rm -rf wrangler-dist miniflare-dist emitted-types",
55
+ "clean": "rimraf wrangler-dist miniflare-dist emitted-types",
56
56
  "dev": "npm run clean && concurrently -c black,blue --kill-others-on-fail false 'npm run bundle -- --watch' 'npm run check:type -- --watch --preserveWatchOutput'",
57
57
  "emit-types": "tsc -p tsconfig.emit.json && node -r esbuild-register scripts/emit-types.ts",
58
58
  "prepublishOnly": "SOURCEMAPS=false npm run build",
59
- "start": "npm run bundle && NODE_OPTIONS=--enable-source-maps ./bin/wrangler.js",
59
+ "start": "npm run bundle && cross-env NODE_OPTIONS=--enable-source-maps ./bin/wrangler.js",
60
60
  "test": "jest --silent=false --verbose=true",
61
61
  "test-watch": "npm run test -- --runInBand --testTimeout=50000 --watch",
62
62
  "test:ci": "npm run test -- --verbose=true --coverage"
@@ -97,7 +97,7 @@
97
97
  "blake3-wasm": "^2.1.5",
98
98
  "chokidar": "^3.5.3",
99
99
  "esbuild": "0.14.51",
100
- "miniflare": "^2.6.0",
100
+ "miniflare": "^2.7.1",
101
101
  "nanoid": "^3.3.3",
102
102
  "path-to-regexp": "^6.2.0",
103
103
  "selfsigned": "^2.0.1",
@@ -107,6 +107,7 @@
107
107
  "devDependencies": {
108
108
  "@iarna/toml": "^3.0.0",
109
109
  "@microsoft/api-extractor": "^7.28.3",
110
+ "@types/busboy": "^1.5.0",
110
111
  "@types/command-exists": "^1.2.0",
111
112
  "@types/express": "^4.17.13",
112
113
  "@types/glob-to-regexp": "0.4.1",
@@ -120,6 +121,7 @@
120
121
  "@types/yargs": "^17.0.10",
121
122
  "@webcontainer/env": "^1.0.1",
122
123
  "body-parser": "^1.20.0",
124
+ "busboy": "^1.6.0",
123
125
  "clipboardy": "^3.0.0",
124
126
  "cmd-shim": "^4.1.0",
125
127
  "command-exists": "^1.2.9",
@@ -158,7 +160,7 @@
158
160
  "timeago.js": "^4.0.2",
159
161
  "tmp-promise": "^3.0.3",
160
162
  "ts-dedent": "^2.2.0",
161
- "undici": "^5.5.1",
163
+ "undici": "^5.9.1",
162
164
  "update-check": "^1.5.4",
163
165
  "ws": "^8.5.0",
164
166
  "xdg-app-paths": "^7.3.0",
@@ -168,6 +170,6 @@
168
170
  "fsevents": "~2.3.2"
169
171
  },
170
172
  "engines": {
171
- "node": ">=16.7.0"
173
+ "node": ">=16.13.0"
172
174
  }
173
175
  }
@@ -61,7 +61,7 @@ describe("normalizeAndValidateConfig()", () => {
61
61
  unsafe: {
62
62
  bindings: [],
63
63
  },
64
- worker_namespaces: [],
64
+ dispatch_namespaces: [],
65
65
  usage_model: undefined,
66
66
  vars: {},
67
67
  define: {},
@@ -1635,6 +1635,7 @@ describe("normalizeAndValidateConfig()", () => {
1635
1635
  id: "KV_ID_2",
1636
1636
  preview_id: 2222,
1637
1637
  },
1638
+ { binding: "VALID", id: "" },
1638
1639
  ],
1639
1640
  } as unknown as RawConfig,
1640
1641
  undefined,
@@ -1654,7 +1655,8 @@ describe("normalizeAndValidateConfig()", () => {
1654
1655
  - \\"kv_namespaces[1]\\" bindings should have a string \\"id\\" field but got {\\"binding\\":\\"VALID\\"}.
1655
1656
  - \\"kv_namespaces[2]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":2000,\\"id\\":2111}.
1656
1657
  - \\"kv_namespaces[2]\\" bindings should have a string \\"id\\" field but got {\\"binding\\":2000,\\"id\\":2111}.
1657
- - \\"kv_namespaces[3]\\" bindings should, optionally, have a string \\"preview_id\\" field but got {\\"binding\\":\\"KV_BINDING_2\\",\\"id\\":\\"KV_ID_2\\",\\"preview_id\\":2222}."
1658
+ - \\"kv_namespaces[3]\\" bindings should, optionally, have a string \\"preview_id\\" field but got {\\"binding\\":\\"KV_BINDING_2\\",\\"id\\":\\"KV_ID_2\\",\\"preview_id\\":2222}.
1659
+ - \\"kv_namespaces[4]\\" bindings should have a string \\"id\\" field but got {\\"binding\\":\\"VALID\\",\\"id\\":\\"\\"}."
1658
1660
  `);
1659
1661
  });
1660
1662
  });
@@ -1740,6 +1742,7 @@ describe("normalizeAndValidateConfig()", () => {
1740
1742
  bucket_name: "R2_BUCKET_2",
1741
1743
  preview_bucket_name: 2555,
1742
1744
  },
1745
+ { binding: "R2_BINDING_1", bucket_name: "" },
1743
1746
  ],
1744
1747
  } as unknown as RawConfig,
1745
1748
  undefined,
@@ -1759,7 +1762,8 @@ describe("normalizeAndValidateConfig()", () => {
1759
1762
  - \\"r2_buckets[1]\\" bindings should have a string \\"bucket_name\\" field but got {\\"binding\\":\\"R2_BINDING_1\\"}.
1760
1763
  - \\"r2_buckets[2]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":2333,\\"bucket_name\\":2444}.
1761
1764
  - \\"r2_buckets[2]\\" bindings should have a string \\"bucket_name\\" field but got {\\"binding\\":2333,\\"bucket_name\\":2444}.
1762
- - \\"r2_buckets[3]\\" bindings should, optionally, have a string \\"preview_bucket_name\\" field but got {\\"binding\\":\\"R2_BINDING_2\\",\\"bucket_name\\":\\"R2_BUCKET_2\\",\\"preview_bucket_name\\":2555}."
1765
+ - \\"r2_buckets[3]\\" bindings should, optionally, have a string \\"preview_bucket_name\\" field but got {\\"binding\\":\\"R2_BINDING_2\\",\\"bucket_name\\":\\"R2_BUCKET_2\\",\\"preview_bucket_name\\":2555}.
1766
+ - \\"r2_buckets[4]\\" bindings should have a string \\"bucket_name\\" field but got {\\"binding\\":\\"R2_BINDING_1\\",\\"bucket_name\\":\\"\\"}."
1763
1767
  `);
1764
1768
  });
1765
1769
  });
@@ -1909,11 +1913,11 @@ describe("normalizeAndValidateConfig()", () => {
1909
1913
  });
1910
1914
  });
1911
1915
 
1912
- describe("[worker_namespaces]", () => {
1913
- it("should log an experimental warning when worker_namespaces is used", () => {
1916
+ describe("[dispatch_namespaces]", () => {
1917
+ it("should log an experimental warning when dispatch_namespaces is used", () => {
1914
1918
  const { config, diagnostics } = normalizeAndValidateConfig(
1915
1919
  {
1916
- worker_namespaces: [
1920
+ dispatch_namespaces: [
1917
1921
  {
1918
1922
  binding: "BINDING_1",
1919
1923
  namespace: "NAMESPACE_1",
@@ -1924,44 +1928,44 @@ describe("normalizeAndValidateConfig()", () => {
1924
1928
  { env: undefined }
1925
1929
  );
1926
1930
  expect(config).toEqual(
1927
- expect.not.objectContaining({ worker_namespaces: expect.anything })
1931
+ expect.not.objectContaining({ dispatch_namespaces: expect.anything })
1928
1932
  );
1929
1933
  expect(diagnostics.hasWarnings()).toBe(true);
1930
1934
  expect(diagnostics.hasErrors()).toBe(false);
1931
1935
  expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1932
1936
  "Processing wrangler configuration:
1933
- - \\"worker_namespaces\\" fields are experimental and may change or break at any time."
1937
+ - \\"dispatch_namespaces\\" fields are experimental and may change or break at any time."
1934
1938
  `);
1935
1939
  });
1936
1940
 
1937
- it("should error if worker_namespaces is not an array", () => {
1941
+ it("should error if dispatch_namespaces is not an array", () => {
1938
1942
  const { config, diagnostics } = normalizeAndValidateConfig(
1939
1943
  {
1940
- worker_namespaces: "just a string",
1944
+ dispatch_namespaces: "just a string",
1941
1945
  } as unknown as RawConfig,
1942
1946
  undefined,
1943
1947
  { env: undefined }
1944
1948
  );
1945
1949
 
1946
1950
  expect(config).toEqual(
1947
- expect.not.objectContaining({ worker_namespaces: expect.anything })
1951
+ expect.not.objectContaining({ dispatch_namespaces: expect.anything })
1948
1952
  );
1949
1953
  expect(diagnostics.hasWarnings()).toBe(true);
1950
1954
  expect(diagnostics.hasErrors()).toBe(true);
1951
1955
  expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1952
1956
  "Processing wrangler configuration:
1953
- - \\"worker_namespaces\\" fields are experimental and may change or break at any time."
1957
+ - \\"dispatch_namespaces\\" fields are experimental and may change or break at any time."
1954
1958
  `);
1955
1959
  expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1956
1960
  "Processing wrangler configuration:
1957
- - The field \\"worker_namespaces\\" should be an array but got \\"just a string\\"."
1961
+ - The field \\"dispatch_namespaces\\" should be an array but got \\"just a string\\"."
1958
1962
  `);
1959
1963
  });
1960
1964
 
1961
- it("should error on non valid worker_namespaces", () => {
1965
+ it("should error on non valid dispatch_namespaces", () => {
1962
1966
  const { config, diagnostics } = normalizeAndValidateConfig(
1963
1967
  {
1964
- worker_namespaces: [
1968
+ dispatch_namespaces: [
1965
1969
  "a string",
1966
1970
  123,
1967
1971
  {
@@ -1969,17 +1973,17 @@ describe("normalizeAndValidateConfig()", () => {
1969
1973
  namespace: 456,
1970
1974
  },
1971
1975
  {
1972
- binding: "WORKER_NAMESPACE_BINDING_1",
1976
+ binding: "DISPATCH_NAMESPACE_BINDING_1",
1973
1977
  namespace: 456,
1974
1978
  },
1975
1979
  // this one is valid
1976
1980
  {
1977
- binding: "WORKER_NAMESPACE_BINDING_1",
1978
- namespace: "WORKER_NAMESPACE_BINDING_NAMESPACE_1",
1981
+ binding: "DISPATCH_NAMESPACE_BINDING_1",
1982
+ namespace: "DISPATCH_NAMESPACE_BINDING_NAMESPACE_1",
1979
1983
  },
1980
1984
  {
1981
1985
  binding: 123,
1982
- namespace: "WORKER_NAMESPACE_BINDING_SERVICE_1",
1986
+ namespace: "DISPATCH_NAMESPACE_BINDING_SERVICE_1",
1983
1987
  },
1984
1988
  {
1985
1989
  binding: 123,
@@ -1992,25 +1996,25 @@ describe("normalizeAndValidateConfig()", () => {
1992
1996
  );
1993
1997
  expect(config).toEqual(
1994
1998
  expect.not.objectContaining({
1995
- worker_namespaces: expect.anything,
1999
+ dispatch_namespaces: expect.anything,
1996
2000
  })
1997
2001
  );
1998
2002
  expect(diagnostics.hasWarnings()).toBe(true);
1999
2003
  expect(diagnostics.hasErrors()).toBe(true);
2000
2004
  expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2001
2005
  "Processing wrangler configuration:
2002
- - \\"worker_namespaces\\" fields are experimental and may change or break at any time."
2006
+ - \\"dispatch_namespaces\\" fields are experimental and may change or break at any time."
2003
2007
  `);
2004
2008
  expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2005
2009
  "Processing wrangler configuration:
2006
- - \\"worker_namespaces[0]\\" binding should be objects, but got \\"a string\\"
2007
- - \\"worker_namespaces[1]\\" binding should be objects, but got 123
2008
- - \\"worker_namespaces[2]\\" should have a string \\"binding\\" field but got {\\"binding\\":123,\\"namespace\\":456}.
2009
- - \\"worker_namespaces[2]\\" should have a string \\"namespace\\" field but got {\\"binding\\":123,\\"namespace\\":456}.
2010
- - \\"worker_namespaces[3]\\" should have a string \\"namespace\\" field but got {\\"binding\\":\\"WORKER_NAMESPACE_BINDING_1\\",\\"namespace\\":456}.
2011
- - \\"worker_namespaces[5]\\" should have a string \\"binding\\" field but got {\\"binding\\":123,\\"namespace\\":\\"WORKER_NAMESPACE_BINDING_SERVICE_1\\"}.
2012
- - \\"worker_namespaces[6]\\" should have a string \\"binding\\" field but got {\\"binding\\":123,\\"service\\":456}.
2013
- - \\"worker_namespaces[6]\\" should have a string \\"namespace\\" field but got {\\"binding\\":123,\\"service\\":456}."
2010
+ - \\"dispatch_namespaces[0]\\" binding should be objects, but got \\"a string\\"
2011
+ - \\"dispatch_namespaces[1]\\" binding should be objects, but got 123
2012
+ - \\"dispatch_namespaces[2]\\" should have a string \\"binding\\" field but got {\\"binding\\":123,\\"namespace\\":456}.
2013
+ - \\"dispatch_namespaces[2]\\" should have a string \\"namespace\\" field but got {\\"binding\\":123,\\"namespace\\":456}.
2014
+ - \\"dispatch_namespaces[3]\\" should have a string \\"namespace\\" field but got {\\"binding\\":\\"DISPATCH_NAMESPACE_BINDING_1\\",\\"namespace\\":456}.
2015
+ - \\"dispatch_namespaces[5]\\" should have a string \\"binding\\" field but got {\\"binding\\":123,\\"namespace\\":\\"DISPATCH_NAMESPACE_BINDING_SERVICE_1\\"}.
2016
+ - \\"dispatch_namespaces[6]\\" should have a string \\"binding\\" field but got {\\"binding\\":123,\\"service\\":456}.
2017
+ - \\"dispatch_namespaces[6]\\" should have a string \\"namespace\\" field but got {\\"binding\\":123,\\"service\\":456}."
2014
2018
  `);
2015
2019
  });
2016
2020
  });
@@ -668,12 +668,12 @@ describe("wrangler dev", () => {
668
668
  writeWranglerToml({
669
669
  main: "index.js",
670
670
  dev: {
671
- ip: "0.0.0.0",
671
+ ip: "1.2.3.4",
672
672
  },
673
673
  });
674
674
  fs.writeFileSync("index.js", `export default {};`);
675
675
  await runWrangler("dev");
676
- expect((Dev as jest.Mock).mock.calls[0][0].ip).toEqual("0.0.0.0");
676
+ expect((Dev as jest.Mock).mock.calls[0][0].ip).toEqual("1.2.3.4");
677
677
  expect(std.out).toMatchInlineSnapshot(`""`);
678
678
  expect(std.warn).toMatchInlineSnapshot(`""`);
679
679
  expect(std.err).toMatchInlineSnapshot(`""`);
@@ -683,12 +683,12 @@ describe("wrangler dev", () => {
683
683
  writeWranglerToml({
684
684
  main: "index.js",
685
685
  dev: {
686
- ip: "1.1.1.1",
686
+ ip: "1.2.3.4",
687
687
  },
688
688
  });
689
689
  fs.writeFileSync("index.js", `export default {};`);
690
- await runWrangler("dev --ip=0.0.0.0");
691
- expect((Dev as jest.Mock).mock.calls[0][0].ip).toEqual("0.0.0.0");
690
+ await runWrangler("dev --ip=5.6.7.8");
691
+ expect((Dev as jest.Mock).mock.calls[0][0].ip).toEqual("5.6.7.8");
692
692
  expect(std.out).toMatchInlineSnapshot(`""`);
693
693
  expect(std.warn).toMatchInlineSnapshot(`""`);
694
694
  expect(std.err).toMatchInlineSnapshot(`""`);
@@ -1005,7 +1005,7 @@ describe("wrangler dev", () => {
1005
1005
  --compatibility-date Date to use for compatibility checks [string]
1006
1006
  --compatibility-flags, --compatibility-flag Flags to use for compatibility checks [array]
1007
1007
  --latest Use the latest version of the worker runtime [boolean] [default: true]
1008
- --ip IP address to listen on [string] [default: \\"0.0.0.0\\"]
1008
+ --ip IP address to listen on [string]
1009
1009
  --port Port to listen on [number]
1010
1010
  --inspector-port Port for devtools to connect to [number]
1011
1011
  --routes, --route Routes to upload [array]
@@ -1017,6 +1017,8 @@ describe("wrangler dev", () => {
1017
1017
  --site-include Array of .gitignore-style patterns that match file or directory names from the sites directory. Only matched items will be uploaded. [array]
1018
1018
  --site-exclude Array of .gitignore-style patterns that match file or directory names from the sites directory. Matched items will not be uploaded. [array]
1019
1019
  --upstream-protocol Protocol to forward requests to host on, defaults to https. [choices: \\"http\\", \\"https\\"]
1020
+ --var A key-value pair to be injected into the script as a variable [array]
1021
+ --define A key-value pair to be substituted in the script [array]
1020
1022
  --jsx-factory The function that is called for each JSX element [string]
1021
1023
  --jsx-fragment The function that is called for each JSX fragment [string]
1022
1024
  --tsconfig Path to a custom tsconfig.json file [string]
@@ -1,6 +1,4 @@
1
1
  import fs from "node:fs";
2
- import path from "node:path";
3
- import process from "node:process";
4
2
  import { setup } from "create-cloudflare";
5
3
  import { mockConsoleMethods } from "./helpers/mock-console";
6
4
  import { mockConfirm, clearConfirmMocks } from "./helpers/mock-dialogs";
@@ -73,7 +71,7 @@ describe("generate", () => {
73
71
  ).resolves.toBeUndefined();
74
72
 
75
73
  expect(createCloudflareMock).lastCalledWith(
76
- path.resolve(process.cwd(), "my-worker-1"),
74
+ "my-worker-1",
77
75
  "some-template",
78
76
  { debug: false, force: false, init: true }
79
77
  );
@@ -85,7 +83,7 @@ describe("generate", () => {
85
83
  ).resolves.toBeUndefined();
86
84
 
87
85
  expect(createCloudflareMock).lastCalledWith(
88
- path.resolve(process.cwd(), "my-worker-2"),
86
+ "my-worker-2",
89
87
  "some-template",
90
88
  { debug: false, force: false, init: true }
91
89
  );
@@ -183,6 +183,7 @@ export function unsetAllMocks() {
183
183
 
184
184
  const kvGetMocks = new Map<string, string | Buffer>();
185
185
  const r2GetMocks = new Map<string, string | undefined>();
186
+ const dashScriptMocks = new Map<string, string | undefined>();
186
187
 
187
188
  /**
188
189
  * @mocked typeof fetchKVGetValue
@@ -260,4 +261,36 @@ export function setMockFetchR2Objects({
260
261
  export function unsetSpecialMockFns() {
261
262
  kvGetMocks.clear();
262
263
  r2GetMocks.clear();
264
+ dashScriptMocks.clear();
265
+ }
266
+
267
+ /**
268
+ * @mocked typeof fetchDashScript
269
+ * multipart/form-data is the response for modules and raw text for the Script endpoint.
270
+ */
271
+ export async function mockFetchDashScript(resource: string): Promise<string> {
272
+ if (dashScriptMocks.has(resource)) {
273
+ const value = dashScriptMocks.get(resource) ?? "";
274
+
275
+ return value;
276
+ }
277
+ throw new Error(`no mock found for \`init from-dash\` - ${resource}`);
278
+ }
279
+
280
+ /**
281
+ * Mock setter for usage within test blocks, companion helper to `mockFetchDashScript`
282
+ */
283
+ export function setMockFetchDashScript({
284
+ accountId,
285
+ fromDashScriptName,
286
+ mockResponse,
287
+ }: {
288
+ accountId: string;
289
+ fromDashScriptName: string;
290
+ mockResponse?: string;
291
+ }) {
292
+ dashScriptMocks.set(
293
+ `/accounts/${accountId}/workers/scripts/${fromDashScriptName}`,
294
+ mockResponse
295
+ );
263
296
  }
@@ -0,0 +1,8 @@
1
+ import { setMockResponse } from "./mock-cfetch";
2
+
3
+ export function mockGetZoneFromHostRequest(host: string, zone?: string) {
4
+ setMockResponse("/zones", (_uri, _init, queryParams) => {
5
+ expect(queryParams.get("name")).toEqual(host);
6
+ return zone ? [{ id: zone }] : [];
7
+ });
8
+ }
@@ -0,0 +1,7 @@
1
+ import { setMockResponse } from "./mock-cfetch";
2
+
3
+ export function mockCollectKnownRoutesRequest(
4
+ routes: { pattern: string; script: string }[]
5
+ ) {
6
+ setMockResponse(`/zones/:zoneId/workers/routes`, "GET", () => routes);
7
+ }
@@ -31,21 +31,21 @@ describe("wrangler", () => {
31
31
  "wrangler
32
32
 
33
33
  Commands:
34
- wrangler init [name] 📥 Create a wrangler.toml configuration file
35
- wrangler dev [script] 👂 Start a local server for developing your worker
36
- wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
37
- wrangler tail [name] 🦚 Starts a log tailing session for a published Worker.
38
- wrangler secret 🤫 Generate a secret that can be referenced in a Worker
39
- wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces
40
- wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
41
- wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
42
- wrangler pages ⚡️ Configure Cloudflare Pages
43
- wrangler r2 📦 Interact with an R2 store
44
- wrangler worker-namespace 📦 Interact with a worker namespace
45
- wrangler pubsub 📮 Interact and manage Pub/Sub Brokers
46
- wrangler login 🔓 Login to Cloudflare
47
- wrangler logout 🚪 Logout from Cloudflare
48
- wrangler whoami 🕵️ Retrieve your user info and test your auth config
34
+ wrangler init [name] 📥 Create a wrangler.toml configuration file
35
+ wrangler dev [script] 👂 Start a local server for developing your worker
36
+ wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
37
+ wrangler tail [worker] 🦚 Starts a log tailing session for a published Worker.
38
+ wrangler secret 🤫 Generate a secret that can be referenced in a Worker
39
+ wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces
40
+ wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
41
+ wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
42
+ wrangler pages ⚡️ Configure Cloudflare Pages
43
+ wrangler r2 📦 Interact with an R2 store
44
+ wrangler dispatch-namespace 📦 Interact with a dispatch namespace
45
+ wrangler pubsub 📮 Interact and manage Pub/Sub Brokers
46
+ wrangler login 🔓 Login to Cloudflare
47
+ wrangler logout 🚪 Logout from Cloudflare
48
+ wrangler whoami 🕵️ Retrieve your user info and test your auth config
49
49
 
50
50
  Flags:
51
51
  -c, --config Path to .toml configuration file [string]
@@ -70,21 +70,21 @@ describe("wrangler", () => {
70
70
  wrangler
71
71
 
72
72
  Commands:
73
- wrangler init [name] 📥 Create a wrangler.toml configuration file
74
- wrangler dev [script] 👂 Start a local server for developing your worker
75
- wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
76
- wrangler tail [name] 🦚 Starts a log tailing session for a published Worker.
77
- wrangler secret 🤫 Generate a secret that can be referenced in a Worker
78
- wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces
79
- wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
80
- wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
81
- wrangler pages ⚡️ Configure Cloudflare Pages
82
- wrangler r2 📦 Interact with an R2 store
83
- wrangler worker-namespace 📦 Interact with a worker namespace
84
- wrangler pubsub 📮 Interact and manage Pub/Sub Brokers
85
- wrangler login 🔓 Login to Cloudflare
86
- wrangler logout 🚪 Logout from Cloudflare
87
- wrangler whoami 🕵️ Retrieve your user info and test your auth config
73
+ wrangler init [name] 📥 Create a wrangler.toml configuration file
74
+ wrangler dev [script] 👂 Start a local server for developing your worker
75
+ wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
76
+ wrangler tail [worker] 🦚 Starts a log tailing session for a published Worker.
77
+ wrangler secret 🤫 Generate a secret that can be referenced in a Worker
78
+ wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces
79
+ wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
80
+ wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
81
+ wrangler pages ⚡️ Configure Cloudflare Pages
82
+ wrangler r2 📦 Interact with an R2 store
83
+ wrangler dispatch-namespace 📦 Interact with a dispatch namespace
84
+ wrangler pubsub 📮 Interact and manage Pub/Sub Brokers
85
+ wrangler login 🔓 Login to Cloudflare
86
+ wrangler logout 🚪 Logout from Cloudflare
87
+ wrangler whoami 🕵️ Retrieve your user info and test your auth config
88
88
 
89
89
  Flags:
90
90
  -c, --config Path to .toml configuration file [string]