|
| 1 | +import * as fs from "node:fs"; |
1 | 2 | import { http, HttpResponse } from "msw"; |
2 | 3 | import { vi } from "vitest"; |
3 | 4 | import { CI } from "../is-ci"; |
@@ -189,6 +190,7 @@ describe("metrics", () => { |
189 | 190 | isPagesCI: false, |
190 | 191 | isWorkersCI: false, |
191 | 192 | isInteractive: true, |
| 193 | + hasAssets: false, |
192 | 194 | argsUsed: [], |
193 | 195 | argsCombination: "", |
194 | 196 | command: "wrangler docs", |
@@ -359,6 +361,58 @@ describe("metrics", () => { |
359 | 361 | expect(std.debug).toContain('isWorkersCI":true'); |
360 | 362 | }); |
361 | 363 |
|
| 364 | + it("should capture Workers + Assets projects", async () => { |
| 365 | + writeWranglerConfig({ assets: { directory: "./public" } }); |
| 366 | + |
| 367 | + // set up empty static assets directory |
| 368 | + fs.mkdirSync("./public"); |
| 369 | + |
| 370 | + const requests = mockMetricRequest(); |
| 371 | + |
| 372 | + await runWrangler("docs arg"); |
| 373 | + expect(requests.count).toBe(2); |
| 374 | + |
| 375 | + // command started |
| 376 | + const expectedStartReq = { |
| 377 | + deviceId: "f82b1f46-eb7b-4154-aa9f-ce95f23b2288", |
| 378 | + event: "wrangler command started", |
| 379 | + timestamp: 1733961600000, |
| 380 | + properties: { |
| 381 | + amplitude_session_id: 1733961600000, |
| 382 | + amplitude_event_id: 0, |
| 383 | + ...{ ...reused, hasAssets: true }, |
| 384 | + }, |
| 385 | + }; |
| 386 | + expect(std.debug).toContain( |
| 387 | + `Posting data ${JSON.stringify(expectedStartReq)}` |
| 388 | + ); |
| 389 | + |
| 390 | + // command completed |
| 391 | + const expectedCompleteReq = { |
| 392 | + deviceId: "f82b1f46-eb7b-4154-aa9f-ce95f23b2288", |
| 393 | + event: "wrangler command completed", |
| 394 | + timestamp: 1733961606000, |
| 395 | + properties: { |
| 396 | + amplitude_session_id: 1733961600000, |
| 397 | + amplitude_event_id: 1, |
| 398 | + ...{ ...reused, hasAssets: true }, |
| 399 | + durationMs: 6000, |
| 400 | + durationSeconds: 6, |
| 401 | + durationMinutes: 0.1, |
| 402 | + }, |
| 403 | + }; |
| 404 | + expect(std.debug).toContain( |
| 405 | + `Posting data ${JSON.stringify(expectedCompleteReq)}` |
| 406 | + ); |
| 407 | + expect(std.out).toMatchInlineSnapshot(` |
| 408 | + " |
| 409 | + Cloudflare collects anonymous telemetry about your usage of Wrangler. Learn more at https://github.com/cloudflare/workers-sdk/tree/main/packages/wrangler/telemetry.md |
| 410 | + Opening a link in your default browser: FAKE_DOCS_URL:{\\"params\\":\\"query=arg&hitsPerPage=1&getRankingInfo=0\\"}" |
| 411 | + `); |
| 412 | + expect(std.warn).toMatchInlineSnapshot(`""`); |
| 413 | + expect(std.err).toMatchInlineSnapshot(`""`); |
| 414 | + }); |
| 415 | + |
362 | 416 | it("should not send arguments with wrangler login", async () => { |
363 | 417 | const requests = mockMetricRequest(); |
364 | 418 |
|
|
0 commit comments