This repository has been archived by the owner on Sep 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add workspace with Argos and Playwright to take screenshots of the pa…
…ges. Signed-off-by: Artur Owczarek <[email protected]>
- Loading branch information
1 parent
e011c8e
commit 6e73724
Showing
8 changed files
with
1,040 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "argos", | ||
"version": "0.0.0", | ||
"description": "Workspace for visual difference detection", | ||
"license": "MIT", | ||
"private": true, | ||
"scripts": { | ||
"screenshot": "playwright test", | ||
"upload": "npx @argos-ci/cli upload ./screenshots" | ||
}, | ||
"devDependencies": { | ||
"@argos-ci/cli": "^0.6.0", | ||
"@argos-ci/playwright": "^0.0.7", | ||
"@playwright/test": "^1.38.1", | ||
"cheerio": "^1.0.0-rc.12" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {devices} from '@playwright/test'; | ||
import type {PlaywrightTestConfig} from '@playwright/test'; | ||
|
||
const config: PlaywrightTestConfig = { | ||
webServer: { | ||
cwd: "..", | ||
port: 3000, | ||
command: 'yarn serve', | ||
}, | ||
projects: [ | ||
{ | ||
name: 'chromium', | ||
use: { | ||
...devices['Desktop Chrome'], | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* Iframes can load lazily */ | ||
iframe, | ||
/* Avatars can be flaky due to using external sources: GitHub/Unavatar */ | ||
.avatar__photo, | ||
/* Gifs load lazily and are animated */ | ||
img[src$='.gif'], | ||
/* Algolia keyboard shortcuts appear with a little delay */ | ||
.DocSearch-Button-Keys > kbd, | ||
/* The live playground preview can often display dates/counters */ | ||
[class*='playgroundPreview'] { | ||
visibility: hidden; | ||
} | ||
|
||
/* Different docs last-update dates can alter layout */ | ||
.theme-last-updated, | ||
/* Mermaid diagrams are rendered client-side and produce layout shifts */ | ||
.docusaurus-mermaid-container { | ||
display: none; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as fs from "fs"; | ||
import {test} from "@playwright/test"; | ||
import {argosScreenshot} from "@argos-ci/playwright"; | ||
import {extractSitemapPathnames, pathnameToArgosName} from "argos/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+ | ||
// See https://github.com/facebook/docusaurus/pull/9256 | ||
// Docusaurus adds a <html data-has-hydrated="true"> once hydrated | ||
function waitForDocusaurusHydration() { | ||
// uncomment the line when Docusaurus is upgraded to v2.4.3 | ||
// return document.documentElement.dataset.hasHydrated === "true"; | ||
return true; | ||
} | ||
|
||
function screenshotPathname(pathname: string, index: number, numberOfPaths: number) { | ||
test(`pathname ${pathname}`, async ({page}) => { | ||
const url = siteUrl + pathname; | ||
console.log(`${index + 1}/${numberOfPaths} Screenshotting`, url); | ||
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); | ||
console.log("Pathnames to screenshot:", pathnames); | ||
pathnames.forEach((path, index) => screenshotPathname(path, index, pathnames.length)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import * as cheerio from "cheerio"; | ||
import * as fs from "fs"; | ||
|
||
export function extractSitemapPathnames(sitemapPath: string): string[] { | ||
const sitemap = fs.readFileSync(sitemapPath).toString(); | ||
const $ = cheerio.load(sitemap, { xmlMode: true }); | ||
const urls: string[] = []; | ||
$("loc").each(function handleLoc() { | ||
urls.push($(this).text()); | ||
}); | ||
return urls.map((url) => new URL(url).pathname); | ||
} | ||
|
||
// Converts a pathname to a decent screenshot name | ||
export function pathnameToArgosName(pathname: string): string { | ||
return pathname.replace(/^\/|\/$/g, "") || "index"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,5 +57,8 @@ | |
}, | ||
"engines": { | ||
"node": ">=16.14" | ||
} | ||
}, | ||
"workspaces": [ | ||
"argos" | ||
] | ||
} |
Oops, something went wrong.