wrangler 2.9.0 → 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 (82) hide show
  1. package/README.md +3 -3
  2. package/miniflare-dist/index.mjs +2 -15
  3. package/package.json +9 -9
  4. package/src/__tests__/configuration.test.ts +70 -0
  5. package/src/__tests__/d1/d1.test.ts +3 -6
  6. package/src/__tests__/d1/execute.test.ts +64 -0
  7. package/src/__tests__/d1/migrate.test.ts +107 -0
  8. package/src/__tests__/deployments.test.ts +40 -16
  9. package/src/__tests__/dev.test.tsx +3 -3
  10. package/src/__tests__/generate.test.ts +1 -1
  11. package/src/__tests__/helpers/end-event-loop.ts +6 -0
  12. package/src/__tests__/helpers/mock-get-pages-upload-token.ts +25 -0
  13. package/src/__tests__/helpers/mock-set-timeout.ts +16 -0
  14. package/src/__tests__/helpers/msw/handlers/deployments.ts +40 -16
  15. package/src/__tests__/helpers/string-dynamic-values-matcher.ts +28 -0
  16. package/src/__tests__/index.test.ts +3 -4
  17. package/src/__tests__/init.test.ts +1 -1
  18. package/src/__tests__/kv.test.ts +8 -8
  19. package/src/__tests__/middleware.test.ts +65 -0
  20. package/src/__tests__/mtls-certificates.test.ts +585 -0
  21. package/src/__tests__/pages/deployment-list.test.ts +78 -0
  22. package/src/__tests__/pages/functions-build.test.ts +402 -0
  23. package/src/__tests__/pages/pages.test.ts +81 -0
  24. package/src/__tests__/pages/project-create.test.ts +63 -0
  25. package/src/__tests__/pages/project-list.test.ts +108 -0
  26. package/src/__tests__/pages/project-upload.test.ts +481 -0
  27. package/src/__tests__/pages/publish.test.ts +2745 -0
  28. package/src/__tests__/publish.test.ts +58 -27
  29. package/src/__tests__/queues.test.ts +2 -2
  30. package/src/__tests__/secret.test.ts +4 -4
  31. package/src/__tests__/tsconfig.tsbuildinfo +1 -1
  32. package/src/__tests__/user.test.ts +1 -1
  33. package/src/__tests__/whoami.test.tsx +1 -1
  34. package/src/__tests__/worker-namespace.test.ts +1 -1
  35. package/src/api/index.ts +8 -0
  36. package/src/api/mtls-certificate.ts +148 -0
  37. package/src/api/pages/create-worker-bundle-contents.ts +75 -0
  38. package/src/api/pages/publish.tsx +52 -8
  39. package/src/bundle.ts +6 -5
  40. package/src/config/config.ts +7 -7
  41. package/src/config/environment.ts +9 -2
  42. package/src/config/index.ts +13 -0
  43. package/src/config/validation.ts +50 -3
  44. package/src/create-worker-upload-form.ts +9 -0
  45. package/src/d1/execute.tsx +124 -91
  46. package/src/d1/migrations/apply.tsx +36 -29
  47. package/src/d1/migrations/create.tsx +10 -8
  48. package/src/d1/migrations/helpers.ts +63 -38
  49. package/src/d1/migrations/list.tsx +31 -20
  50. package/src/d1/migrations/options.ts +6 -1
  51. package/src/d1/types.ts +1 -0
  52. package/src/d1/utils.ts +2 -1
  53. package/src/deployments.ts +62 -39
  54. package/src/dev/dev.tsx +1 -15
  55. package/src/dev/remote.tsx +2 -2
  56. package/src/dev.tsx +9 -6
  57. package/src/generate/index.ts +1 -1
  58. package/src/index.ts +15 -5
  59. package/src/miniflare-cli/assets.ts +1 -1
  60. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -1
  61. package/src/mtls-certificate/cli.ts +155 -0
  62. package/src/pages/build.ts +103 -23
  63. package/src/pages/buildFunctions.ts +32 -31
  64. package/src/pages/dev.ts +4 -2
  65. package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
  66. package/src/pages/publish.tsx +12 -1
  67. package/src/pages/utils.ts +1 -1
  68. package/src/publish/publish.ts +3 -2
  69. package/src/secret/index.ts +1 -0
  70. package/src/sites.ts +1 -1
  71. package/src/tail/filters.ts +1 -1
  72. package/src/user/user.ts +4 -3
  73. package/src/worker.ts +6 -0
  74. package/templates/format-dev-errors.ts +1 -0
  75. package/templates/new-worker.ts +3 -0
  76. package/templates/serve-static-assets.ts +1 -0
  77. package/templates/service-bindings-module-facade.js +1 -0
  78. package/templates/tsconfig.init.json +1 -1
  79. package/templates/tsconfig.tsbuildinfo +1 -1
  80. package/wrangler-dist/cli.d.ts +82 -2
  81. package/wrangler-dist/cli.js +1726 -1616
  82. package/src/__tests__/pages.test.ts +0 -2905
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
 
