The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import type { EnvironmentServerConfig } from "@t3tools/client-runtime/connection"; |
| 2 | import { EnvironmentId } from "@t3tools/contracts"; |
| 3 | import { describe, expect, it } from "vite-plus/test"; |
| 4 | |
| 5 | import { |
| 6 | type ProfileReport, |
| 7 | type ReportedProfiles, |
| 8 | takeDueProfileReports, |
| 9 | } from "./BrowserProfileReporter"; |
| 10 | |
| 11 | const first = EnvironmentId.make("environment-1"); |
| 12 | const second = EnvironmentId.make("environment-2"); |
| 13 | const config = (label: string) => ({ label }) as unknown as EnvironmentServerConfig; |
| 14 | const input = (recordingFrameRate: number) => |
| 15 | ({ profiles: [], defaultProfileId: "default", recordingFrameRate }) as unknown as ProfileReport; |
| 16 | |
| 17 | describe("takeDueProfileReports", () => { |
| 18 | it("reports each environment once per config and input", () => { |
| 19 | const reported: ReportedProfiles = new Map(); |
| 20 | const configA = config("a"); |
| 21 | const configB = config("b"); |
| 22 | const settings = input(10); |
| 23 | const targets = new Map([ |
| 24 | [first, configA], |
| 25 | [second, configB], |
| 26 | ]); |
| 27 | |
| 28 | expect(takeDueProfileReports(reported, targets, settings)).toEqual([first, second]); |
| 29 | expect(takeDueProfileReports(reported, new Map(targets), settings)).toEqual([]); |
| 30 | |
| 31 | const restarted = config("a-restarted"); |
| 32 | expect( |
| 33 | takeDueProfileReports( |
| 34 | reported, |
| 35 | new Map([ |
| 36 | [first, restarted], |
| 37 | [second, configB], |
| 38 | ]), |
| 39 | settings, |
| 40 | ), |
| 41 | ).toEqual([first]); |
| 42 | }); |
| 43 | |
| 44 | it("reports every target again when the profile settings change", () => { |
| 45 | const reported: ReportedProfiles = new Map(); |
| 46 | const targets = new Map([ |
| 47 | [first, config("a")], |
| 48 | [second, config("b")], |
| 49 | ]); |
| 50 | takeDueProfileReports(reported, targets, input(10)); |
| 51 | |
| 52 | expect(takeDueProfileReports(reported, targets, input(30))).toEqual([first, second]); |
| 53 | }); |
| 54 | |
| 55 | it("reports an environment again once it becomes operable again", () => { |
| 56 | const reported: ReportedProfiles = new Map(); |
| 57 | const configA = config("a"); |
| 58 | const settings = input(10); |
| 59 | takeDueProfileReports(reported, new Map([[first, configA]]), settings); |
| 60 | |
| 61 | expect(takeDueProfileReports(reported, new Map(), settings)).toEqual([]); |
| 62 | expect(takeDueProfileReports(reported, new Map([[first, configA]]), settings)).toEqual([first]); |
| 63 | }); |
| 64 | }); |