wrangler 2.9.1 → 2.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +3 -3
  2. package/miniflare-dist/index.mjs +1 -1
  3. package/package.json +8 -8
  4. package/src/__tests__/configuration.test.ts +70 -0
  5. package/src/__tests__/d1/d1.test.ts +2 -2
  6. package/src/__tests__/d1/execute.test.ts +64 -0
  7. package/src/__tests__/d1/migrate.test.ts +14 -0
  8. package/src/__tests__/deployments.test.ts +40 -16
  9. package/src/__tests__/dev.test.tsx +3 -3
  10. package/src/__tests__/helpers/msw/handlers/deployments.ts +40 -16
  11. package/src/__tests__/helpers/string-dynamic-values-matcher.ts +28 -0
  12. package/src/__tests__/index.test.ts +2 -0
  13. package/src/__tests__/kv.test.ts +8 -8
  14. package/src/__tests__/middleware.test.ts +65 -0
  15. package/src/__tests__/mtls-certificates.test.ts +585 -0
  16. package/src/__tests__/pages/functions-build.test.ts +402 -0
  17. package/src/__tests__/pages/pages.test.ts +7 -7
  18. package/src/__tests__/pages/publish.test.ts +525 -1
  19. package/src/__tests__/publish.test.ts +58 -27
  20. package/src/__tests__/queues.test.ts +2 -2
  21. package/src/__tests__/secret.test.ts +4 -4
  22. package/src/__tests__/tsconfig.tsbuildinfo +1 -1
  23. package/src/__tests__/user.test.ts +1 -1
  24. package/src/__tests__/whoami.test.tsx +1 -1
  25. package/src/api/index.ts +8 -0
  26. package/src/api/mtls-certificate.ts +148 -0
  27. package/src/api/pages/create-worker-bundle-contents.ts +75 -0
  28. package/src/api/pages/publish.tsx +52 -8
  29. package/src/bundle.ts +6 -5
  30. package/src/config/config.ts +7 -7
  31. package/src/config/environment.ts +9 -2
  32. package/src/config/index.ts +13 -0
  33. package/src/config/validation.ts +50 -3
  34. package/src/create-worker-upload-form.ts +9 -0
  35. package/src/d1/execute.tsx +123 -90
  36. package/src/d1/migrations/apply.tsx +29 -24
  37. package/src/d1/migrations/create.tsx +7 -7
  38. package/src/d1/migrations/helpers.ts +63 -38
  39. package/src/d1/migrations/list.tsx +19 -16
  40. package/src/d1/migrations/options.ts +6 -1
  41. package/src/d1/types.ts +1 -0
  42. package/src/d1/utils.ts +2 -1
  43. package/src/deployments.ts +62 -39
  44. package/src/dev/dev.tsx +1 -15
  45. package/src/dev/remote.tsx +2 -2
  46. package/src/dev.tsx +9 -6
  47. package/src/generate/index.ts +1 -1
  48. package/src/index.ts +15 -5
  49. package/src/miniflare-cli/assets.ts +1 -1
  50. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -1
  51. package/src/mtls-certificate/cli.ts +155 -0
  52. package/src/pages/build.ts +103 -23
  53. package/src/pages/buildFunctions.ts +32 -31
  54. package/src/pages/dev.ts +4 -2
  55. package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
  56. package/src/pages/publish.tsx +12 -1
  57. package/src/pages/utils.ts +1 -1
  58. package/src/publish/publish.ts +3 -2
  59. package/src/secret/index.ts +1 -0
  60. package/src/sites.ts +1 -1
  61. package/src/tail/filters.ts +1 -1
  62. package/src/user/user.ts +4 -3
  63. package/src/worker.ts +6 -0
  64. package/templates/format-dev-errors.ts +1 -0
  65. package/templates/new-worker.ts +3 -0
  66. package/templates/serve-static-assets.ts +1 -0
  67. package/templates/service-bindings-module-facade.js +1 -0
  68. package/templates/tsconfig.tsbuildinfo +1 -1
  69. package/wrangler-dist/cli.d.ts +82 -2
  70. package/wrangler-dist/cli.js +1501 -1031
package/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  <h1 align="center"> ⛅️ wrangler </h1>
2
2
  <section align="center" id="shieldio-badges">
