Skip to content

Commit

Permalink
fix(telemetry): correctly parse alerted date (vercel#8042)
Browse files Browse the repository at this point in the history
### Description

Fix parsing the telemetry config alerted date in the JS lib

### Testing Instructions

<!--
  Give a quick description of steps to test your changes.
-->
  • Loading branch information
tknickman committed Apr 25, 2024
1 parent 5e5f7d9 commit 326b541
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
9 changes: 2 additions & 7 deletions packages/turbo-telemetry/src/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ describe("TelemetryConfig", () => {
telemetry_enabled: true,
telemetry_id: "123456",
telemetry_salt: "private-salt",
telemetry_alerted: new Date(),
telemetry_alerted: new Date().toISOString(),
},
});

Expand Down Expand Up @@ -389,7 +389,7 @@ describe("TelemetryConfig", () => {
telemetry_enabled: true,
telemetry_id: "123456",
telemetry_salt: "private-salt",
telemetry_alerted: new Date(),
telemetry_alerted: new Date().toISOString(),
},
});

Expand All @@ -401,11 +401,6 @@ describe("TelemetryConfig", () => {
test("should set telemetry_alerted to current date and write the config if telemetry_alerted is undefined", (t) => {
const mockWriteFileSync = mock.fn();
t.mock.method(fs, "writeFileSync", mockWriteFileSync);
mock.timers.enable({
apis: ["Date"],
now: new Date("2021-01-01T00:00:00.000Z"),
});

const result = telemetryConfig.alertShown();

assert.equal(result, true);
Expand Down
4 changes: 2 additions & 2 deletions packages/turbo-telemetry/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const ConfigSchema = z.object({
telemetry_enabled: z.boolean(),
telemetry_id: z.string(),
telemetry_salt: z.string(),
telemetry_alerted: z.date().optional(),
telemetry_alerted: z.string().optional(),
});

type Config = z.infer<typeof ConfigSchema>;
Expand Down Expand Up @@ -188,7 +188,7 @@ export class TelemetryConfig {
return true;
}

this.config.telemetry_alerted = new Date();
this.config.telemetry_alerted = new Date().toISOString();
this.tryWrite();
return true;
}
Expand Down

0 comments on commit 326b541

Please sign in to comment.