Skip to content

Commit f90b1ae

Browse files
committed
use published sitemap
1 parent f3c74d9 commit f90b1ae

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

.github/workflows/test-preview.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
with:
3131
repository: ClickHouse/clickhouse-docs
3232
path: ./
33-
33+
3434
# Step 2: Log url
3535
- name: Log BASE_URL
3636
run: echo "BASE_URL=${{ github.event.deployment_status.environment_url }}"
@@ -44,7 +44,7 @@ jobs:
4444
node-version: '20.18.0'
4545
cache: 'yarn'
4646

47-
# Step 4: Install dependencies and build the site
47+
# Step 4: Install dependencies and build the site (needed for sitemap.xml)
4848
- name: Install and build
4949
run: |
5050
export NODE_OPTIONS="--max_old_space_size=4096"
@@ -60,3 +60,4 @@ jobs:
6060
ARGOS_BRANCH: ${{ github.event.deployment_status.environment == 'Production' && 'main' || github.ref_name }}
6161
CI: true
6262
ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }}
63+

tests/screenshot.spec.ts

+23-14
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import * as fs from 'fs';
22
import {argosScreenshot} from '@argos-ci/playwright';
33
import {test} from '@playwright/test';
4+
import axios from 'axios';
45
import {extractSitemapPathnames, pathnameToArgosName} from './utils';
56

67
// Constants
78
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`;
910
const stylesheetPath = './tests/screenshot.css';
1011
const 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
});

tests/utils.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import * as cheerio from "cheerio";
22
import * as fs from "fs";
33

4-
export function extractSitemapPathnames(sitemapPath: string): string[] {
5-
const sitemap = fs.readFileSync(sitemapPath).toString();
4+
export function extractSitemapPathnames(sitemap: string): string[] {
65
const $ = cheerio.load(sitemap, { xmlMode: true });
76
const urls: string[] = [];
87
$("loc").each(function handleLoc() {

0 commit comments

Comments
 (0)