wrangler 0.0.0-e3cab74 → 0.0.0-e3d46ab3

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 (158) hide show
  1. package/README.md +47 -16
  2. package/bin/wrangler.js +95 -32
  3. package/config-schema.json +2939 -0
  4. package/kv-asset-handler.js +1 -0
  5. package/package.json +135 -84
  6. package/templates/__tests__/pages-dev-util.test.ts +128 -0
  7. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  8. package/templates/__tests__/tsconfig.json +8 -0
  9. package/templates/checked-fetch.js +30 -0
  10. package/templates/facade.d.ts +19 -0
  11. package/templates/gitignore +167 -0
  12. package/templates/init-tests/test-jest-new-worker.js +23 -0
  13. package/templates/init-tests/test-vitest-new-worker.js +24 -0
  14. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  15. package/templates/middleware/common.ts +67 -0
  16. package/templates/middleware/loader-modules.ts +134 -0
  17. package/templates/middleware/loader-sw.ts +229 -0
  18. package/templates/middleware/middleware-ensure-req-body-drained.ts +18 -0
  19. package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
  20. package/templates/middleware/middleware-pretty-error.ts +40 -0
  21. package/templates/middleware/middleware-scheduled.ts +15 -0
  22. package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
  23. package/templates/middleware/middleware-serve-static-assets.ts +56 -0
  24. package/templates/modules-watch-stub.js +4 -0
  25. package/templates/new-worker-scheduled.js +17 -0
  26. package/templates/new-worker-scheduled.ts +32 -0
  27. package/templates/new-worker.js +3 -3
  28. package/templates/new-worker.ts +22 -4
  29. package/templates/no-op-worker.js +10 -0
  30. package/templates/pages-dev-pipeline.ts +32 -0
  31. package/templates/pages-dev-util.ts +55 -0
  32. package/templates/pages-shim.ts +9 -0
  33. package/templates/pages-template-plugin.ts +190 -0
  34. package/templates/pages-template-worker.ts +198 -0
  35. package/templates/startDevWorker/InspectorProxyWorker.ts +664 -0
  36. package/templates/startDevWorker/ProxyWorker.ts +334 -0
  37. package/templates/tsconfig-sanity.ts +11 -0
  38. package/templates/tsconfig.init.json +105 -0
  39. package/templates/tsconfig.json +6 -103
  40. package/wrangler-dist/InspectorProxyWorker.js +464 -0
  41. package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
  42. package/wrangler-dist/ProxyWorker.js +240 -0
  43. package/wrangler-dist/ProxyWorker.js.map +6 -0
  44. package/wrangler-dist/cli.d.ts +24056 -0
  45. package/wrangler-dist/cli.js +199391 -131806
  46. package/wrangler-dist/wasm-sync.wasm +0 -0
  47. package/import_meta_url.js +0 -3
  48. package/miniflare-config-stubs/.env.empty +0 -0
  49. package/miniflare-config-stubs/package.empty.json +0 -1
  50. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  51. package/pages/functions/buildWorker.ts +0 -62
  52. package/pages/functions/filepath-routing.test.ts +0 -123
  53. package/pages/functions/filepath-routing.ts +0 -178
  54. package/pages/functions/identifiers.ts +0 -78
  55. package/pages/functions/routes.ts +0 -151
  56. package/pages/functions/template-worker.ts +0 -130
  57. package/src/__tests__/configuration.test.ts +0 -2185
  58. package/src/__tests__/dev.test.tsx +0 -113
  59. package/src/__tests__/guess-worker-format.test.ts +0 -66
  60. package/src/__tests__/helpers/clipboardy-mock.js +0 -4
  61. package/src/__tests__/helpers/cmd-shim.d.ts +0 -11
  62. package/src/__tests__/helpers/faye-websocket.d.ts +0 -6
  63. package/src/__tests__/helpers/mock-account-id.ts +0 -30
  64. package/src/__tests__/helpers/mock-bin.ts +0 -36
  65. package/src/__tests__/helpers/mock-cfetch.ts +0 -207
  66. package/src/__tests__/helpers/mock-console.ts +0 -62
  67. package/src/__tests__/helpers/mock-dialogs.ts +0 -65
  68. package/src/__tests__/helpers/mock-kv.ts +0 -40
  69. package/src/__tests__/helpers/mock-user.ts +0 -27
  70. package/src/__tests__/helpers/mock-web-socket.ts +0 -29
  71. package/src/__tests__/helpers/run-in-tmp.ts +0 -29
  72. package/src/__tests__/helpers/run-wrangler.ts +0 -16
  73. package/src/__tests__/helpers/write-wrangler-toml.ts +0 -17
  74. package/src/__tests__/index.test.ts +0 -866
  75. package/src/__tests__/jest.setup.ts +0 -57
  76. package/src/__tests__/kv.test.ts +0 -1141
  77. package/src/__tests__/logout.test.ts +0 -50
  78. package/src/__tests__/package-manager.test.ts +0 -206
  79. package/src/__tests__/parse.test.ts +0 -322
  80. package/src/__tests__/publish.test.ts +0 -2406
  81. package/src/__tests__/r2.test.ts +0 -198
  82. package/src/__tests__/secret.test.ts +0 -326
  83. package/src/__tests__/sentry.test.ts +0 -146
  84. package/src/__tests__/tail.test.ts +0 -564
  85. package/src/__tests__/whoami.test.tsx +0 -86
  86. package/src/api/form_data.ts +0 -217
  87. package/src/api/preview.ts +0 -147
  88. package/src/api/worker.ts +0 -186
  89. package/src/bundle.ts +0 -133
  90. package/src/cfetch/index.ts +0 -104
  91. package/src/cfetch/internal.ts +0 -133
  92. package/src/cli.ts +0 -19
  93. package/src/config/README.md +0 -107
  94. package/src/config/config.ts +0 -265
  95. package/src/config/diagnostics.ts +0 -80
  96. package/src/config/environment.ts +0 -305
  97. package/src/config/index.ts +0 -52
  98. package/src/config/validation-helpers.ts +0 -370
  99. package/src/config/validation.ts +0 -1017
  100. package/src/dev.tsx +0 -961
  101. package/src/dialogs.tsx +0 -77
  102. package/src/entry.ts +0 -57
  103. package/src/environment-variables.ts +0 -33
  104. package/src/guess-worker-format.ts +0 -68
  105. package/src/index.tsx +0 -2327
  106. package/src/inspect.ts +0 -609
  107. package/src/kv.tsx +0 -275
  108. package/src/module-collection.ts +0 -170
  109. package/src/open-in-browser.ts +0 -13
  110. package/src/package-manager.ts +0 -126
  111. package/src/pages.tsx +0 -1045
  112. package/src/parse.ts +0 -183
  113. package/src/paths.ts +0 -26
  114. package/src/proxy.ts +0 -376
  115. package/src/publish.ts +0 -368
  116. package/src/r2.ts +0 -50
  117. package/src/reporting.ts +0 -115
  118. package/src/sites.tsx +0 -241
  119. package/src/tail/filters.ts +0 -279
  120. package/src/tail/index.ts +0 -299
  121. package/src/tail/printing.ts +0 -62
  122. package/src/user.tsx +0 -1049
  123. package/src/whoami.tsx +0 -69
  124. package/templates/static-asset-facade.js +0 -47
  125. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  126. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  127. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  128. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  129. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  130. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  131. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  132. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  133. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  134. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  135. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  136. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  137. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  138. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  139. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  140. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  141. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  142. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  143. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  144. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  145. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  146. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  147. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  148. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  149. package/vendor/wrangler-mime/LICENSE +0 -21
  150. package/vendor/wrangler-mime/Mime.js +0 -97
  151. package/vendor/wrangler-mime/README.md +0 -187
  152. package/vendor/wrangler-mime/cli.js +0 -46
  153. package/vendor/wrangler-mime/index.js +0 -4
  154. package/vendor/wrangler-mime/lite.js +0 -4
  155. package/vendor/wrangler-mime/package.json +0 -52
  156. package/vendor/wrangler-mime/types/other.js +0 -1
  157. package/vendor/wrangler-mime/types/standard.js +0 -1
  158. package/wrangler-dist/cli.js.map +0 -7
