wrangler 0.0.13 → 0.0.17

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 (67) hide show
  1. package/bin/wrangler.js +2 -2
  2. package/package.json +20 -11
  3. package/pages/functions/buildWorker.ts +1 -1
  4. package/pages/functions/filepath-routing.test.ts +112 -28
  5. package/pages/functions/filepath-routing.ts +44 -51
  6. package/pages/functions/routes.ts +11 -18
  7. package/pages/functions/template-worker.ts +3 -9
  8. package/src/__tests__/dev.test.tsx +42 -5
  9. package/src/__tests__/guess-worker-format.test.ts +66 -0
  10. package/src/__tests__/{clipboardy-mock.js → helpers/clipboardy-mock.js} +0 -0
  11. package/src/__tests__/helpers/cmd-shim.d.ts +11 -0
  12. package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
  13. package/src/__tests__/helpers/mock-account-id.ts +30 -0
  14. package/src/__tests__/helpers/mock-bin.ts +36 -0
  15. package/src/__tests__/{mock-cfetch.ts → helpers/mock-cfetch.ts} +43 -9
  16. package/src/__tests__/helpers/mock-console.ts +62 -0
  17. package/src/__tests__/{mock-dialogs.ts → helpers/mock-dialogs.ts} +1 -1
  18. package/src/__tests__/helpers/mock-kv.ts +40 -0
  19. package/src/__tests__/helpers/mock-user.ts +27 -0
  20. package/src/__tests__/helpers/mock-web-socket.ts +37 -0
  21. package/src/__tests__/{run-in-tmp.ts → helpers/run-in-tmp.ts} +1 -1
  22. package/src/__tests__/helpers/run-wrangler.ts +16 -0
  23. package/src/__tests__/helpers/write-wrangler-toml.ts +20 -0
  24. package/src/__tests__/index.test.ts +418 -71
  25. package/src/__tests__/jest.setup.ts +30 -2
  26. package/src/__tests__/kv.test.ts +147 -252
  27. package/src/__tests__/logout.test.ts +50 -0
  28. package/src/__tests__/package-manager.test.ts +206 -0
  29. package/src/__tests__/publish.test.ts +1136 -291
  30. package/src/__tests__/r2.test.ts +206 -0
  31. package/src/__tests__/secret.test.ts +210 -0
  32. package/src/__tests__/sentry.test.ts +146 -0
  33. package/src/__tests__/tail.test.ts +246 -0
  34. package/src/__tests__/whoami.test.tsx +6 -47
  35. package/src/api/form_data.ts +75 -25
  36. package/src/api/preview.ts +2 -2
  37. package/src/api/worker.ts +34 -15
  38. package/src/bundle.ts +127 -0
  39. package/src/cfetch/index.ts +7 -15
  40. package/src/cfetch/internal.ts +41 -6
  41. package/src/cli.ts +10 -0
  42. package/src/config.ts +125 -95
  43. package/src/dev.tsx +300 -193
  44. package/src/dialogs.tsx +2 -2
  45. package/src/guess-worker-format.ts +68 -0
  46. package/src/index.tsx +578 -192
  47. package/src/inspect.ts +29 -10
  48. package/src/kv.tsx +23 -17
  49. package/src/module-collection.ts +32 -12
  50. package/src/open-in-browser.ts +13 -0
  51. package/src/package-manager.ts +120 -0
  52. package/src/pages.tsx +28 -23
  53. package/src/paths.ts +26 -0
  54. package/src/proxy.ts +88 -14
  55. package/src/publish.ts +260 -297
  56. package/src/r2.ts +50 -0
  57. package/src/reporting.ts +115 -0
  58. package/src/sites.tsx +28 -27
  59. package/src/tail.tsx +178 -9
  60. package/src/user.tsx +58 -44
  61. package/templates/new-worker.js +15 -0
  62. package/templates/new-worker.ts +15 -0
  63. package/{static-asset-facade.js → templates/static-asset-facade.js} +0 -0
  64. package/wrangler-dist/cli.js +124315 -104677
  65. package/wrangler-dist/cli.js.map +3 -3
  66. package/src/__tests__/mock-console.ts +0 -34
  67. package/src/__tests__/run-wrangler.ts +0 -8
