Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions ui/studio/context.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ vi.mock("../../checkpoint", () => ({
check: vi.fn(() => Promise.resolve()),
}));

// std-env evaluates `isCI` once at import time from the environment, so telemetry
// tests can't control it through process.env. Pin it here (off by default) so the
// suite behaves the same on a developer machine and on CI.
const stdEnvState = vi.hoisted(() => ({ isCI: false }));

vi.mock("std-env", async (importOriginal) => {
const actual = await importOriginal<typeof import("std-env")>();
return {
...actual,
get isCI() {
return stdEnvState.isCI;
},
};
});

vi.mock("./NuqsHashAdapter", () => ({
NuqsHashAdapter: ({ children }: { children: ReactNode }) => <>{children}</>,
}));
Expand Down Expand Up @@ -192,6 +207,7 @@ afterEach(() => {
vi.unstubAllGlobals();
document.body.innerHTML = "";
delete process.env.CHECKPOINT_DISABLE;
stdEnvState.isCI = false;
delete (globalThis as { VERSION_INJECTED_AT_BUILD_TIME?: string })
.VERSION_INJECTED_AT_BUILD_TIME;
});
Expand Down Expand Up @@ -443,6 +459,24 @@ describe("StudioContextProvider telemetry opt-out", () => {
harness.cleanup();
});

it("skips launch telemetry on CI", () => {
stdEnvState.isCI = true;
const harness = renderHarness();

act(() => {
harness.getLatestStudio()?.onEvent({
name: "studio_launched",
payload: {
tableCount: 3,
},
});
});

expect(check).not.toHaveBeenCalled();

harness.cleanup();
});

it("skips launch telemetry when CHECKPOINT_DISABLE=1", () => {
process.env.CHECKPOINT_DISABLE = "1";

Expand Down