@@ -1,198 +0,0 @@
1
- import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
2
- import { setMockResponse, unsetAllMocks } from "./helpers/mock-cfetch";
3
- import { mockConsoleMethods } from "./helpers/mock-console";
4
- import { runInTempDir } from "./helpers/run-in-tmp";
5
- import { runWrangler } from "./helpers/run-wrangler";
6
- import type { R2BucketInfo } from "../r2";
7
-
8
- describe("wrangler", () => {
9
- mockAccountId();
10
- mockApiToken();
11
- runInTempDir();
12
- const std = mockConsoleMethods();
13
-
14
- afterEach(() => {
15
- unsetAllMocks();
16
- });
17
-
18
- describe("r2", () => {
19
- describe("bucket", () => {
20
- describe("list", () => {
21
- function mockListRequest(buckets: R2BucketInfo[]) {
22
- const requests = { count: 0 };
23
- setMockResponse(
24
- "/accounts/:accountId/r2/buckets",
25
- ([_url, accountId], init) => {
26
- requests.count++;
27
- expect(accountId).toEqual("some-account-id");
28
- expect(init).toEqual({});
29
- return { buckets };
30
- }
31
- );
32
- return requests;
33
- }
34
-
35
- it("should list buckets", async () => {
36
- const expectedBuckets: R2BucketInfo[] = [
37
- { name: "bucket-1", creation_date: "01-01-2001" },
38
- { name: "bucket-2", creation_date: "01-01-2001" },
39
- ];
40
- mockListRequest(expectedBuckets);
41
- await runWrangler("r2 bucket list");
42
-
43
- expect(std.err).toMatchInlineSnapshot(`""`);
44
- const buckets = JSON.parse(std.out);
45
- expect(buckets).toEqual(expectedBuckets);
46
- });
47
- });
48
-
49
- describe("create", () => {
50
- function mockCreateRequest(expectedBucketName: string) {
51
- const requests = { count: 0 };
52
- setMockResponse(
53
- "/accounts/:accountId/r2/buckets/:bucketName",
54
- "PUT",
55
- ([_url, accountId, bucketName]) => {
56
- expect(accountId).toEqual("some-account-id");
57
- expect(bucketName).toEqual(expectedBucketName);
58
- requests.count += 1;
59
- }
60
- );
61
- return requests;
62
- }
63
-
64
- it("should error if no bucket name is given", async () => {
65
- await expect(
66
- runWrangler("r2 bucket create")
67
- ).rejects.toThrowErrorMatchingInlineSnapshot(
68
- `"Not enough non-option arguments: got 0, need at least 1"`
69
- );
70
- expect(std.out).toMatchInlineSnapshot(`""`);
71
- expect(std.err).toMatchInlineSnapshot(`
72
- "wrangler r2 bucket create <name>
73
-
74
- Create a new R2 bucket
75
-
76
- Positionals:
77
- name The name of the new bucket [string] [required]
78
-
79
- Flags:
80
- -c, --config Path to .toml configuration file [string]
81
- -h, --help Show help [boolean]
82
- -v, --version Show version number [boolean]
83
- --legacy-env Use legacy environments [boolean]
84
-
85
- Not enough non-option arguments: got 0, need at least 1"
86
- `);
87
- });
88
-
89
- it("should error if the bucket to create contains spaces", async () => {
90
- await expect(
91
- runWrangler("r2 bucket create abc def ghi")
92
- ).rejects.toThrowErrorMatchingInlineSnapshot(
93
- `"Unexpected additional positional arguments \\"def ghi\\"."`
94
- );
95
- expect(std.out).toMatchInlineSnapshot(`""`);
96
- expect(std.err).toMatchInlineSnapshot(`
97
- "wrangler r2 bucket create <name>
98
-
99
- Create a new R2 bucket
100
-
101
- Positionals:
102
- name The name of the new bucket [string] [required]
103
-
104
- Flags:
105
- -c, --config Path to .toml configuration file [string]
106
- -h, --help Show help [boolean]
107
- -v, --version Show version number [boolean]
108
- --legacy-env Use legacy environments [boolean]
109
-
110
- Unexpected additional positional arguments \\"def ghi\\"."
111
- `);
112
- });
113
-
114
- it("should create a bucket", async () => {
115
- const requests = mockCreateRequest("testBucket");
116
- await runWrangler("r2 bucket create testBucket");
117
- expect(std.out).toMatchInlineSnapshot(`
118
- "Creating bucket testBucket.
119
- Created bucket testBucket."
120
- `);
121
- expect(requests.count).toEqual(1);
122
- });
123
- });
124
-
125
- describe("delete", () => {
126
- function mockDeleteRequest(expectedBucketName: string) {
127
- const requests = { count: 0 };
128
- setMockResponse(
129
- "/accounts/:accountId/r2/buckets/:bucketName",
130
- "DELETE",
131
- ([_url, accountId, bucketName]) => {
132
- expect(accountId).toEqual("some-account-id");
133
- expect(bucketName).toEqual(expectedBucketName);
134
- requests.count += 1;
135
- }
136
- );
137
- return requests;
138
- }
139
-
140
- it("should error if no bucket name is given", async () => {
141
- await expect(
142
- runWrangler("r2 bucket delete")
143
- ).rejects.toThrowErrorMatchingInlineSnapshot(
144
- `"Not enough non-option arguments: got 0, need at least 1"`
145
- );
146
- expect(std.out).toMatchInlineSnapshot(`""`);
147
- expect(std.err).toMatchInlineSnapshot(`
148
- "wrangler r2 bucket delete <name>
149
-
150
- Delete an R2 bucket
151
-
152
- Positionals:
153
- name The name of the bucket to delete [string] [required]
154
-
155
- Flags:
156
- -c, --config Path to .toml configuration file [string]
157
- -h, --help Show help [boolean]
158
- -v, --version Show version number [boolean]
159
- --legacy-env Use legacy environments [boolean]
160
-
161
- Not enough non-option arguments: got 0, need at least 1"
162
- `);
163
- });
164
-
165
- it("should error if the bucket name to delete contains spaces", async () => {
166
- await expect(
167
- runWrangler("r2 bucket delete abc def ghi")
168
- ).rejects.toThrowErrorMatchingInlineSnapshot(
169
- `"Unexpected additional positional arguments \\"def ghi\\"."`
170
- );
171
- expect(std.out).toMatchInlineSnapshot(`""`);
172
- expect(std.err).toMatchInlineSnapshot(`
173
- "wrangler r2 bucket delete <name>
174
-
175
- Delete an R2 bucket
176
-
177
- Positionals:
178
- name The name of the bucket to delete [string] [required]
179
-
180
- Flags:
181
- -c, --config Path to .toml configuration file [string]
182
- -h, --help Show help [boolean]
183
- -v, --version Show version number [boolean]
184
- --legacy-env Use legacy environments [boolean]
185
-
186
- Unexpected additional positional arguments \\"def ghi\\"."
187
- `);
188
- });
189
-
190
- it("should delete a bucket specified by name", async () => {
191
- const requests = mockDeleteRequest("some-bucket");
192
- await runWrangler(`r2 bucket delete some-bucket`);
193
- expect(requests.count).toEqual(1);
194
- });
195
- });
196
- });
197
- });
198
- });
@@ -1,326 +0,0 @@
1
- import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
2
- import { setMockResponse, unsetAllMocks } from "./helpers/mock-cfetch";
3
- import { mockConsoleMethods } from "./helpers/mock-console";
4
- import { mockConfirm, mockPrompt } from "./helpers/mock-dialogs";
5
- import { runInTempDir } from "./helpers/run-in-tmp";
6
- import { runWrangler } from "./helpers/run-wrangler";
7
-
8
- describe("wrangler secret", () => {
9
- const std = mockConsoleMethods();
10
- runInTempDir();
11
- mockAccountId();
12
- mockApiToken();
13
-
14
- afterEach(() => {
15
- unsetAllMocks();
16
- });
17
-
18
- describe("put", () => {
19
- function mockPutRequest(
20
- input: { name: string; text: string },
21
- env?: string,
22
- legacyEnv = false
23
- ) {
24
- const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
25
- const environment = env && !legacyEnv ? "/environments/:envName" : "";
26
- setMockResponse(
27
- `/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/secrets`,
28
- "PUT",
29
- ([_url, accountId, scriptName, envName], { body }) => {
30
- expect(accountId).toEqual("some-account-id");
31
- expect(scriptName).toEqual(
32
- legacyEnv && env ? `script-name-${env}` : "script-name"
33
- );
34
- if (!legacyEnv) {
35
- expect(envName).toEqual(env);
36
- }
37
- const { name, text, type } = JSON.parse(body as string);
38
- expect(type).toEqual("secret_text");
39
- expect(name).toEqual(input.name);
40
- expect(text).toEqual(input.text);
41
-
42
- return { name, type };
43
- }
44
- );
45
- }
46
-
47
- it("should create a secret", async () => {
48
- mockPrompt({
49
- text: "Enter a secret value:",
50
- type: "password",
51
- result: "the-secret",
52
- });
53
-
54
- mockPutRequest({ name: "the-secret-name", text: "the-secret" });
55
- await runWrangler("secret put the-key --name script-name");
56
-
57
- expect(std.out).toMatchInlineSnapshot(`
58
- "🌀 Creating the secret for script script-name
59
- ✨ Success! Uploaded secret the-key"
60
- `);
61
- expect(std.err).toMatchInlineSnapshot(`""`);
62
- });
63
-
64
- it("should create a secret: legacy envs", async () => {
65
- mockPrompt({
66
- text: "Enter a secret value:",
67
- type: "password",
68
- result: "the-secret",
69
- });
70
-
71
- mockPutRequest(
72
- { name: "the-secret-name", text: "the-secret" },
73
- "some-env",
74
- true
75
- );
76
- await runWrangler(
77
- "secret put the-key --name script-name --env some-env --legacy-env"
78
- );
79
-
80
- expect(std.out).toMatchInlineSnapshot(`
81
- "🌀 Creating the secret for script script-name-some-env
82
- ✨ Success! Uploaded secret the-key"
83
- `);
84
- expect(std.err).toMatchInlineSnapshot(`""`);
85
- });
86
-
87
- it("should create a secret: service envs", async () => {
88
- mockPrompt({
89
- text: "Enter a secret value:",
90
- type: "password",
91
- result: "the-secret",
92
- });
93
-
94
- mockPutRequest(
95
- { name: "the-secret-name", text: "the-secret" },
96
- "some-env",
97
- false
98
- );
99
- await runWrangler(
100
- "secret put the-key --name script-name --env some-env --legacy-env false"
101
- );
102
-
103
- expect(std.out).toMatchInlineSnapshot(`
104
- "🌀 Creating the secret for script script-name (some-env)
105
- ✨ Success! Uploaded secret the-key"
106
- `);
107
- expect(std.err).toMatchInlineSnapshot(`""`);
108
- });
109
-
110
- it("should error without a script name", async () => {
111
- let error: Error | undefined;
112
- try {
113
- await runWrangler("secret put the-key");
114
- } catch (e) {
115
- error = e as Error;
116
- }
117
- expect(std.out).toMatchInlineSnapshot(`""`);
118
- expect(std.err).toMatchInlineSnapshot(`
119
- "Missing script name
120
-
121
- %s
122
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
123
- `);
124
- expect(error).toMatchInlineSnapshot(`[Error: Missing script name]`);
125
- });
126
- });
127
-
128
- describe("delete", () => {
129
- function mockDeleteRequest(
130
- input: {
131
- scriptName: string;
132
- secretName: string;
133
- },
134
- env?: string,
135
- legacyEnv = false
136
- ) {
137
- const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
138
- const environment = env && !legacyEnv ? "/environments/:envName" : "";
139
- setMockResponse(
140
- `/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/secrets/:secretName`,
141
- "DELETE",
142
- ([_url, accountId, scriptName, envOrSecretName, secretName]) => {
143
- expect(accountId).toEqual("some-account-id");
144
- expect(scriptName).toEqual(
145
- legacyEnv && env ? `script-name-${env}` : "script-name"
146
- );
147
- if (!legacyEnv) {
148
- if (env) {
149
- expect(envOrSecretName).toEqual(env);
150
- expect(secretName).toEqual(input.secretName);
151
- } else {
152
- expect(envOrSecretName).toEqual(input.secretName);
153
- }
154
- } else {
155
- expect(envOrSecretName).toEqual(input.secretName);
156
- }
157
- return null;
158
- }
159
- );
160
- }
161
- it("should delete a secret", async () => {
162
- mockDeleteRequest({ scriptName: "script-name", secretName: "the-key" });
163
- mockConfirm({
164
- text: "Are you sure you want to permanently delete the variable the-key on the script script-name?",
165
- result: true,
166
- });
167
- await runWrangler("secret delete the-key --name script-name");
168
- expect(std.out).toMatchInlineSnapshot(`
169
- "🌀 Deleting the secret the-key on script script-name
170
- ✨ Success! Deleted secret the-key"
171
- `);
172
- expect(std.err).toMatchInlineSnapshot(`""`);
173
- });
174
-
175
- it("should delete a secret: legacy envs", async () => {
176
- mockDeleteRequest(
177
- { scriptName: "script-name", secretName: "the-key" },
178
- "some-env",
179
- true
180
- );
181
- mockConfirm({
182
- text: "Are you sure you want to permanently delete the variable the-key on the script script-name-some-env?",
183
- result: true,
184
- });
185
- await runWrangler(
186
- "secret delete the-key --name script-name --env some-env --legacy-env"
187
- );
188
- expect(std.out).toMatchInlineSnapshot(`
189
- "🌀 Deleting the secret the-key on script script-name-some-env
190
- ✨ Success! Deleted secret the-key"
191
- `);
192
- expect(std.err).toMatchInlineSnapshot(`""`);
193
- });
194
-
195
- it("should delete a secret: service envs", async () => {
196
- mockDeleteRequest(
197
- { scriptName: "script-name", secretName: "the-key" },
198
- "some-env"
199
- );
200
- mockConfirm({
201
- text: "Are you sure you want to permanently delete the variable the-key on the script script-name (some-env)?",
202
- result: true,
203
- });
204
- await runWrangler(
205
- "secret delete the-key --name script-name --env some-env --legacy-env false"
206
- );
207
- expect(std.out).toMatchInlineSnapshot(`
208
- "🌀 Deleting the secret the-key on script script-name (some-env)
209
- ✨ Success! Deleted secret the-key"
210
- `);
211
- expect(std.err).toMatchInlineSnapshot(`""`);
212
- });
213
-
214
- it("should error without a script name", async () => {
215
- let error: Error | undefined;
216
-
217
- try {
218
- await runWrangler("secret delete the-key");
219
- } catch (e) {
220
- error = e as Error;
221
- }
222
- expect(std.out).toMatchInlineSnapshot(`""`);
223
- expect(std.err).toMatchInlineSnapshot(`
224
- "Missing script name
225
-
226
- %s
227
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
228
- `);
229
- expect(error).toMatchInlineSnapshot(`[Error: Missing script name]`);
230
- });
231
- });
232
-
233
- describe("list", () => {
234
- function mockListRequest(
235
- input: { scriptName: string },
236
- env?: string,
237
- legacyEnv = false
238
- ) {
239
- const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
240
- const environment = env && !legacyEnv ? "/environments/:envName" : "";
241
- setMockResponse(
242
- `/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/secrets`,
243
- "GET",
244
- ([_url, accountId, scriptName, envName]) => {
245
- expect(accountId).toEqual("some-account-id");
246
- expect(scriptName).toEqual(
247
- legacyEnv && env ? `script-name-${env}` : "script-name"
248
- );
249
- if (!legacyEnv) {
250
- expect(envName).toEqual(env);
251
- }
252
-
253
- return [
254
- {
255
- name: "the-secret-name",
256
- type: "secret_text",
257
- },
258
- ];
259
- }
260
- );
261
- }
262
-
263
- it("should list secrets", async () => {
264
- mockListRequest({ scriptName: "script-name" });
265
- await runWrangler("secret list --name script-name");
266
- expect(std.out).toMatchInlineSnapshot(`
267
- "[
268
- {
269
- \\"name\\": \\"the-secret-name\\",
270
- \\"type\\": \\"secret_text\\"
271
- }
272
- ]"
273
- `);
274
- expect(std.err).toMatchInlineSnapshot(`""`);
275
- });
276
-
277
- it("should list secrets: legacy envs", async () => {
278
- mockListRequest({ scriptName: "script-name" }, "some-env", true);
279
- await runWrangler(
280
- "secret list --name script-name --env some-env --legacy-env"
281
- );
282
- expect(std.out).toMatchInlineSnapshot(`
283
- "[
284
- {
285
- \\"name\\": \\"the-secret-name\\",
286
- \\"type\\": \\"secret_text\\"
287
- }
288
- ]"
289
- `);
290
- expect(std.err).toMatchInlineSnapshot(`""`);
291
- });
292
-
293
- it("should list secrets: service envs", async () => {
294
- mockListRequest({ scriptName: "script-name" }, "some-env");
295
- await runWrangler(
296
- "secret list --name script-name --env some-env --legacy-env false"
297
- );
298
- expect(std.out).toMatchInlineSnapshot(`
299
- "[
300
- {
301
- \\"name\\": \\"the-secret-name\\",
302
- \\"type\\": \\"secret_text\\"
303
- }
304
- ]"
305
- `);
306
- expect(std.err).toMatchInlineSnapshot(`""`);
307
- });
308
-
309
- it("should error without a script name", async () => {
310
- let error: Error | undefined;
311
- try {
312
- await runWrangler("secret list");
313
- } catch (e) {
314
- error = e as Error;
315
- }
316
- expect(std.out).toMatchInlineSnapshot(`""`);
317
- expect(std.err).toMatchInlineSnapshot(`
318
- "Missing script name
319
-
320
- %s
321
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
322
- `);
323
- expect(error).toMatchInlineSnapshot(`[Error: Missing script name]`);
324
- });
325
- });
326
- });
@@ -1,146 +0,0 @@
1
- import * as fs from "node:fs";
2
- import * as fsp from "node:fs/promises";
3
- import os from "node:os";
4
- import path from "node:path";
5
- import * as TOML from "@iarna/toml";
6
- import * as Sentry from "@sentry/node";
7
- import prompts from "prompts";
8
-
9
- import { mockConsoleMethods } from "./helpers/mock-console";
10
- import { runInTempDir } from "./helpers/run-in-tmp";
11
- import { runWrangler } from "./helpers/run-wrangler";
12
- const { reportError } = jest.requireActual("../reporting");
13
-
14
- describe("Error Reporting", () => {
15
- runInTempDir({ homedir: "./home" });
16
- mockConsoleMethods();
17
- const reportingTOMLPath = ".wrangler/config/reporting.toml";
18
-
19
- const originalTTY = process.stdout.isTTY;
20
- beforeEach(() => {
21
- jest.mock("@sentry/node");
22
- jest.spyOn(Sentry, "captureException");
23
- process.stdout.isTTY = true;
24
- });
25
-
26
- afterEach(() => {
27
- jest.unmock("@sentry/node");
28
- jest.clearAllMocks();
29
- process.stdout.isTTY = originalTTY;
30
- });
31
-
32
- it("should confirm user will allow error reporting usage", async () => {
33
- jest.spyOn(prompts, "prompt").mockResolvedValue({ sentryDecision: true });
34
-
35
- await reportError(new Error("test error"), "testFalse");
36
-
37
- const { error_tracking_opt, error_tracking_opt_date } = TOML.parse(
38
- await fsp.readFile(path.join(os.homedir(), reportingTOMLPath), "utf-8")
39
- );
40
-
41
- expect(error_tracking_opt).toBe(true);
42
- expect(error_tracking_opt_date).toBeTruthy();
43
-
44
- expect(Sentry.captureException).toHaveBeenCalledWith(
45
- new Error("test error")
46
- );
47
- });
48
-
49
- it("should confirm user will disallow error reporting usage", async () => {
50
- jest.spyOn(prompts, "prompt").mockResolvedValue({ sentryDecision: false });
51
- await reportError(new Error("test error"), "testFalse");
52
-
53
- const { error_tracking_opt, error_tracking_opt_date } = TOML.parse(
54
- await fsp.readFile(path.join(os.homedir(), reportingTOMLPath), "utf-8")
55
- );
56
-
57
- expect(error_tracking_opt).toBe(false);
58
- expect(error_tracking_opt_date).toBeTruthy();
59
-
60
- expect(Sentry.captureException).not.toHaveBeenCalledWith(
61
- new Error("test error"),
62
- "testFalse"
63
- );
64
- });
65
-
66
- it("should confirm user will allow 'once' error reporting usage", async () => {
67
- jest.spyOn(prompts, "prompt").mockResolvedValue({ sentryDecision: "once" });
68
- await runWrangler();
69
- await reportError(new Error("test error"), "testFalse");
70
-
71
- expect(fs.existsSync(path.join(os.homedir(), reportingTOMLPath))).toBe(
72
- false
73
- );
74
-
75
- expect(Sentry.captureException).not.toHaveBeenCalledWith(
76
- new Error("test error"),
77
- "testFalse"
78
- );
79
- });
80
-
81
- it("should not prompt w/ subsequent Errors after user disallows error reporting", async () => {
82
- jest.spyOn(prompts, "prompt").mockResolvedValue({ sentryDecision: false });
83
- await reportError(new Error("test error"), "testFalse");
84
-
85
- expect(Sentry.captureException).not.toHaveBeenCalledWith(
86
- new Error("test error"),
87
- "testFalse"
88
- );
89
-
90
- await reportError(new Error("second test error"), "testFalse");
91
- expect(Sentry.captureException).not.toHaveBeenCalledWith(
92
- new Error("second test error"),
93
- "testFalse"
94
- );
95
- });
96
-
97
- it("should not prompt w/ subsequent Errors after user Always allows error reporting", async () => {
98
- jest.spyOn(prompts, "prompt").mockResolvedValue({ sentryDecision: true });
99
- await reportError(new Error("test error"), "testFalse");
100
-
101
- expect(Sentry.captureException).toHaveBeenCalledWith(
102
- new Error("test error")
103
- );
104
-
105
- await reportError(new Error("second test error"), "testFalse");
106
- expect(Sentry.captureException).toHaveBeenCalledWith(
107
- new Error("second test error")
108
- );
109
- });
110
-
111
- it("should prompt w/ subsequent Errors after user allows error reporting once", async () => {
112
- const promptSpy = jest
113
- .spyOn(prompts, "prompt")
114
- .mockResolvedValue({ sentryDecision: "once" });
115
- await reportError(new Error("test error"), "testFalse");
116
-
117
- expect(Sentry.captureException).toHaveBeenCalledWith(
118
- new Error("test error")
119
- );
120
-
121
- await reportError(new Error("second test error"), "testFalse");
122
- expect(Sentry.captureException).toHaveBeenCalledWith(
123
- new Error("second test error")
124
- );
125
-
126
- expect(promptSpy).toBeCalledTimes(2);
127
- });
128
-
129
- it("should not prompt in non-TTY environment", async () => {
130
- process.stdout.isTTY = false;
131
-
132
- await reportError(new Error("test error"), "testFalse");
133
-
134
- const { error_tracking_opt, error_tracking_opt_date } = TOML.parse(
135
- await fsp.readFile(path.join(os.homedir(), reportingTOMLPath), "utf-8")
136
- );
137
-
138
- expect(error_tracking_opt).toBe(false);
139
- expect(error_tracking_opt_date).toBeTruthy();
140
-
141
- expect(Sentry.captureException).not.toHaveBeenCalledWith(
142
- new Error("test error")
143
- );
144
- process.stdout.isTTY = originalTTY;
145
- });
146
- });