Files
SnapOtter/tests/e2e-docker/analytics-disabled.spec.ts
T
SnapOtterandGitHub 5d36ac06d8 feat(analytics): build-time bake + telemetry depth (#336)
Bake PostHog + Sentry into the published Docker image (SNAPOTTER_ANALYTICS
build arg, codegen script). Delete entire consent system. Move event emission
to BullMQ worker. Add cross-tier identity stitching, Sentry performance
tracing on both tiers, frontend funnel events. Fix stateful regex bug.

86 files changed, 1593 insertions(+), 3747 deletions(-)
2026-06-24 11:05:39 +08:00

83 lines
2.4 KiB
TypeScript

import { expect, test } from "@playwright/test";
// Tests for behavior when analytics is disabled at build time.
// Skip automatically if the container was built with analytics enabled.
// biome-ignore lint/suspicious/noUndeclaredEnvVars: e2e test env var
const BASE_URL = process.env.API_URL ?? "http://localhost:1349";
async function loginFresh(page: import("@playwright/test").Page) {
await page.goto("/login");
await page.getByLabel("Username").fill("admin");
await page.getByLabel("Password").fill("admin");
await page.getByRole("button", { name: /login/i }).click();
}
test.describe("Analytics disabled by build-time config", () => {
test.use({ storageState: { cookies: [], origins: [] } });
test.beforeEach(async ({ request: _request }, testInfo) => {
const res = await fetch(`${BASE_URL}/api/v1/config/analytics`);
const config = await res.json();
if (config.enabled) {
testInfo.skip();
}
});
test("config endpoint returns disabled with empty fields", async ({ request }) => {
const res = await request.get("/api/v1/config/analytics");
expect(res.ok()).toBeTruthy();
const config = await res.json();
expect(config).toEqual({
enabled: false,
posthogApiKey: "",
posthogHost: "",
sentryDsn: "",
sampleRate: 0,
instanceId: "",
});
});
test("login goes directly to home (no consent screen)", async ({ page }) => {
await loginFresh(page);
await page.waitForURL("/", { timeout: 30_000 });
await expect(page).toHaveURL("/");
});
test("no outbound network requests to PostHog or Sentry", async ({ page }) => {
const analyticsRequests: string[] = [];
await page.route("**/*", (route) => {
const url = route.request().url();
let host = "";
try {
host = new URL(url).hostname.toLowerCase();
} catch {
// non-URL scheme
}
if (
host === "posthog.com" ||
host.endsWith(".posthog.com") ||
host === "sentry.io" ||
host.endsWith(".sentry.io")
) {
analyticsRequests.push(url);
}
return route.continue();
});
await loginFresh(page);
await page.waitForURL("/", { timeout: 30_000 });
await page.goto("/resize");
await page.waitForTimeout(2_000);
await page.goto("/compress");
await page.waitForTimeout(2_000);
await page.goto("/");
await page.waitForTimeout(2_000);
expect(analyticsRequests).toEqual([]);
});
});