11import * as fs from 'fs' ;
22import { argosScreenshot } from '@argos-ci/playwright' ;
33import { test } from '@playwright/test' ;
4+ import axios from 'axios' ;
45import { extractSitemapPathnames , pathnameToArgosName } from './utils' ;
56
67// Constants
78const siteUrl = process . env . CI ? process . env . BASE_URL : 'http://localhost:3000' ;
8- const sitemapPath = './build /sitemap.xml' ;
9+ const sitemapUrl = ` ${ siteUrl } /docs /sitemap.xml` ;
910const stylesheetPath = './tests/screenshot.css' ;
1011const stylesheet = fs . readFileSync ( stylesheetPath ) . toString ( ) ;
1112
@@ -16,19 +17,27 @@ function waitForDocusaurusHydration() {
1617 return document . documentElement . dataset . hasHydrated === 'true' ;
1718}
1819
19- function screenshotPathname ( pathname : string ) {
20- test ( `pathname ${ pathname } ` , async ( { page} ) => {
21- const url = siteUrl + pathname ;
22- await page . goto ( url ) ;
23- await page . waitForFunction ( waitForDocusaurusHydration ) ;
24- await page . addStyleTag ( { content : stylesheet } ) ;
25- await argosScreenshot ( page , pathnameToArgosName ( pathname ) ) ;
20+ test . describe ( 'Docusaurus site screenshots' , async ( ) => {
21+ let pathnames : string [ ] = [ ] ;
22+
23+ test . beforeAll ( async ( ) => {
24+ // Fetch the sitemap dynamically
25+ const response = await axios . get ( sitemapUrl ) ;
26+ const sitemapContent = response . data ;
27+ pathnames = extractSitemapPathnames ( sitemapContent ) . filter ( ( pathname ) =>
28+ pathname . startsWith ( '/docs/en' ) // currently test en only
29+ ) ;
2630 } ) ;
27- }
2831
29- test . describe ( 'Docusaurus site screenshots' , ( ) => {
30- const pathnames = extractSitemapPathnames ( sitemapPath ) . filter ( ( pathname ) =>
31- pathname . startsWith ( '/docs/en' ) // currently test en only
32- ) ;
33- pathnames . forEach ( screenshotPathname ) ;
32+ test ( 'Generate and run screenshot tests' , async ( { page} ) => {
33+ // Iterate through the pathnames and run tests dynamically
34+ for ( const pathname of pathnames ) {
35+ console . log ( `processing ${ pathname } ` )
36+ const url = siteUrl + pathname ;
37+ await page . goto ( url ) ;
38+ await page . waitForFunction ( waitForDocusaurusHydration ) ;
39+ await page . addStyleTag ( { content : stylesheet } ) ;
40+ await argosScreenshot ( page , pathnameToArgosName ( pathname ) ) ;
41+ }
42+ } ) ;
3443} ) ;
0 commit comments