3
3
  <a href="https://www.npmjs.com/package/wrangler"><img alt="npm" src="https://img.shields.io/npm/dw/wrangler?style=flat-square"></a>
4
- <img alt="GitHub contributors" src="https://img.shields.io/github/contributors/cloudflare/wrangler2?style=flat-square">
5
- <img alt="GitHub commit activity (branch)" src="https://img.shields.io/github/commit-activity/w/cloudflare/wrangler2/main?style=flat-square">
4
+ <img alt="GitHub contributors" src="https://img.shields.io/github/contributors/cloudflare/workers-sdk?style=flat-square">
5
+ <img alt="GitHub commit activity (branch)" src="https://img.shields.io/github/commit-activity/w/cloudflare/workers-sdk/main?style=flat-square">
6
6
  <a href="https://discord.gg/CloudflareDev"><img alt="Discord" src="https://img.shields.io/discord/595317990191398933?color=%23F48120&style=flat-square"></a>
7
7
  </section>
8
8
 
9
- > This package is for wrangler v2.x, released first in May 2022. If you're looking for v1.x of the `@cloudflare/wrangler` package, visit https://www.npmjs.com/package/@cloudflare/wrangler / https://github.com/cloudflare/wrangler.
9
+ > This package is for wrangler v2.x, released first in May 2022. If you're looking for v1.x of the `@cloudflare/wrangler` package, visit https://www.npmjs.com/package/@cloudflare/wrangler / https://github.com/cloudflare/wrangler-legacy.
10
10
 
