diff --git a/packages/gitbook/e2e/internal.spec.ts b/packages/gitbook/e2e/internal.spec.ts index ad945bfa5..3a884ae5e 100644 --- a/packages/gitbook/e2e/internal.spec.ts +++ b/packages/gitbook/e2e/internal.spec.ts @@ -80,14 +80,6 @@ const testCases: TestsCase[] = [ }, screenshot: false, }, - { - name: 'PDF (all pages)', - url: '~gitbook/pdf?limit=10', - }, - { - name: 'PDF (only current page)', - url: '~gitbook/pdf?page=Bw7LjWwgTjV8nIV4s7rs&only=yes&limit=2', - }, { name: 'Not found', url: 'content-not-found', @@ -314,14 +306,6 @@ const testCases: TestsCase[] = [ }, screenshot: false, }, - { - name: 'PDF (all pages)', - url: '~gitbook/pdf?limit=10', - }, - { - name: 'PDF (only current page)', - url: '~gitbook/pdf?page=DfnNkU49mvLe2ythHAyx&only=yes&limit=2', // limit 2 pages to catch any bugs with multiple pages - }, { name: 'Not found', url: 'content-not-found', diff --git a/packages/gitbook/e2e/pdf.spec.ts b/packages/gitbook/e2e/pdf.spec.ts new file mode 100644 index 000000000..59b6a8462 --- /dev/null +++ b/packages/gitbook/e2e/pdf.spec.ts @@ -0,0 +1,163 @@ +import { argosScreenshot } from '@argos-ci/playwright'; +import { expect, test } from '@playwright/test'; +import { waitForIcons } from './util'; + +test.describe('PDF export', () => { + test('export all pages as PDF (e2e)', async ({ page }) => { + // Set the header to disable the Vercel toolbar + // But only on the main document as it'd cause CORS issues on other resources + await page.route('**/*', async (route, request) => { + if (request.resourceType() === 'document') { + await route.continue({ + headers: { + ...request.headers(), + 'x-vercel-skip-toolbar': '1', + }, + }); + } else { + await route.continue(); + } + }); + + await page.goto( + 'https://gitbook-open-e2e-sites.gitbook.io/gitbook-doc/~gitbook/pdf?limit=10' + ); + + const printBtn = page.getByTestId('print-button'); + await expect(printBtn).toBeVisible(); + + await argosScreenshot(page, 'pdf - all pages', { + viewports: ['macbook-16', 'macbook-13', 'ipad-2', 'iphone-x'], + argosCSS: ` + /* Hide Intercom */ + .intercom-lightweight-app { + display: none !important; + } + `, + threshold: undefined, + fullPage: true, + beforeScreenshot: async ({ runStabilization }) => { + await runStabilization(); + await waitForIcons(page); + }, + }); + }); + + test('export all pages as PDF (GitBook docs)', async ({ page }) => { + // Set the header to disable the Vercel toolbar + // But only on the main document as it'd cause CORS issues on other resources + await page.route('**/*', async (route, request) => { + if (request.resourceType() === 'document') { + await route.continue({ + headers: { + ...request.headers(), + 'x-vercel-skip-toolbar': '1', + }, + }); + } else { + await route.continue(); + } + }); + + await page.goto('https://gitbook.com/docs/~gitbook/pdf?limit=10'); + + const printBtn = page.getByTestId('print-button'); + await expect(printBtn).toBeVisible(); + + await argosScreenshot(page, 'pdf - all pages', { + viewports: ['macbook-16', 'macbook-13', 'ipad-2', 'iphone-x'], + argosCSS: ` + /* Hide Intercom */ + .intercom-lightweight-app { + display: none !important; + } + `, + threshold: undefined, + fullPage: true, + beforeScreenshot: async ({ runStabilization }) => { + await runStabilization(); + await waitForIcons(page); + }, + }); + }); + + test('export a single page as PDF (e2e)', async ({ page }) => { + // Set the header to disable the Vercel toolbar + // But only on the main document as it'd cause CORS issues on other resources + await page.route('**/*', async (route, request) => { + if (request.resourceType() === 'document') { + await route.continue({ + headers: { + ...request.headers(), + 'x-vercel-skip-toolbar': '1', + }, + }); + } else { + await route.continue(); + } + }); + + await page.goto( + 'https://gitbook-open-e2e-sites.gitbook.io/gitbook-doc/~gitbook/pdf?page=Bw7LjWwgTjV8nIV4s7rs&only=yes&limit=2' + ); + + const printBtn = page.getByTestId('print-button'); + await expect(printBtn).toBeVisible(); + + await argosScreenshot(page, 'pdf - all pages', { + viewports: ['macbook-16', 'macbook-13', 'ipad-2', 'iphone-x'], + argosCSS: ` + /* Hide Intercom */ + .intercom-lightweight-app { + display: none !important; + } + `, + threshold: undefined, + fullPage: true, + beforeScreenshot: async ({ runStabilization }) => { + await runStabilization(); + await waitForIcons(page); + }, + }); + }); + + test('export a single page as PDF (GitBook docs)', async ({ page }) => { + // Set the header to disable the Vercel toolbar + // But only on the main document as it'd cause CORS issues on other resources + await page.route('**/*', async (route, request) => { + if (request.resourceType() === 'document') { + await route.continue({ + headers: { + ...request.headers(), + 'x-vercel-skip-toolbar': '1', + }, + }); + } else { + await route.continue(); + } + }); + + await page.goto( + 'https://gitbook.com/docs/~gitbook/pdf?page=DfnNkU49mvLe2ythHAyx&only=yes&limit=2' + ); + + const printBtn = page.getByTestId('print-button'); + await expect(printBtn).toBeVisible(); + + await argosScreenshot(page, 'pdf - all pages', { + viewports: ['macbook-16', 'macbook-13', 'ipad-2', 'iphone-x'], + argosCSS: ` + /* Hide Intercom */ + .intercom-lightweight-app { + display: none !important; + } + `, + threshold: undefined, + fullPage: true, + beforeScreenshot: async ({ runStabilization }) => { + await runStabilization(); + await waitForIcons(page); + }, + }); + }); +}); diff --git a/packages/gitbook/e2e/util.ts b/packages/gitbook/e2e/util.ts index f54b70fbe..937b776d7 100644 --- a/packages/gitbook/e2e/util.ts +++ b/packages/gitbook/e2e/util.ts @@ -346,7 +346,7 @@ export function getCustomizationURL(partial: DeepPartial { const urlStates: Record< string,