1
1
import * as fs from 'fs' ;
2
2
import { argosScreenshot } from '@argos-ci/playwright' ;
3
3
import { test } from '@playwright/test' ;
4
+ import axios from 'axios' ;
4
5
import { extractSitemapPathnames , pathnameToArgosName } from './utils' ;
5
6
6
7
// Constants
7
8
const siteUrl = process . env . CI ? process . env . BASE_URL : 'http://localhost:3000' ;
8
- const sitemapPath = './build /sitemap.xml' ;
9
+ const sitemapUrl = ` ${ siteUrl } /docs /sitemap.xml` ;
9
10
const stylesheetPath = './tests/screenshot.css' ;
10
11
const stylesheet = fs . readFileSync ( stylesheetPath ) . toString ( ) ;
11
12
@@ -16,19 +17,27 @@ function waitForDocusaurusHydration() {
16
17
return document . documentElement . dataset . hasHydrated === 'true' ;
17
18
}
18
19
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
+ ) ;
26
30
} ) ;
27
- }
28
31
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
+ } ) ;
34
43
} ) ;
0 commit comments