An open source design system that's fully customizable and agent ready
TypeScript
test(docsite): the banner case checks the reachable banner without holding the probe (#9115)
Christopher Chedeau2bb4c594e7db
diff --git a/apps/docsite/e2e/internal-docs-prompt.spec.ts b/apps/docsite/e2e/internal-docs-prompt.spec.tsindex 71e83d9022..48c24010bd 100644--- a/apps/docsite/e2e/internal-docs-prompt.spec.ts+++ b/apps/docsite/e2e/internal-docs-prompt.spec.ts@@ -52,16 +52,18 @@ async function servePublicOrigin(async function serveReachability(page: Page, origin: string) {let requests = 0;- let allowReply = () => {};- const gate = new Promise<void>(resolve => {- allowReply = resolve;- });+ const sandboxes: (string | null)[] = [];await page.route(`${probeOrigin}/embed/access-check?**`, async route => {requests++;expect(new URL(route.request().url()).searchParams.get('parent_origin'),).toBe(origin);- await gate;+ // The probe's frame exists while its request waits here: the probe removes+ // it once it has an answer, or when its four-second timeout fires. Reading+ // it now cannot race that timeout.+ const frame = await route.request().frame().frameElement();+ sandboxes.push(await frame.getAttribute('sandbox'));+ await frame.dispose();await route.fulfill({contentType: 'text/html; charset=utf-8',headers: {@@ -74,7 +76,7 @@ async function serveReachability(page: Page, origin: string) {body: `<!doctype html><html><body><script>window.parent.postMessage({type:'codebunny:access-check:v1',reachable:true},${JSON.stringify(origin)});</script></body></html>`,});});- return {requests: () => requests, allowReply};+ return {requests: () => requests, sandboxes: () => [...sandboxes]};}for (const {name, origin} of deployments) {@@ -115,37 +117,12 @@ for (const {name, origin} of deployments) {name: 'View production',exact: true,});- await expect(notice).toHaveCount(isCanary ? 1 : 0);- await expect(internal).toHaveCount(0);- if (isCanary) {- await expect(production).toHaveAttribute(- 'href',- 'https://astryx.atmeta.com/docs/getting-started?source=test',- );- await expect(notice).toContainText("You're viewing Canary docs");- await expect(notice.locator('[data-status="warning"]')).toHaveCount(- 2,- );- await page.screenshot({- path: testInfo.outputPath(- `docs-banner-canary-default-${name}-${width}-${colorScheme}.png`,- ),- });- await expect(notice).toContainText(- 'These docs may include unreleased components and props. View production docs for the latest stable release.',- );- await expect(notice).not.toContainText(- /Meta internal|Meta-specific components/,- );- }- await expect(- page.locator(- 'iframe[title="Astryx documentation reachability check"]',- ),- ).toHaveAttribute('sandbox', 'allow-scripts allow-same-origin');- probe.allowReply();+ // The probe answers at once, so this case checks the reachable banner.+ // The banner a page shows until reachability is known is the same one a+ // failed probe leaves, checked by the failed-reachability case.await expect(notice).toHaveCount(1);await expect(notice).toContainText('Working on Meta internal tools?');+ expect(probe.sandboxes()).toEqual(['allow-scripts allow-same-origin']);await expect(notice).not.toContainText("You're viewing Canary docs");if (isCanary) {await expect(notice).toContainText(@@ -266,45 +243,60 @@ for (const {name, origin} of deployments) {}for (const width of [1440, 390]) {- test(`${target}: failed reachability exposes no internal wording at ${width}px`, async ({- page,- baseURL,- }, testInfo) => {- await page.setViewportSize({width, height: 900});- const origin = deployments[0].origin;- await servePublicOrigin(page, baseURL, origin);- await page.route(`${probeOrigin}/**`, route => route.abort());- await page.goto(`${origin}/docs/getting-started`);- await expect(- page.getByRole('heading', {name: 'Getting Started', exact: true}),- ).toBeVisible();- await expect(- page.locator('iframe[title="Astryx documentation reachability check"]'),- ).toHaveCount(0, {timeout: 10_000});- const notice = page.getByRole('region', {name: noticeName});- await expect(notice).toHaveCount(isCanary ? 1 : 0);- await expect(- page.getByRole('link', {- name: 'Meta internal docs',- exact: true,- }),- ).toHaveCount(0);- if (isCanary) {- await expect(notice.locator('[data-status="warning"]')).toHaveCount(2);- await expect(notice).not.toContainText(- /Meta internal|Meta-specific components/,- );- expect(await notice.evaluate(element => element.outerHTML)).not.toMatch(- /Meta internal|Meta-specific components/,- );+ for (const colorScheme of ['light', 'dark'] as const) {+ test(`${target}: failed reachability exposes no internal wording at ${width}px in ${colorScheme}`, async ({+ page,+ baseURL,+ }, testInfo) => {+ await page.setViewportSize({width, height: 900});+ await page.emulateMedia({colorScheme});+ const origin = deployments[0].origin;+ await servePublicOrigin(page, baseURL, origin);+ await page.route(`${probeOrigin}/**`, route => route.abort());+ await page.goto(`${origin}/docs/getting-started?source=test`);await expect(- notice.getByRole('link', {name: 'View production', exact: true}),+ page.getByRole('heading', {name: 'Getting Started', exact: true}),).toBeVisible();- }- await page.screenshot({- path: testInfo.outputPath(- `docs-banner-${target}-no-internal-access-${width}.png`,- ),+ await expect(+ page.locator('iframe[title="Astryx documentation reachability check"]'),+ ).toHaveCount(0, {timeout: 10_000});+ const notice = page.getByRole('region', {name: noticeName});+ await expect(notice).toHaveCount(isCanary ? 1 : 0);+ await expect(+ page.getByRole('link', {+ name: 'Meta internal docs',+ exact: true,+ }),+ ).toHaveCount(0);+ if (isCanary) {+ // The banner a page shows until reachability is known, too.+ await expect(notice).toContainText("You're viewing Canary docs");+ await expect(notice).toContainText(+ 'These docs may include unreleased components and props. View production docs for the latest stable release.',+ );+ await expect(notice.locator('[data-status="warning"]')).toHaveCount(2);+ await expect(notice).not.toContainText(+ /Meta internal|Meta-specific components/,+ );+ expect(await notice.evaluate(element => element.outerHTML)).not.toMatch(+ /Meta internal|Meta-specific components/,+ );+ const production = notice.getByRole('link', {+ name: 'View production',+ exact: true,+ });+ await expect(production).toBeVisible();+ await expect(production).toHaveAttribute(+ 'href',+ 'https://astryx.atmeta.com/docs/getting-started?source=test',+ );+ }+ await page.evaluate(() => document.fonts.ready);+ await page.screenshot({+ path: testInfo.outputPath(+ `docs-banner-${target}-no-internal-access-${width}-${colorScheme}.png`,+ ),+ });});- });+ }}