@@ -0,0 +1,206 @@
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
+
84
+ Options:
85
+ -l, --local Run on my machine [boolean] [default: false]
86
+
87
+ Not enough non-option arguments: got 0, need at least 1"
88
+ `);
89
+ });
90
+
91
+ it("should error if the bucket to create contains spaces", async () => {
92
+ await expect(
93
+ runWrangler("r2 bucket create abc def ghi")
94
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
95
+ `"Unexpected additional positional arguments \\"def ghi\\"."`
96
+ );
97
+ expect(std.out).toMatchInlineSnapshot(`""`);
98
+ expect(std.err).toMatchInlineSnapshot(`
99
+ "wrangler r2 bucket create <name>
100
+
101
+ Create a new R2 bucket
102
+
103
+ Positionals:
104
+ name The name of the new bucket [string] [required]
105
+
106
+ Flags:
107
+ -c, --config Path to .toml configuration file [string]
108
+ -h, --help Show help [boolean]
109
+ -v, --version Show version number [boolean]
110
+
111
+ Options:
112
+ -l, --local Run on my machine [boolean] [default: false]
113
+
114
+ Unexpected additional positional arguments \\"def ghi\\"."
115
+ `);
116
+ });
117
+
118
+ it("should create a bucket", async () => {
119
+ const requests = mockCreateRequest("testBucket");
120
+ await runWrangler("r2 bucket create testBucket");
121
+ expect(std.out).toMatchInlineSnapshot(`
122
+ "Creating bucket testBucket.
123
+ Created bucket testBucket."
124
+ `);
125
+ expect(requests.count).toEqual(1);
126
+ });
127
+ });
128
+
129
+ describe("delete", () => {
130
+ function mockDeleteRequest(expectedBucketName: string) {
131
+ const requests = { count: 0 };
132
+ setMockResponse(
133
+ "/accounts/:accountId/r2/buckets/:bucketName",
134
+ "DELETE",
135
+ ([_url, accountId, bucketName]) => {
136
+ expect(accountId).toEqual("some-account-id");
137
+ expect(bucketName).toEqual(expectedBucketName);
138
+ requests.count += 1;
139
+ }
140
+ );
141
+ return requests;
142
+ }
143
+
144
+ it("should error if no bucket name is given", async () => {
145
+ await expect(
146
+ runWrangler("r2 bucket delete")
147
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
148
+ `"Not enough non-option arguments: got 0, need at least 1"`
149
+ );
150
+ expect(std.out).toMatchInlineSnapshot(`""`);
151
+ expect(std.err).toMatchInlineSnapshot(`
152
+ "wrangler r2 bucket delete <name>
153
+
154
+ Delete an R2 bucket
155
+
156
+ Positionals:
157
+ name The name of the bucket to delete [string] [required]
158
+
159
+ Flags:
160
+ -c, --config Path to .toml configuration file [string]
161
+ -h, --help Show help [boolean]
162
+ -v, --version Show version number [boolean]
163
+
164
+ Options:
165
+ -l, --local Run on my machine [boolean] [default: false]
166
+
167
+ Not enough non-option arguments: got 0, need at least 1"
168
+ `);
169
+ });
170
+
171
+ it("should error if the bucket name to delete contains spaces", async () => {
172
+ await expect(
173
+ runWrangler("r2 bucket delete abc def ghi")
174
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
175
+ `"Unexpected additional positional arguments \\"def ghi\\"."`
176
+ );
177
+ expect(std.out).toMatchInlineSnapshot(`""`);
178
+ expect(std.err).toMatchInlineSnapshot(`
179
+ "wrangler r2 bucket delete <name>
180
+
181
+ Delete an R2 bucket
182
+
183
+ Positionals:
184
+ name The name of the bucket to delete [string] [required]
185
+
186
+ Flags:
187
+ -c, --config Path to .toml configuration file [string]
188
+ -h, --help Show help [boolean]
189
+ -v, --version Show version number [boolean]
190
+
191
+ Options:
192
+ -l, --local Run on my machine [boolean] [default: false]
193
+
194
+ Unexpected additional positional arguments \\"def ghi\\"."
195
+ `);
196
+ });
197
+
198
+ it("should delete a bucket specified by name", async () => {
199
+ const requests = mockDeleteRequest("some-bucket");
200
+ await runWrangler(`r2 bucket delete some-bucket`);
201
+ expect(requests.count).toEqual(1);
202
+ });
203
+ });
204
+ });
205
+ });
206
+ });
@@ -0,0 +1,210 @@
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(input: { name: string; text: string }) {
20
+ setMockResponse(
21
+ "/accounts/:accountId/workers/scripts/:scriptName/secrets",
22
+ "PUT",
23
+ ([_url, accountId], { body }) => {
24
+ expect(accountId).toEqual("some-account-id");
25
+ const { name, text, type } = JSON.parse(body as string);
26
+ expect(type).toEqual("secret_text");
27
+ expect(name).toEqual(input.name);
28
+ expect(text).toEqual(input.text);
29
+
30
+ return { name, type };
31
+ }
32
+ );
33
+ }
34
+
35
+ it("should create a secret", async () => {
36
+ mockPrompt({
37
+ text: "Enter a secret value:",
38
+ type: "password",
39
+ result: "the-secret",
40
+ });
41
+
42
+ mockPutRequest({ name: "the-secret-name", text: "the-secret" });
43
+ await runWrangler("secret put the-key --name script-name");
44
+
45
+ expect(std.out).toMatchInlineSnapshot(`
46
+ "🌀 Creating the secret for script script-name
47
+ ✨ Success! Uploaded secret the-key"
48
+ `);
49
+ expect(std.err).toMatchInlineSnapshot(`""`);
50
+ });
51
+
52
+ it("should error without a script name", async () => {
53
+ let error: Error | undefined;
54
+ try {
55
+ await runWrangler("secret put the-key");
56
+ } catch (e) {
57
+ error = e as Error;
58
+ }
59
+ expect(std.out).toMatchInlineSnapshot(`""`);
60
+ expect(std.err).toMatchInlineSnapshot(`
61
+ "Missing script name
62
+
63
+ %s
64
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
65
+ `);
66
+ expect(error).toMatchInlineSnapshot(`[Error: Missing script name]`);
67
+ });
68
+
69
+ it("warns about being a no-op in local mode", async () => {
70
+ mockPrompt({
71
+ text: "Enter a secret value:",
72
+ type: "password",
73
+ result: "the-secret",
74
+ });
75
+
76
+ mockPutRequest({ name: "the-secret-name", text: "the-secret" });
77
+ await runWrangler("secret put the-key --name script-name --local");
78
+ expect(std.out).toMatchInlineSnapshot(`""`);
79
+ expect(std.err).toMatchInlineSnapshot(`""`);
80
+ expect(std.warn).toMatchInlineSnapshot(
81
+ `"\`wrangler secret put\` is a no-op in --local mode"`
82
+ );
83
+ });
84
+ });
85
+
86
+ describe("delete", () => {
87
+ function mockDeleteRequest(input: {
88
+ scriptName: string;
89
+ secretName: string;
90
+ }) {
91
+ setMockResponse(
92
+ "/accounts/:accountId/workers/scripts/:scriptName/secrets/:secretName",
93
+ "DELETE",
94
+ ([_url, accountId, scriptName, secretName]) => {
95
+ expect(accountId).toEqual("some-account-id");
96
+ expect(scriptName).toEqual(input.scriptName);
97
+ expect(secretName).toEqual(input.secretName);
98
+
99
+ return null;
100
+ }
101
+ );
102
+ }
103
+ it("should delete a secret", async () => {
104
+ mockDeleteRequest({ scriptName: "script-name", secretName: "the-key" });
105
+ mockConfirm({
106
+ text: "Are you sure you want to permanently delete the variable the-key on the script script-name?",
107
+ result: true,
108
+ });
109
+ await runWrangler("secret delete the-key --name script-name");
110
+ expect(std.out).toMatchInlineSnapshot(`
111
+ "🌀 Deleting the secret the-key on script script-name.
112
+ ✨ Success! Deleted secret the-key"
113
+ `);
114
+ expect(std.err).toMatchInlineSnapshot(`""`);
115
+ });
116
+
117
+ it("should error without a script name", async () => {
118
+ let error: Error | undefined;
119
+
120
+ try {
121
+ await runWrangler("secret delete the-key");
122
+ } catch (e) {
123
+ error = e as Error;
124
+ }
125
+ expect(std.out).toMatchInlineSnapshot(`""`);
126
+ expect(std.err).toMatchInlineSnapshot(`
127
+ "Missing script name
128
+
129
+ %s
130
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
131
+ `);
132
+ expect(error).toMatchInlineSnapshot(`[Error: Missing script name]`);
133
+ });
134
+
135
+ it("warns about being a no-op in local mode", async () => {
136
+ mockConfirm({
137
+ text: "Are you sure you want to permanently delete the variable the-key on the script script-name?",
138
+ result: true,
139
+ });
140
+ await runWrangler("secret delete the-key --name script-name --local");
141
+ expect(std.out).toMatchInlineSnapshot(
142
+ `"🌀 Deleting the secret the-key on script script-name."`
143
+ );
144
+ expect(std.err).toMatchInlineSnapshot(`""`);
145
+ expect(std.warn).toMatchInlineSnapshot(
146
+ `"\`wrangler secret delete\` is a no-op in --local mode"`
147
+ );
148
+ });
149
+ });
150
+
151
+ describe("list", () => {
152
+ function mockListRequest(input: { scriptName: string }) {
153
+ setMockResponse(
154
+ "/accounts/:accountId/workers/scripts/:scriptName/secrets",
155
+ "GET",
156
+ ([_url, accountId, scriptName]) => {
157
+ expect(accountId).toEqual("some-account-id");
158
+ expect(scriptName).toEqual(input.scriptName);
159
+
160
+ return [
161
+ {
162
+ name: "the-secret-name",
163
+ type: "secret_text",
164
+ },
165
+ ];
166
+ }
167
+ );
168
+ }
169
+
170
+ it("should list secrets", async () => {
171
+ mockListRequest({ scriptName: "script-name" });
172
+ await runWrangler("secret list --name script-name");
173
+ expect(std.out).toMatchInlineSnapshot(`
174
+ "[
175
+ {
176
+ \\"name\\": \\"the-secret-name\\",
177
+ \\"type\\": \\"secret_text\\"
178
+ }
179
+ ]"
180
+ `);
181
+ expect(std.err).toMatchInlineSnapshot(`""`);
182
+ });
183
+
184
+ it("should error without a script name", async () => {
185
+ let error: Error | undefined;
186
+ try {
187
+ await runWrangler("secret list");
188
+ } catch (e) {
189
+ error = e as Error;
190
+ }
191
+ expect(std.out).toMatchInlineSnapshot(`""`);
192
+ expect(std.err).toMatchInlineSnapshot(`
193
+ "Missing script name
194
+
195
+ %s
196
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
197
+ `);
198
+ expect(error).toMatchInlineSnapshot(`[Error: Missing script name]`);
199
+ });
200
+
201
+ it("warns about being a no-op in local mode", async () => {
202
+ await runWrangler("secret list --name script-name --local");
203
+ expect(std.out).toMatchInlineSnapshot(`""`);
204
+ expect(std.err).toMatchInlineSnapshot(`""`);
205
+ expect(std.warn).toMatchInlineSnapshot(
206
+ `"\`wrangler secret list\` is a no-op in --local mode"`
207
+ );
208
+ });
209
+ });
210
+ });
@@ -0,0 +1,146 @@
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
+ });