-
Notifications
You must be signed in to change notification settings - Fork 290
/
Copy pathscreenshot.spec.ts
42 lines (38 loc) · 1.43 KB
/
screenshot.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import * as fs from 'fs';
import { test } from '@playwright/test';
import { argosScreenshot } from '@argos-ci/playwright';
import { extractSitemapPathnames, pathnameToArgosName } from './utils';
// Constants
const siteUrl = 'http://localhost:3000';
const sitemapPath = './build/sitemap.xml';
const stylesheetPath = './screenshot.css';
const stylesheet = fs.readFileSync(stylesheetPath).toString();
// Wait for hydration, requires Docusaurus v2.4.3+
// Docusaurus adds a <html data-has-hydrated="true"> once hydrated
// See https://github.com/facebook/docusaurus/pull/9256
function waitForDocusaurusHydration() {
return document.documentElement.dataset.hasHydrated === 'true';
}
function screenshotPathname(pathname: string) {
test(`pathname ${pathname}`, async ({ page }) => {
const url = siteUrl + pathname;
await page.goto(url);
await page.waitForFunction(waitForDocusaurusHydration);
await page.addStyleTag({ content: stylesheet });
await argosScreenshot(page, pathnameToArgosName(pathname));
});
}
test.describe('Docusaurus site screenshots', () => {
const pathnames = extractSitemapPathnames(sitemapPath).filter((pathname) =>
pathname.match(
' ^/$|' +
'mana-calculator|' +
'learn/glossary|' +
'build/networks-endpoints|' +
'create-mnemonic|' +
'(api|apis)/core',
),
);
console.log('Pathnames to screenshot:', pathnames);
pathnames.forEach(screenshotPathname);
});