From 66f9526594fc7e3b187daf0087178d90fa83bafa Mon Sep 17 00:00:00 2001 From: taranvohra Date: Fri, 11 Oct 2024 15:44:09 +0530 Subject: [PATCH 1/2] open.gitbook.com e2e test --- packages/gitbook/e2e/pages.spec.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/packages/gitbook/e2e/pages.spec.ts b/packages/gitbook/e2e/pages.spec.ts index b61dbbc20..a1303aadc 100644 --- a/packages/gitbook/e2e/pages.spec.ts +++ b/packages/gitbook/e2e/pages.spec.ts @@ -3,6 +3,7 @@ import { CustomizationHeaderPreset, CustomizationIconsStyle, CustomizationLocale, + PublishedSiteContentLookup, SiteCustomizationSettings, } from '@gitbook/api'; import { test, expect, Page } from '@playwright/test'; @@ -763,6 +764,32 @@ const testCases: TestsCase[] = [ }, ], }, + { + name: 'open.gitbook.com', + baseUrl: 'https://open.gitbook.com/', + tests: [ + { + name: 'GitBook Docs', + url: await (async () => { + const res = await fetch( + `https://api.gitbook.com/v1/urls/published?url=https://docs.gitbook.com`, + ); + + if (!res.ok) { + throw new Error('Failed to get published URL'); + } + + const published = await res.json(); + if (!('site' in published)) { + throw new Error('Expected site for published URL'); + } + + return `~site/${published.site}?token=${published.apiToken}`; + })(), + run: waitForCookiesDialog, + }, + ], + }, ]; for (const testCase of testCases) { From c4c4af40dde5f2d5f44346b1061154cb25c9cdd1 Mon Sep 17 00:00:00 2001 From: taranvohra Date: Fri, 11 Oct 2024 15:52:59 +0530 Subject: [PATCH 2/2] testEntryUrl --- packages/gitbook/e2e/pages.spec.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/gitbook/e2e/pages.spec.ts b/packages/gitbook/e2e/pages.spec.ts index a1303aadc..76d0ac0be 100644 --- a/packages/gitbook/e2e/pages.spec.ts +++ b/packages/gitbook/e2e/pages.spec.ts @@ -15,7 +15,7 @@ import { getContentTestURL } from '../tests/utils'; interface Test { name: string; - url: string; // URL to visit for testing + url: string | (() => Promise); // URL to visit for testing run?: (page: Page) => Promise; // The test to run fullPage?: boolean; // Whether the test should be fullscreened during testing screenshot?: false; // Should a screenshot be stored @@ -770,7 +770,7 @@ const testCases: TestsCase[] = [ tests: [ { name: 'GitBook Docs', - url: await (async () => { + url: async () => { const res = await fetch( `https://api.gitbook.com/v1/urls/published?url=https://docs.gitbook.com`, ); @@ -785,7 +785,7 @@ const testCases: TestsCase[] = [ } return `~site/${published.site}?token=${published.apiToken}`; - })(), + }, run: waitForCookiesDialog, }, ], @@ -797,7 +797,9 @@ for (const testCase of testCases) { for (const testEntry of testCase.tests) { const testFn = testEntry.only ? test.only : test; testFn(testEntry.name, async ({ page, baseURL }) => { - const contentUrl = new URL(testEntry.url, testCase.baseUrl); + const testEntryUrl = + typeof testEntry.url === 'string' ? testEntry.url : await testEntry.url(); + const contentUrl = new URL(testEntryUrl, testCase.baseUrl); const url = getContentTestURL(contentUrl.toString(), baseURL); await page.goto(url); if (testEntry.run) {