@@ -669,7 +669,7 @@ async function generateHandler({
669
669
  return new HTMLRewriter().on("body", {
670
670
  element(e) {
671
671
  e.append(
672
- `<!-- Cloudflare Pages Analytics --><script defer src='https://static.cloudflareinsights.com/beacon.min.js' data-cf-beacon='{"token": "${metadata.analytics?.token}"}'><\/script><!-- Cloudflare Pages Analytics -->`,
672
+ `<!-- Cloudflare Pages Analytics --><script defer src='https://static.cloudflareinsights.com/beacon.min.js' data-cf-beacon='{"token": "${metadata.analytics?.token}"}'></script><!-- Cloudflare Pages Analytics -->`,
673
673
  { html: true }
674
674
  );
675
675
  }
@@ -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);
@@ -6349,16 +6349,3 @@ async function main() {
6349
6349
  }
6350
6350
  }
6351
6351
  await main();
6352
- /**
6353
- * @fileoverview Main entrypoint for libraries using yargs-parser in Node.js
6354
- * CJS and ESM environments.
6355
- *
6356
- * @license
6357
- * Copyright (c) 2016, Contributors
6358
- * SPDX-License-Identifier: ISC
6359
- */
6360
- /**
6361
- * @license
6362
- * Copyright (c) 2016, Contributors
6363
- * SPDX-License-Identifier: ISC
6364
- */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wrangler",
3
- "version": "2.9.0",
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
- "esbuild": "0.14.51",
109
- "miniflare": "2.11.0",
108
+ "esbuild": "0.16.3",
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(
@@ -1,11 +1,8 @@
1
+ import { endEventLoop } from "../helpers/end-event-loop";
1
2
  import { mockConsoleMethods } from "../helpers/mock-console";
2
3
  import { runInTempDir } from "../helpers/run-in-tmp";
3
4
  import { runWrangler } from "../helpers/run-wrangler";
4
5
 
5
- function endEventLoop() {
6
- return new Promise((resolve) => setImmediate(resolve));
7
- }
8
-
9
6
  describe("d1", () => {
10
7
  const std = mockConsoleMethods();
11
8
  runInTempDir();
@@ -36,7 +33,7 @@ describe("d1", () => {
36
33
 
37
34
  --------------------
38
35
  🚧 D1 is currently in open alpha and is not recommended for production data and traffic
39
- 🚧 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
40
37
  🚧 To request features, visit https://community.cloudflare.com/c/developers/d1
41
38
  🚧 To give feedback, visit https://discord.gg/cloudflaredev
42
39
  --------------------"
@@ -76,7 +73,7 @@ describe("d1", () => {
76
73
 
77
74
  --------------------
78
75
  🚧 D1 is currently in open alpha and is not recommended for production data and traffic
79
- 🚧 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
80
77
  🚧 To request features, visit https://community.cloudflare.com/c/developers/d1
81
78
  🚧 To give feedback, visit https://discord.gg/cloudflaredev
82
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
+ });
@@ -1,4 +1,6 @@
1
1
  import { cwd } from "process";
2
+ import { reinitialiseAuthTokens } from "../../user";
3
+ import { mockAccountId, mockApiToken } from "../helpers/mock-account-id";
2
4
  import { useMockIsTTY } from "../helpers/mock-istty";
3
5
  import { runInTempDir } from "../helpers/run-in-tmp";
4
6
  import { runWrangler } from "../helpers/run-wrangler";
@@ -8,6 +10,21 @@ describe("migrate", () => {
8
10
  runInTempDir();
9
11
  const { setIsTTY } = useMockIsTTY();
10
12
 
13
+ describe("create", () => {
14
+ it("should reject the --local flag for create", async () => {
15
+ setIsTTY(false);
16
+ writeWranglerToml({
17
+ d1_databases: [
18
+ { binding: "DATABASE", database_name: "db", database_id: "xxxx" },
19
+ ],
20
+ });
21
+
22
+ await expect(
23
+ runWrangler("d1 migrations create test some-message --local DATABASE")
24
+ ).rejects.toThrowError(`Unknown argument: local`);
25
+ });
26
+ });
27
+
11
28
  describe("apply", () => {
12
29
  it("should not attempt to login in local mode", async () => {
13
30
  setIsTTY(false);
@@ -44,5 +61,95 @@ describe("migrate", () => {
44
61
  `No migrations present at ${cwd().replaceAll("\\", "/")}/migrations.`
45
62
  );
46
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
+ });
78
+ });
79
+
80
+ describe("list", () => {
81
+ mockAccountId();
82
+ mockApiToken({ apiToken: null });
83
+
84
+ it("should not attempt to login in local mode", async () => {
85
+ setIsTTY(false);
86
+ writeWranglerToml({
87
+ d1_databases: [
88
+ { binding: "DATABASE", database_name: "db", database_id: "xxxx" },
89
+ ],
90
+ });
91
+ // If we get to the point where we are checking for migrations then we have not been asked to log in.
92
+ await expect(
93
+ runWrangler("d1 migrations list --local DATABASE")
94
+ ).rejects.toThrowError(
95
+ `No migrations present at ${cwd().replaceAll("\\", "/")}/migrations.`
96
+ );
97
+ });
98
+
99
+ it("should use the custom migrations folder when provided", async () => {
100
+ setIsTTY(false);
101
+ writeWranglerToml({
102
+ d1_databases: [
103
+ {
104
+ binding: "DATABASE",
105
+ database_name: "db",
106
+ database_id: "xxxx",
107
+ migrations_dir: "my-migrations-go-here",
108
+ },
109
+ ],
110
+ });
111
+ await expect(
112
+ runWrangler("d1 migrations list --local DATABASE")
113
+ ).rejects.toThrowError(
114
+ `No migrations present at ${cwd().replaceAll(
115
+ "\\",
116
+ "/"
117
+ )}/my-migrations-go-here.`
118
+ );
119
+ });
120
+
121
+ it("should try to read D1 config from wrangler.toml when logged in", async () => {
122
+ // no need to clear this env var as it's implicitly cleared by mockApiToken in afterEach
123
+ process.env.CLOUDFLARE_API_TOKEN = "api-token";
124
+ reinitialiseAuthTokens();
125
+ setIsTTY(false);
126
+ writeWranglerToml();
127
+ await expect(
128
+ runWrangler("d1 migrations list DATABASE")
129
+ ).rejects.toThrowError(
130
+ "Can't find a DB with name/binding 'DATABASE' in local config. Check info in wrangler.toml..."
131
+ );
132
+ });
133
+
134
+ it("should throw if user is not authenticated and not using --local", async () => {
135
+ setIsTTY(false);
136
+
137
+ await expect(
138
+ runWrangler("d1 migrations list DATABASE")
139
+ ).rejects.toThrowError(
140
+ "In a non-interactive environment, it's necessary to set a CLOUDFLARE_API_TOKEN environment variable for wrangler to work"
141
+ );
142
+ });
143
+
144
+ it("should not try to read wrangler.toml in local mode", async () => {
145
+ setIsTTY(false);
146
+ writeWranglerToml();
147
+ // If we get to the point where we are checking for migrations then we have not checked wrangler.toml.
148
+ await expect(
149
+ runWrangler("d1 migrations list --local DATABASE")
150
+ ).rejects.toThrowError(
151
+ `No migrations present at ${cwd().replaceAll("\\", "/")}/migrations.`
152
+ );
153
+ });
47
154
  });
48
155
  });
@@ -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
  `);
@@ -131,7 +131,7 @@ describe("generate", () => {
131
131
  // was harder than i thought, leaving this for now.
132
132
  it.todo("clones a cloudflare template with full checkouts");
133
133
 
134
- it("clones a user/repo template", async () => {
134
+ it.skip("clones a user/repo template", async () => {
135
135
  await expect(
136
136
  runWrangler("generate my-worker caass/wrangler-generate-test-template")
137
137
  ).resolves.toBeUndefined();
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Forces a tick and ensures that all pending promises resolve
3
+ */
4
+ export function endEventLoop() {
5
+ return new Promise((resolve) => setImmediate(resolve));
6
+ }
@@ -0,0 +1,25 @@
1
+ import { rest } from "msw";
2
+ import { msw } from "./msw";
3
+
4
+ /**
5
+ * Mocks the `/accounts/:accountId/pages/projects/:projectName/upload-token` GET request
6
+ */
7
+ export function mockGetUploadTokenRequest(
8
+ jwt: string,
9
+ accountId: string,
10
+ projectName: string
11
+ ) {
12
+ msw.use(
13
+ rest.get(
14
+ `*/accounts/:accountId/pages/projects/${projectName}/upload-token`,
15
+ (req, res, ctx) => {
16
+ expect(req.params.accountId).toEqual(accountId);
17
+
18
+ return res(
19
+ ctx.status(200),
20
+ ctx.json({ success: true, errors: [], messages: [], result: { jwt } })
21
+ );
22
+ }
23
+ )
24
+ );
25
+ }
@@ -0,0 +1,16 @@
1
+ let setTimeoutSpy: jest.SpyInstance;
2
+
3
+ export function mockSetTimeout() {
4
+ beforeEach(() => {
5
+ setTimeoutSpy = jest
6
+ .spyOn(global, "setTimeout")
7
+ // @ts-expect-error we're using a very simple setTimeout mock here
8
+ .mockImplementation((fn, _period) => {
9
+ setImmediate(fn);
10
+ });
11
+ });
12
+
13
+ afterEach(() => {
14
+ setTimeoutSpy.mockRestore();
15
+ });
16
+ }
@@ -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
  )