Compare commits

...

2 Commits

Author SHA1 Message Date
taranvohra c4c4af40dd testEntryUrl 2024-10-11 15:52:59 +05:30
taranvohra 66f9526594 open.gitbook.com e2e test 2024-10-11 15:44:09 +05:30
+31 -2
View File
@@ -3,6 +3,7 @@ import {
CustomizationHeaderPreset,
CustomizationIconsStyle,
CustomizationLocale,
PublishedSiteContentLookup,
SiteCustomizationSettings,
} from '@gitbook/api';
import { test, expect, Page } from '@playwright/test';
@@ -14,7 +15,7 @@ import { getContentTestURL } from '../tests/utils';
interface Test {
name: string;
url: string; // URL to visit for testing
url: string | (() => Promise<string>); // URL to visit for testing
run?: (page: Page) => Promise<unknown>; // The test to run
fullPage?: boolean; // Whether the test should be fullscreened during testing
screenshot?: false; // Should a screenshot be stored
@@ -763,6 +764,32 @@ const testCases: TestsCase[] = [
},
],
},
{
name: 'open.gitbook.com',
baseUrl: 'https://open.gitbook.com/',
tests: [
{
name: 'GitBook Docs',
url: 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<PublishedSiteContentLookup>();
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) {
@@ -770,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) {