11
11
  `wrangler` is a command line tool for building [Cloudflare Workers](https://workers.cloudflare.com/).
12
12
 
@@ -6152,7 +6152,7 @@ async function generateAssetsFetch(directory, log, tre) {
6152
6152
  const filepath = assetKeyEntryMap.get(assetKey);
6153
6153
  if (!filepath) {
6154
6154
  throw new Error(
6155
- "Could not fetch asset. Please file an issue on GitHub (https://github.com/cloudflare/wrangler2/issues/new/choose) with reproduction steps."
6155
+ "Could not fetch asset. Please file an issue on GitHub (https://github.com/cloudflare/workers-sdk/issues/new/choose) with reproduction steps."
6156
6156
  );
6157
6157
  }
6158
6158
  const body = readFileSync5(filepath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wrangler",
3
- "version": "2.9.1",
3
+ "version": "2.10.0",
4
4
  "description": "Command-line interface for all things Cloudflare Workers",
5
5
  "keywords": [
6
6
  "wrangler",
@@ -24,13 +24,13 @@
24
24
  "http",
25
25
  "cli"
26
26
  ],
27
- "homepage": "https://github.com/cloudflare/wrangler2#readme",
27
+ "homepage": "https://github.com/cloudflare/workers-sdk#readme",
28
28
  "bugs": {
29
- "url": "https://github.com/cloudflare/wrangler2/issues"
29
+ "url": "https://github.com/cloudflare/workers-sdk/issues"
30
30
  },
31
31
  "repository": {
32
32
  "type": "git",
33
- "url": "https://github.com/cloudflare/wrangler2.git",
33
+ "url": "https://github.com/cloudflare/workers-sdk.git",
34
34
  "directory": "packages/wrangler"
35
35
  },
36
36
  "license": "MIT OR Apache-2.0",
@@ -100,13 +100,13 @@
100
100
  "@cloudflare/kv-asset-handler": "^0.2.0",
101
101
  "@esbuild-plugins/node-globals-polyfill": "^0.1.1",
102
102
  "@esbuild-plugins/node-modules-polyfill": "^0.1.4",
103
- "@miniflare/core": "2.11.0",
104
- "@miniflare/d1": "2.11.0",
105
- "@miniflare/durable-objects": "2.11.0",
103
+ "@miniflare/core": "2.12.0",
104
+ "@miniflare/d1": "2.12.0",
105
+ "@miniflare/durable-objects": "2.12.0",
106
106
  "blake3-wasm": "^2.1.5",
107
107
  "chokidar": "^3.5.3",
108
108
  "esbuild": "0.16.3",
109
- "miniflare": "2.11.0",
109
+ "miniflare": "2.12.0",
110
110
  "nanoid": "^3.3.3",
111
111
  "path-to-regexp": "^6.2.0",
112
112
  "selfsigned": "^2.0.1",
@@ -68,6 +68,7 @@ describe("normalizeAndValidateConfig()", () => {
68
68
  bindings: [],
69
69
  },
70
70
  dispatch_namespaces: [],
71
+ mtls_certificates: [],
71
72
  usage_model: undefined,
72
73
  vars: {},
73
74
  define: {},
@@ -2190,6 +2191,75 @@ describe("normalizeAndValidateConfig()", () => {
2190
2191
  });
2191
2192
  });
2192
2193
 
2194
+ describe("[mtls_certificates]", () => {
2195
+ it("should error if mtls_certificates is not an array", () => {
2196
+ const { diagnostics } = normalizeAndValidateConfig(
2197
+ {
2198
+ mtls_certificates: "just a string",
2199
+ } as unknown as RawConfig,
2200
+ undefined,
2201
+ { env: undefined }
2202
+ );
2203
+
2204
+ expect(diagnostics.hasWarnings()).toBe(false);
2205
+ expect(diagnostics.hasErrors()).toBe(true);
2206
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2207
+ "Processing wrangler configuration:
2208
+ - The field \\"mtls_certificates\\" should be an array but got \\"just a string\\"."
2209
+ `);
2210
+ });
2211
+
2212
+ it("should error on non valid mtls_certificates", () => {
2213
+ const { diagnostics } = normalizeAndValidateConfig(
2214
+ {
2215
+ mtls_certificates: [
2216
+ "a string",
2217
+ 123,
2218
+ false,
2219
+ {
2220
+ binding: 123,
2221
+ namespace: 123,
2222
+ },
2223
+ {
2224
+ binding: "CERT_ONE",
2225
+ id: "1234",
2226
+ },
2227
+ {
2228
+ binding: "CERT_TWO",
2229
+ certificate_id: 1234,
2230
+ },
2231
+ // this one is valid
2232
+ {
2233
+ binding: "CERT_THREE",
2234
+ certificate_id: "1234",
2235
+ },
2236
+ {
2237
+ binding: true,
2238
+ service: "1234",
2239
+ },
2240
+ ],
2241
+ } as unknown as RawConfig,
2242
+ undefined,
2243
+ { env: undefined }
2244
+ );
2245
+
2246
+ expect(diagnostics.hasWarnings()).toBe(false);
2247
+ expect(diagnostics.hasErrors()).toBe(true);
2248
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2249
+ "Processing wrangler configuration:
2250
+ - \\"mtls_certificates\\" bindings should be objects, but got \\"a string\\"
2251
+ - \\"mtls_certificates\\" bindings should be objects, but got 123
2252
+ - \\"mtls_certificates\\" bindings should be objects, but got false
2253
+ - \\"mtls_certificates[3]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":123,\\"namespace\\":123}.
2254
+ - \\"mtls_certificates[3]\\" bindings should have a string \\"certificate_id\\" field but got {\\"binding\\":123,\\"namespace\\":123}.
2255
+ - \\"mtls_certificates[4]\\" bindings should have a string \\"certificate_id\\" field but got {\\"binding\\":\\"CERT_ONE\\",\\"id\\":\\"1234\\"}.
2256
+ - \\"mtls_certificates[5]\\" bindings should have a string \\"certificate_id\\" field but got {\\"binding\\":\\"CERT_TWO\\",\\"certificate_id\\":1234}.
2257
+ - \\"mtls_certificates[7]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":true,\\"service\\":\\"1234\\"}.
2258
+ - \\"mtls_certificates[7]\\" bindings should have a string \\"certificate_id\\" field but got {\\"binding\\":true,\\"service\\":\\"1234\\"}."
2259
+ `);
2260
+ });
2261
+ });
2262
+
2193
2263
  describe("[unsafe.bindings]", () => {
2194
2264
  it("should error if unsafe is an array", () => {
2195
2265
  const { diagnostics } = normalizeAndValidateConfig(
@@ -33,7 +33,7 @@ describe("d1", () => {
33
33
 
34
34
  --------------------
35
35
  🚧 D1 is currently in open alpha and is not recommended for production data and traffic
36
- 🚧 Please report any bugs to https://github.com/cloudflare/wrangler2/issues/new/choose
36
+ 🚧 Please report any bugs to https://github.com/cloudflare/workers-sdk/issues/new/choose
37
37
  🚧 To request features, visit https://community.cloudflare.com/c/developers/d1
38
38
  🚧 To give feedback, visit https://discord.gg/cloudflaredev
39
39
  --------------------"
@@ -73,7 +73,7 @@ describe("d1", () => {
73
73
 
74
74
  --------------------
75
75
  🚧 D1 is currently in open alpha and is not recommended for production data and traffic
76
- 🚧 Please report any bugs to https://github.com/cloudflare/wrangler2/issues/new/choose
76
+ 🚧 Please report any bugs to https://github.com/cloudflare/workers-sdk/issues/new/choose
77
77
  🚧 To request features, visit https://community.cloudflare.com/c/developers/d1
78
78
  🚧 To give feedback, visit https://discord.gg/cloudflaredev
79
79
  --------------------"
@@ -0,0 +1,64 @@
1
+ import { useMockIsTTY } from "../helpers/mock-istty";
2
+ import { runInTempDir } from "../helpers/run-in-tmp";
3
+ import { runWrangler } from "../helpers/run-wrangler";
4
+ import writeWranglerToml from "../helpers/write-wrangler-toml";
5
+
6
+ describe("execute", () => {
7
+ runInTempDir();
8
+ const { setIsTTY } = useMockIsTTY();
9
+
10
+ it("should require login when running against prod", async () => {
11
+ setIsTTY(false);
12
+ writeWranglerToml({
13
+ d1_databases: [
14
+ { binding: "DATABASE", database_name: "db", database_id: "xxxx" },
15
+ ],
16
+ });
17
+
18
+ await expect(
19
+ runWrangler("d1 execute --command 'select 1;'")
20
+ ).rejects.toThrowError(
21
+ `In a non-interactive environment, it's necessary to set a CLOUDFLARE_API_TOKEN environment variable for wrangler to work. Please go to https://developers.cloudflare.com/api/tokens/create/ for instructions on how to create an api token, and assign its value to CLOUDFLARE_API_TOKEN.`
22
+ );
23
+ });
24
+
25
+ it("should expect either --command or --file", async () => {
26
+ setIsTTY(false);
27
+ writeWranglerToml({
28
+ d1_databases: [
29
+ { binding: "DATABASE", database_name: "db", database_id: "xxxx" },
30
+ ],
31
+ });
32
+
33
+ await expect(runWrangler("d1 execute db")).rejects.toThrowError(
34
+ `Error: must provide --command or --file`
35
+ );
36
+ });
37
+
38
+ it("should reject the use of --preview with --local", async () => {
39
+ setIsTTY(false);
40
+ writeWranglerToml({
41
+ d1_databases: [
42
+ { binding: "DATABASE", database_name: "db", database_id: "xxxx" },
43
+ ],
44
+ });
45
+
46
+ await expect(
47
+ runWrangler(`d1 execute db --command "select;" --local --preview`)
48
+ ).rejects.toThrowError(`Error: can't use --preview with --local`);
49
+ });
50
+
51
+ it("should expect --local when using --persist-to", async () => {
52
+ setIsTTY(false);
53
+ writeWranglerToml({
54
+ d1_databases: [
55
+ { binding: "DATABASE", database_name: "db", database_id: "xxxx" },
56
+ ],
57
+ });
58
+ await runWrangler("d1 migrations create db test");
59
+
60
+ await expect(
61
+ runWrangler("d1 migrations apply --local db --preview")
62
+ ).rejects.toThrowError(`Error: can't use --preview with --local`);
63
+ });
64
+ });
@@ -61,6 +61,20 @@ describe("migrate", () => {
61
61
  `No migrations present at ${cwd().replaceAll("\\", "/")}/migrations.`
62
62
  );
63
63
  });
64
+
65
+ it("should reject the use of --preview with --local", async () => {
66
+ setIsTTY(false);
67
+ writeWranglerToml({
68
+ d1_databases: [
69
+ { binding: "DATABASE", database_name: "db", database_id: "xxxx" },
70
+ ],
71
+ });
72
+ await runWrangler("d1 migrations create db test");
73
+
74
+ await expect(
75
+ runWrangler("d1 migrations apply --local db --preview")
76
+ ).rejects.toThrowError(`Error: can't use --preview with --local`);
77
+ });
64
78
  });
65
79
 
66
80
  describe("list", () => {
@@ -62,18 +62,30 @@ describe("deployments", () => {
62
62
 
63
63
  await runWrangler("deployments");
64
64
  expect(std.out).toMatchInlineSnapshot(`
65
- "🚧\`wrangler deployments\` is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose
65
+ "🚧\`wrangler deployments\` is a beta command. Please report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose
66
66
 
67
67
 
68
- Deployment ID: Galaxy-Class
69
- Created on: 2021-01-01T00:00:00.000000Z
70
- Author: Jean-Luc-Picard@federation.org
71
- Source: 🤠 Wrangler
68
+ Deployment ID: Constitution-Class
69
+ Created on: 2021-01-01T00:00:00.000000Z
70
+ Author: Jean-Luc-Picard@federation.org
71
+ Trigger: Upload from Wrangler 🤠
72
+
73
+ Deployment ID: Intrepid-Class
74
+ Created on: 2021-02-02T00:00:00.000000Z
75
+ Author: Kathryn-Janeway@federation.org
76
+ Trigger: Rollback from Wrangler 🤠
77
+ Rollback from: MOCK-DEPLOYMENT-ID-1111
72
78
 
73
79
  Deployment ID: Intrepid-Class
74
- Created on: 2021-02-02T00:00:00.000000Z
75
- Author: Kathryn-Janeway@federation.org
76
- Source: 🤠 Wrangler
80
+ Created on: 2021-02-03T00:00:00.000000Z
81
+ Author: Kathryn-Janeway@federation.org
82
+ Trigger: Wrangler 🤠
83
+
84
+ Deployment ID: Galaxy-Class
85
+ Created on: 2021-01-04T00:00:00.000000Z
86
+ Author: Jean-Luc-Picard@federation.org
87
+ Trigger: Rollback from Wrangler 🤠
88
+ Rollback from: MOCK-DEPLOYMENT-ID-2222
77
89
  🟩 Active"
78
90
  `);
79
91
  });
@@ -81,18 +93,30 @@ describe("deployments", () => {
81
93
  it("should log deployments for script with passed in name option", async () => {
82
94
  await runWrangler("deployments --name something-else");
83
95
  expect(std.out).toMatchInlineSnapshot(`
84
- "🚧\`wrangler deployments\` is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose
96
+ "🚧\`wrangler deployments\` is a beta command. Please report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose
85
97
 
86
98
 
87
- Deployment ID: Galaxy-Class
88
- Created on: 2021-01-01T00:00:00.000000Z
89
- Author: Jean-Luc-Picard@federation.org
90
- Source: 🤠 Wrangler
99
+ Deployment ID: Constitution-Class
100
+ Created on: 2021-01-01T00:00:00.000000Z
101
+ Author: Jean-Luc-Picard@federation.org
102
+ Trigger: Upload from Wrangler 🤠
103
+
104
+ Deployment ID: Intrepid-Class
105
+ Created on: 2021-02-02T00:00:00.000000Z
106
+ Author: Kathryn-Janeway@federation.org
107
+ Trigger: Rollback from Wrangler 🤠
108
+ Rollback from: MOCK-DEPLOYMENT-ID-1111
91
109
 
92
110
  Deployment ID: Intrepid-Class
93
- Created on: 2021-02-02T00:00:00.000000Z
94
- Author: Kathryn-Janeway@federation.org
95
- Source: 🤠 Wrangler
111
+ Created on: 2021-02-03T00:00:00.000000Z
112
+ Author: Kathryn-Janeway@federation.org
113
+ Trigger: Wrangler 🤠
114
+
115
+ Deployment ID: Galaxy-Class
116
+ Created on: 2021-01-04T00:00:00.000000Z
117
+ Author: Jean-Luc-Picard@federation.org
118
+ Trigger: Rollback from Wrangler 🤠
119
+ Rollback from: MOCK-DEPLOYMENT-ID-2222
96
120
  🟩 Active"
97
121
  `);
98
122
  });
@@ -136,7 +136,7 @@ describe("wrangler dev", () => {
136
136
 
137
137
  expect(std.out).toMatchInlineSnapshot(`
138
138
  "
139
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
139
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
140
140
  `);
141
141
  expect(std.err).toMatchInlineSnapshot(`
142
142
  "X [ERROR] Missing entry-point: The entry-point should be specified via the command line (e.g. \`wrangler dev path/to/script\`) or the \`main\` config field.
@@ -698,7 +698,7 @@ describe("wrangler dev", () => {
698
698
  expect(std.out).toMatchInlineSnapshot(`
699
699
  "Running custom build: node -e \\"console.log('custom build');\\"
700
700
 
701
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
701
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
702
702
  `);
703
703
  expect(std.err).toMatchInlineSnapshot(`
704
704
  "X [ERROR] The expected output file at \\"index.js\\" was not found after running custom build: node -e \\"console.log('custom build');\\".
@@ -774,7 +774,7 @@ describe("wrangler dev", () => {
774
774
  "▲ [WARNING] Setting upstream-protocol to http is not currently implemented.
775
775
 
776
776
  If this is required in your project, please add your use case to the following issue:
777
- https://github.com/cloudflare/wrangler2/issues/583.
777
+ https://github.com/cloudflare/workers-sdk/issues/583.
778
778
 
779
779
  "
780
780
  `);
@@ -1,6 +1,25 @@
1
1
  import { rest } from "msw";
2
2
  import { createFetchResult } from "../index";
3
3
 
4
+ const latestDeployment = {
5
+ id: "Galaxy-Class",
6
+ number: "1701-E",
7
+ annotations: {
8
+ "workers/triggered_by": "rollback",
9
+ "workers/rollback_from": "MOCK-DEPLOYMENT-ID-2222",
10
+ },
11
+ metadata: {
12
+ author_id: "Picard-Gamma-6-0-7-3",
13
+ author_email: "Jean-Luc-Picard@federation.org",
14
+ source: "wrangler",
15
+ created_on: "2021-01-04T00:00:00.000000Z",
16
+ modified_on: "2021-01-04T00:00:00.000000Z",
17
+ },
18
+ resources: {
19
+ script: "MOCK-TAG",
20
+ bindings: [],
21
+ },
22
+ };
4
23
  export const mswSuccessDeployments = [
5
24
  rest.get(
6
25
  "*/accounts/:accountId/workers/deployments/by-script/:scriptTag",
@@ -8,25 +27,14 @@ export const mswSuccessDeployments = [
8
27
  response.once(
9
28
  context.json(
10
29
  createFetchResult({
11
- latest: {
12
- id: "Galaxy-Class",
13
- number: "1701-E",
14
- metadata: {
15
- author_id: "Picard-Gamma-6-0-7-3",
16
- author_email: "Jean-Luc-Picard@federation.org",
17
- source: "wrangler",
18
- created_on: "2021-01-01T00:00:00.000000Z",
19
- modified_on: "2021-01-01T00:00:00.000000Z",
20
- },
21
- resources: {
22
- script: "MOCK-TAG",
23
- bindings: [],
24
- },
25
- },
30
+ latest: latestDeployment,
26
31
  items: [
27
32
  {
28
- id: "Galaxy-Class",
33
+ id: "Constitution-Class",
29
34
  number: "1701-E",
35
+ annotations: {
36
+ "workers/triggered_by": "upload",
37
+ },
30
38
  metadata: {
31
39
  author_id: "Picard-Gamma-6-0-7-3",
32
40
  author_email: "Jean-Luc-Picard@federation.org",
@@ -38,6 +46,10 @@ export const mswSuccessDeployments = [
38
46
  {
39
47
  id: "Intrepid-Class",
40
48
  number: "NCC-74656",
49
+ annotations: {
50
+ "workers/triggered_by": "rollback",
51
+ "workers/rollback_from": "MOCK-DEPLOYMENT-ID-1111",
52
+ },
41
53
  metadata: {
42
54
  author_id: "Kathryn-Jane-Gamma-6-0-7-3",
43
55
  author_email: "Kathryn-Janeway@federation.org",
@@ -46,6 +58,18 @@ export const mswSuccessDeployments = [
46
58
  modified_on: "2021-02-02T00:00:00.000000Z",
47
59
  },
48
60
  },
61
+ {
62
+ id: "Intrepid-Class",
63
+ number: "NCC-74656",
64
+ metadata: {
65
+ author_id: "Kathryn-Jane-Gamma-6-0-7-3",
66
+ author_email: "Kathryn-Janeway@federation.org",
67
+ source: "wrangler",
68
+ created_on: "2021-02-03T00:00:00.000000Z",
69
+ modified_on: "2021-02-03T00:00:00.000000Z",
70
+ },
71
+ },
72
+ latestDeployment,
49
73
  ],
50
74
  })
51
75
  )
@@ -0,0 +1,28 @@
1
+ export type PatternReplacementPair = [string | RegExp, string];
2
+
3
+ /**
4
+ * Sometimes, we might need to test strings that contain dynamic |
5
+ * random | generated data (such as file hashes, IDs, etc.).
6
+ *
7
+ * This helper function replaces the dynamic parts of such strings with
8
+ * static values, thus enabling us to properly test the contents of the
9
+ * string.
10
+ *
11
+ * see https://jestjs.io/docs/snapshot-testing#property-matchers
12
+ */
13
+ export function replaceRandomWithConstantData(
14
+ stringWithRandomData: string,
15
+ patternReplacementPairs: Array<PatternReplacementPair>
16
+ ) {
17
+ let stringWithConstantData = stringWithRandomData;
18
+
19
+ patternReplacementPairs.forEach(
20
+ (pair) =>
21
+ (stringWithConstantData = stringWithConstantData.replace(
22
+ pair[0], // pattern
23
+ pair[1] // replacement
24
+ ))
25
+ );
26
+
27
+ return stringWithConstantData;
28
+ }
@@ -50,6 +50,7 @@ describe("wrangler", () => {
50
50
  wrangler dispatch-namespace 📦 Interact with a dispatch namespace
51
51
  wrangler d1 🗄 Interact with a D1 database
52
52
  wrangler pubsub 📮 Interact and manage Pub/Sub Brokers
53
+ wrangler mtls-certificate 🪪 Manage certificates used for mTLS connections
53
54
  wrangler login 🔓 Login to Cloudflare
54
55
  wrangler logout 🚪 Logout from Cloudflare
55
56
  wrangler whoami 🕵️ Retrieve your user info and test your auth config
@@ -99,6 +100,7 @@ describe("wrangler", () => {
99
100
  wrangler dispatch-namespace 📦 Interact with a dispatch namespace
100
101
  wrangler d1 🗄 Interact with a D1 database
101
102
  wrangler pubsub 📮 Interact and manage Pub/Sub Brokers
103
+ wrangler mtls-certificate 🪪 Manage certificates used for mTLS connections
102
104
  wrangler login 🔓 Login to Cloudflare
103
105
  wrangler logout 🚪 Logout from Cloudflare
104
106
  wrangler whoami 🕵️ Retrieve your user info and test your auth config
@@ -747,7 +747,7 @@ describe("wrangler", () => {
747
747
 
748
748
  expect(std.out).toMatchInlineSnapshot(`
749
749
  "
750
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
750
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
751
751
  `);
752
752
  expect(std.err).toMatchInlineSnapshot(`
753
753
  "X [ERROR] A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
@@ -769,7 +769,7 @@ describe("wrangler", () => {
769
769
  );
770
770
  expect(std.out).toMatchInlineSnapshot(`
771
771
  "
772
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
772
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
773
773
  `);
774
774
  expect(std.err).toMatchInlineSnapshot(`
775
775
  "X [ERROR] someBinding has both a namespace ID and a preview ID. Specify \\"--preview\\" or \\"--preview false\\" to avoid writing data to the wrong namespace.
@@ -940,7 +940,7 @@ describe("wrangler", () => {
940
940
  `);
941
941
  expect(std.out).toMatchInlineSnapshot(`
942
942
  "
943
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
943
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
944
944
  `);
945
945
  });
946
946
  });
@@ -1190,7 +1190,7 @@ describe("wrangler", () => {
1190
1190
  );
1191
1191
  expect(std.out).toMatchInlineSnapshot(`
1192
1192
  "
1193
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
1193
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
1194
1194
  `);
1195
1195
  expect(std.err).toMatchInlineSnapshot(`
1196
1196
  "X [ERROR] A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
@@ -1453,7 +1453,7 @@ describe("wrangler", () => {
1453
1453
  `);
1454
1454
  expect(std.out).toMatchInlineSnapshot(`
1455
1455
  "
1456
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
1456
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
1457
1457
  `);
1458
1458
  expect(std.warn).toMatchInlineSnapshot(`""`);
1459
1459
  });
@@ -1515,7 +1515,7 @@ describe("wrangler", () => {
1515
1515
 
1516
1516
  expect(std.out).toMatchInlineSnapshot(`
1517
1517
  "
1518
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
1518
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
1519
1519
  `);
1520
1520
  expect(std.warn).toMatchInlineSnapshot(`
1521
1521
  "▲ [WARNING] Unexpected key-value properties in \\"keys.json\\".
@@ -1657,7 +1657,7 @@ describe("wrangler", () => {
1657
1657
  `);
1658
1658
  expect(std.out).toMatchInlineSnapshot(`
1659
1659
  "
1660
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
1660
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
1661
1661
  `);
1662
1662
  expect(std.warn).toMatchInlineSnapshot(`""`);
1663
1663
  });
@@ -1682,7 +1682,7 @@ describe("wrangler", () => {
1682
1682
  `);
1683
1683
  expect(std.out).toMatchInlineSnapshot(`
1684
1684
  "
1685
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
1685
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
1686
1686
  `);
1687
1687
  expect(std.warn).toMatchInlineSnapshot(`""`);
1688
1688
  });
@@ -748,3 +748,68 @@ describe("unchanged functionality when wrapping with middleware", () => {
748
748
  });
749
749
  });
750
750
  });
751
+
752
+ describe("multiple middleware", () => {
753
+ it("should respond correctly with D1 databases, scheduled testing, and formatted dev errors", async () => {
754
+ // Kitchen sink test to check interaction between multiple middlewares
755
+ const scriptContent = `
756
+ export default {
757
+ async fetch(request, env, ctx) {
758
+ const { pathname } = new URL(request.url);
759
+ if (pathname === "/setup") {
760
+ await env.DB.exec("CREATE TABLE IF NOT EXISTS test (id INTEGER PRIMARY KEY, value TEXT);");
761
+ return new Response(null, { status: 204 });
762
+ } else if (pathname === "/query") {
763
+ const rows = await env.DB.prepare("SELECT * FROM test;").all();
764
+ return Response.json(rows.results);
765
+ }
766
+ throw new Error("Not found!");
767
+ },
768
+ async scheduled(controller, env, ctx) {
769
+ const stmt = await env.DB.prepare("INSERT INTO test (id, value) VALUES (?, ?)");
770
+ await stmt.bind(1, "one").run();
771
+ }
772
+ }
773
+ `;
774
+ fs.writeFileSync("index.js", scriptContent);
775
+
776
+ const originalFormatErrors = process.env.FORMAT_WRANGLER_ERRORS;
777
+ process.env.FORMAT_WRANGLER_ERRORS = "true";
778
+
779
+ const worker = await unstable_dev("index.js", {
780
+ experimental: {
781
+ disableExperimentalWarning: true,
782
+ disableDevRegistry: true,
783
+ testScheduled: true,
784
+ d1Databases: [
785
+ {
786
+ binding: "DB",
787
+ database_name: "db",
788
+ database_id: "00000000-0000-0000-0000-000000000000",
789
+ },
790
+ ],
791
+ },
792
+ });
793
+
794
+ try {
795
+ let res = await worker.fetch("http://localhost/setup");
796
+ expect(res.status).toBe(204);
797
+
798
+ res = await worker.fetch("http://localhost/__scheduled");
799
+ expect(res.status).toBe(200);
800
+ expect(await res.text()).toBe("Ran scheduled event");
801
+
802
+ res = await worker.fetch("http://localhost/query");
803
+ expect(res.status).toBe(200);
804
+ expect(await res.json()).toEqual([{ id: 1, value: "one" }]);
805
+
806
+ res = await worker.fetch("http://localhost/bad");
807
+ expect(res.status).toBe(500);
808
+ expect(res.headers.get("Content-Type")).toBe("text/html");
809
+ expect(await res.text()).toContain("Error: Not found!");
810
+ } finally {
811
+ process.env.FORMAT_WRANGLER_ERRORS = originalFormatErrors;
812
+ await worker.stop();
813
+ }
814
+ });
815
+ });