Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions site/src/layouts/Layout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ const structuredData = { "@context": "https://schema.org", "@type": "WebSite", n
console.warn("Theme storage is unavailable; using light mode for this visit.", error);
}
</script>
<script is:inline>
if (location.hostname === "pnp.github.io" && location.pathname.startsWith("/script-samples/")) {
(function(c, l, a, r, i, t, y) {
c[a] = c[a] || function() { (c[a].q = c[a].q || []).push(arguments); };
t = l.createElement(r);
t.async = 1;
t.src = "https://www.clarity.ms/tag/" + i;
y = l.getElementsByTagName(r)[0];
y.parentNode.insertBefore(t, y);
})(window, document, "clarity", "script", "8j6pedl344");
}
</script>
</head>
<body>
<a class="skip-link" href="#main-content">Skip to content</a>
Expand Down
12 changes: 11 additions & 1 deletion site/tests/gallery.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ test("retains old sample, guide, filter, and report links without redirect track

test("keeps local previews free of production analytics and maps every page tracker correctly", async ({ page }) => {
const requests: string[] = [];
page.on("request", (request) => { if (request.url().includes("m365-visitor-stats")) requests.push(request.url()); });
page.on("request", (request) => {
if (request.url().includes("m365-visitor-stats") || request.url().includes("clarity.ms")) requests.push(request.url());
});
const paths = [
["./", "script-samples"],
["contributors/", "script-samples/contributors"],
Expand All @@ -171,10 +173,15 @@ test("activates exactly one production tracker without counting filter or theme
if (!baseURL) throw new Error("Browser tests require the local production server.");
const origin = new URL(baseURL).origin;
const tracked: string[] = [];
const clarity: string[] = [];
await page.route("https://m365-visitor-stats.azurewebsites.net/**", async (route) => {
tracked.push(route.request().url());
await route.fulfill({ contentType: "image/gif", headers: { "Cache-Control": "no-store" }, body: Buffer.from("R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=", "base64") });
});
await page.route("https://www.clarity.ms/tag/**", async (route) => {
clarity.push(route.request().url());
await route.fulfill({ contentType: "application/javascript", body: "window.__clarityTestLoaded = true;" });
});
await page.route("https://pnp.github.io/script-samples/**", async (route) => {
const url = new URL(route.request().url());
const response = await request.get(`${origin}${url.pathname}${url.search}`);
Expand All @@ -188,6 +195,9 @@ test("activates exactly one production tracker without counting filter or theme
await page.goto("https://pnp.github.io/script-samples/");
await expect.poll(() => tracked.length).toBe(1);
expect(tracked[0]).toBe("https://m365-visitor-stats.azurewebsites.net/script-samples");
await expect.poll(() => clarity.length).toBe(1);
expect(clarity[0]).toBe("https://www.clarity.ms/tag/8j6pedl344");
await expect.poll(() => page.evaluate(() => (window as Window & { __clarityTestLoaded?: boolean }).__clarityTestLoaded)).toBe(true);
await page.locator('[data-product="graph"]').click();
await page.locator("#sample-search").fill("permissions");
await page.locator("#theme-toggle").click();
Expand Down
Loading