wrangler 2.0.27 → 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.
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)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wrangler",
3
- "version": "2.0.27",
3
+ "version": "2.0.28",
4
4
  "description": "Command-line interface for all things Cloudflare Workers",
5
5
  "keywords": [
6
6
  "wrangler",
@@ -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: {},
@@ -1913,11 +1913,11 @@ describe("normalizeAndValidateConfig()", () => {
1913
1913
  });
1914
1914
  });
1915
1915
 
1916
- describe("[worker_namespaces]", () => {
1917
- 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", () => {
1918
1918
  const { config, diagnostics } = normalizeAndValidateConfig(
1919
1919
  {
1920
- worker_namespaces: [
1920
+ dispatch_namespaces: [
1921
1921
  {
1922
1922
  binding: "BINDING_1",
1923
1923
  namespace: "NAMESPACE_1",
@@ -1928,44 +1928,44 @@ describe("normalizeAndValidateConfig()", () => {
1928
1928
  { env: undefined }
1929
1929
  );
1930
1930
  expect(config).toEqual(
1931
- expect.not.objectContaining({ worker_namespaces: expect.anything })
1931
+ expect.not.objectContaining({ dispatch_namespaces: expect.anything })
1932
1932
  );
1933
1933
  expect(diagnostics.hasWarnings()).toBe(true);
1934
1934
  expect(diagnostics.hasErrors()).toBe(false);
1935
1935
  expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1936
1936
  "Processing wrangler configuration:
1937
- - \\"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."
1938
1938
  `);
1939
1939
  });
1940
1940
 
1941
- it("should error if worker_namespaces is not an array", () => {
1941
+ it("should error if dispatch_namespaces is not an array", () => {
1942
1942
  const { config, diagnostics } = normalizeAndValidateConfig(
1943
1943
  {
1944
- worker_namespaces: "just a string",
1944
+ dispatch_namespaces: "just a string",
1945
1945
  } as unknown as RawConfig,
1946
1946
  undefined,
1947
1947
  { env: undefined }
1948
1948
  );
1949
1949
 
1950
1950
  expect(config).toEqual(
1951
- expect.not.objectContaining({ worker_namespaces: expect.anything })
1951
+ expect.not.objectContaining({ dispatch_namespaces: expect.anything })
1952
1952
  );
1953
1953
  expect(diagnostics.hasWarnings()).toBe(true);
1954
1954
  expect(diagnostics.hasErrors()).toBe(true);
1955
1955
  expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1956
1956
  "Processing wrangler configuration:
1957
- - \\"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."
1958
1958
  `);
1959
1959
  expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1960
1960
  "Processing wrangler configuration:
1961
- - 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\\"."
1962
1962
  `);
1963
1963
  });
1964
1964
 
1965
- it("should error on non valid worker_namespaces", () => {
1965
+ it("should error on non valid dispatch_namespaces", () => {
1966
1966
  const { config, diagnostics } = normalizeAndValidateConfig(
1967
1967
  {
1968
- worker_namespaces: [
1968
+ dispatch_namespaces: [
1969
1969
  "a string",
1970
1970
  123,
1971
1971
  {
@@ -1973,17 +1973,17 @@ describe("normalizeAndValidateConfig()", () => {
1973
1973
  namespace: 456,
1974
1974
  },
1975
1975
  {
1976
- binding: "WORKER_NAMESPACE_BINDING_1",
1976
+ binding: "DISPATCH_NAMESPACE_BINDING_1",
1977
1977
  namespace: 456,
1978
1978
  },
1979
1979
  // this one is valid
1980
1980
  {
1981
- binding: "WORKER_NAMESPACE_BINDING_1",
1982
- namespace: "WORKER_NAMESPACE_BINDING_NAMESPACE_1",
1981
+ binding: "DISPATCH_NAMESPACE_BINDING_1",
1982
+ namespace: "DISPATCH_NAMESPACE_BINDING_NAMESPACE_1",
1983
1983
  },
1984
1984
  {
1985
1985
  binding: 123,
1986
- namespace: "WORKER_NAMESPACE_BINDING_SERVICE_1",
1986
+ namespace: "DISPATCH_NAMESPACE_BINDING_SERVICE_1",
1987
1987
  },
1988
1988
  {
1989
1989
  binding: 123,
@@ -1996,25 +1996,25 @@ describe("normalizeAndValidateConfig()", () => {
1996
1996
  );
1997
1997
  expect(config).toEqual(
1998
1998
  expect.not.objectContaining({
1999
- worker_namespaces: expect.anything,
1999
+ dispatch_namespaces: expect.anything,
2000
2000
  })
2001
2001
  );
2002
2002
  expect(diagnostics.hasWarnings()).toBe(true);
2003
2003
  expect(diagnostics.hasErrors()).toBe(true);
2004
2004
  expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2005
2005
  "Processing wrangler configuration:
2006
- - \\"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."
2007
2007
  `);
2008
2008
  expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2009
2009
  "Processing wrangler configuration:
2010
- - \\"worker_namespaces[0]\\" binding should be objects, but got \\"a string\\"
2011
- - \\"worker_namespaces[1]\\" binding should be objects, but got 123
2012
- - \\"worker_namespaces[2]\\" should have a string \\"binding\\" field but got {\\"binding\\":123,\\"namespace\\":456}.
2013
- - \\"worker_namespaces[2]\\" should have a string \\"namespace\\" field but got {\\"binding\\":123,\\"namespace\\":456}.
2014
- - \\"worker_namespaces[3]\\" should have a string \\"namespace\\" field but got {\\"binding\\":\\"WORKER_NAMESPACE_BINDING_1\\",\\"namespace\\":456}.
2015
- - \\"worker_namespaces[5]\\" should have a string \\"binding\\" field but got {\\"binding\\":123,\\"namespace\\":\\"WORKER_NAMESPACE_BINDING_SERVICE_1\\"}.
2016
- - \\"worker_namespaces[6]\\" should have a string \\"binding\\" field but got {\\"binding\\":123,\\"service\\":456}.
2017
- - \\"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}."
2018
2018
  `);
2019
2019
  });
2020
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]
@@ -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]
@@ -13,7 +13,9 @@ import {
13
13
  } from "./helpers/mock-cfetch";
14
14
  import { mockConsoleMethods, normalizeSlashes } from "./helpers/mock-console";
15
15
  import { mockConfirm } from "./helpers/mock-dialogs";
16
+ import { mockGetZoneFromHostRequest } from "./helpers/mock-get-zone-from-host";
16
17
  import { useMockIsTTY } from "./helpers/mock-istty";
18
+ import { mockCollectKnownRoutesRequest } from "./helpers/mock-known-routes";
17
19
  import { mockKeyListRequest } from "./helpers/mock-kv";
18
20
  import { mockGetMemberships, mockOAuthFlow } from "./helpers/mock-oauth-flow";
19
21
  import { runInTempDir } from "./helpers/run-in-tmp";
@@ -3615,6 +3617,32 @@ addEventListener('fetch', event => {});`
3615
3617
  "
3616
3618
  `);
3617
3619
  });
3620
+
3621
+ it("can be overridden with cli args", async () => {
3622
+ writeWranglerToml({
3623
+ main: "index.js",
3624
+ define: {
3625
+ abc: "123",
3626
+ },
3627
+ });
3628
+ fs.writeFileSync(
3629
+ "index.js",
3630
+ `
3631
+ console.log(abc);
3632
+ `
3633
+ );
3634
+ mockSubDomainRequest();
3635
+ mockUploadWorkerRequest();
3636
+ await runWrangler("publish --dry-run --outdir dist --define abc:789");
3637
+ expect(fs.readFileSync("dist/index.js", "utf-8")).toMatchInlineSnapshot(`
3638
+ "(() => {
3639
+ // index.js
3640
+ console.log(789);
3641
+ })();
3642
+ //# sourceMappingURL=index.js.map
3643
+ "
3644
+ `);
3645
+ });
3618
3646
  });
3619
3647
 
3620
3648
  describe("custom builds", () => {
@@ -5232,6 +5260,29 @@ addEventListener('fetch', event => {});`
5232
5260
  expect(std.err).toMatchInlineSnapshot(`""`);
5233
5261
  expect(std.warn).toMatchInlineSnapshot(`""`);
5234
5262
  });
5263
+
5264
+ it("should read vars passed as cli arguments", async () => {
5265
+ writeWranglerToml();
5266
+ writeWorkerSource();
5267
+ mockSubDomainRequest();
5268
+ mockUploadWorkerRequest();
5269
+ await runWrangler("publish index.js --var TEXT:sometext --var COUNT:1");
5270
+ expect(std).toMatchInlineSnapshot(`
5271
+ Object {
5272
+ "debug": "",
5273
+ "err": "",
5274
+ "out": "Your worker has access to the following bindings:
5275
+ - Vars:
5276
+ - TEXT: \\"(hidden)\\"
5277
+ - COUNT: \\"(hidden)\\"
5278
+ Total Upload: 0xx KiB / gzip: 0xx KiB
5279
+ Uploaded test-name (TIMINGS)
5280
+ Published test-name (TIMINGS)
5281
+ https://test-name.test-sub-domain.workers.dev",
5282
+ "warn": "",
5283
+ }
5284
+ `);
5285
+ });
5235
5286
  });
5236
5287
 
5237
5288
  describe("[r2_buckets]", () => {
@@ -5514,10 +5565,10 @@ addEventListener('fetch', event => {});`
5514
5565
  });
5515
5566
  });
5516
5567
 
5517
- describe("[worker_namespaces]", () => {
5518
- it("should support bindings to a worker namespace", async () => {
5568
+ describe("[dispatch_namespaces]", () => {
5569
+ it("should support bindings to a dispatch namespace", async () => {
5519
5570
  writeWranglerToml({
5520
- worker_namespaces: [
5571
+ dispatch_namespaces: [
5521
5572
  {
5522
5573
  binding: "foo",
5523
5574
  namespace: "Foo",
@@ -5538,7 +5589,7 @@ addEventListener('fetch', event => {});`
5538
5589
  await runWrangler("publish index.js");
5539
5590
  expect(std.out).toMatchInlineSnapshot(`
5540
5591
  "Your worker has access to the following bindings:
5541
- - Worker Namespaces:
5592
+ - dispatch namespaces:
5542
5593
  - foo: Foo
5543
5594
  Total Upload: 0xx KiB / gzip: 0xx KiB
5544
5595
  Uploaded test-name (TIMINGS)
@@ -5549,7 +5600,7 @@ addEventListener('fetch', event => {});`
5549
5600
  expect(std.warn).toMatchInlineSnapshot(`
5550
5601
  "▲ [WARNING] Processing wrangler.toml configuration:
5551
5602
 
5552
- - \\"worker_namespaces\\" fields are experimental and may change or break at any time.
5603
+ - \\"dispatch_namespaces\\" fields are experimental and may change or break at any time.
5553
5604
 
5554
5605
  "
5555
5606
  `);
@@ -6487,6 +6538,9 @@ function mockUploadWorkerRequest(
6487
6538
  } else {
6488
6539
  expect(metadata.body_part).toEqual("index.js");
6489
6540
  }
6541
+
6542
+ expect(metadata.keep_bindings).toEqual(["plain_text", "json"]);
6543
+
6490
6544
  if ("expectedBindings" in options) {
6491
6545
  expect(metadata.bindings).toEqual(expectedBindings);
6492
6546
  }
@@ -6622,19 +6676,6 @@ function mockUnauthorizedPublishRoutesRequest({
6622
6676
  );
6623
6677
  }
6624
6678
 
6625
- function mockCollectKnownRoutesRequest(
6626
- routes: { pattern: string; script: string }[]
6627
- ) {
6628
- setMockResponse(`/zones/:zoneId/workers/routes`, "GET", () => routes);
6629
- }
6630
-
6631
- function mockGetZoneFromHostRequest(host: string, zone: string) {
6632
- setMockResponse("/zones", (_uri, _init, queryParams) => {
6633
- expect(queryParams.get("name")).toEqual(host);
6634
- return [{ id: zone }];
6635
- });
6636
- }
6637
-
6638
6679
  function mockPublishRoutesFallbackRequest(route: {
6639
6680
  pattern: string;
6640
6681
  script: string;
@@ -3,7 +3,9 @@ import { Headers, Request } from "undici";
3
3
  import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
4
4
  import { setMockResponse, unsetAllMocks } from "./helpers/mock-cfetch";
5
5
  import { mockConsoleMethods } from "./helpers/mock-console";
6
+ import { mockGetZoneFromHostRequest } from "./helpers/mock-get-zone-from-host";
6
7
  import { useMockIsTTY } from "./helpers/mock-istty";
8
+ import { mockCollectKnownRoutesRequest } from "./helpers/mock-known-routes";
7
9
  import { runInTempDir } from "./helpers/run-in-tmp";
8
10
  import { runWrangler } from "./helpers/run-wrangler";
9
11
  import type {
@@ -53,6 +55,38 @@ describe("tail", () => {
53
55
  api.ws.close();
54
56
  expect(api.requests.deletion.count).toStrictEqual(1);
55
57
  });
58
+ it("should connect to the worker assigned to a given route", async () => {
59
+ const api = mockWebsocketAPIs();
60
+ expect(api.requests.creation.count).toStrictEqual(0);
61
+
62
+ mockGetZoneFromHostRequest("example.com", "test-zone");
63
+ mockCollectKnownRoutesRequest([
64
+ {
65
+ pattern: "example.com/*",
66
+ script: "test-worker",
67
+ },
68
+ ]);
69
+ await runWrangler("tail example.com/*");
70
+
71
+ await expect(api.ws.connected).resolves.toBeTruthy();
72
+ expect(api.requests.creation.count).toStrictEqual(1);
73
+ expect(api.requests.deletion.count).toStrictEqual(0);
74
+
75
+ api.ws.close();
76
+ expect(api.requests.deletion.count).toStrictEqual(1);
77
+ });
78
+
79
+ it("should error if a given route is not assigned to the user's zone", async () => {
80
+ mockGetZoneFromHostRequest("example.com", "test-zone");
81
+ mockCollectKnownRoutesRequest([]);
82
+
83
+ await expect(runWrangler("tail example.com/*")).rejects.toThrow();
84
+ });
85
+ it("should error if a given route is not within the user's zone", async () => {
86
+ mockGetZoneFromHostRequest("example.com");
87
+
88
+ await expect(runWrangler("tail example.com/*")).rejects.toThrow();
89
+ });
56
90
 
57
91
  it("creates and then delete tails: legacy envs", async () => {
58
92
  const api = mockWebsocketAPIs("some-env", true);
@@ -1,4 +1,4 @@
1
- // this test has to be run with a version of node.js older than 16.7 to pass
1
+ // this test has to be run with a version of node.js older than 16.13 to pass
2
2
 
3
3
  const { spawn } = require("child_process");
4
4
  const path = require("path");
@@ -11,7 +11,7 @@ const wranglerProcess = spawn(
11
11
  { stdio: "pipe" }
12
12
  );
13
13
 
14
- const messageToMatch = "Wrangler requires at least node.js v16.7.0";
14
+ const messageToMatch = "Wrangler requires at least node.js v16.13.0";
15
15
 
16
16
  wranglerProcess.once("exit", (code) => {
17
17
  try {
@@ -25,7 +25,7 @@ wranglerProcess.once("exit", (code) => {
25
25
  } catch (err) {
26
26
  console.error("Error:", err);
27
27
  throw new Error(
28
- "This test has to be run with a version of node.js under 16.7 to pass"
28
+ "This test has to be run with a version of node.js under 16.13 to pass"
29
29
  );
30
30
  }
31
31
  });