test: verify CHRNX editorial polish
This commit is contained in:
2 files changed
+104
-60
No files matched your search
@@ -10,68 +10,77 @@ if (!['localhost', '127.0.0.1'].includes(host)) {
|
||||
const output = new URL('../tmp/imagegen/', import.meta.url);
|
||||
await mkdir(output, { recursive: true });
|
||||
|
||||
const browser = await chromium.launch();
|
||||
|
||||
async function capture({ name, path, theme, viewport, fullPage = true }) {
|
||||
const context = await browser.newContext({
|
||||
viewport,
|
||||
colorScheme: theme,
|
||||
reducedMotion: 'reduce',
|
||||
});
|
||||
await context.addInitScript(
|
||||
(preference) => localStorage.setItem('chrnx-theme', preference),
|
||||
theme,
|
||||
);
|
||||
const page = await context.newPage();
|
||||
await page.goto(new URL(path, baseURL).href, { waitUntil: 'networkidle' });
|
||||
await page.addStyleTag({
|
||||
content: '*,*::before,*::after{animation:none!important;transition:none!important}',
|
||||
});
|
||||
await page.evaluate(async () => {
|
||||
await document.fonts.ready;
|
||||
for (let y = 0; y <= document.documentElement.scrollHeight; y += window.innerHeight) {
|
||||
window.scrollTo(0, y);
|
||||
await new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)));
|
||||
async function capture(target, variant) {
|
||||
const { path, selector } = target;
|
||||
const { theme, viewport } = variant;
|
||||
const browser = await chromium.launch();
|
||||
try {
|
||||
const context = await browser.newContext({
|
||||
viewport,
|
||||
colorScheme: theme,
|
||||
reducedMotion: 'reduce',
|
||||
});
|
||||
await context.addInitScript(
|
||||
(preference) => localStorage.setItem('chrnx-theme', preference),
|
||||
theme,
|
||||
);
|
||||
const page = await context.newPage();
|
||||
const response = await page.goto(new URL(path, baseURL).href, { waitUntil: 'networkidle' });
|
||||
if (!response?.ok()) {
|
||||
throw new Error(`Capture target ${path} returned HTTP ${response?.status() ?? 'unknown'}.`);
|
||||
}
|
||||
await Promise.race([
|
||||
Promise.all(
|
||||
[...document.images].map((image) =>
|
||||
image.complete ? Promise.resolve() : image.decode().catch(() => {}),
|
||||
await page.addStyleTag({
|
||||
content: '*,*::before,*::after{animation:none!important;transition:none!important}',
|
||||
});
|
||||
await page.evaluate(async () => {
|
||||
await document.fonts.ready;
|
||||
for (let y = 0; y <= document.documentElement.scrollHeight; y += window.innerHeight) {
|
||||
window.scrollTo(0, y);
|
||||
await new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)));
|
||||
}
|
||||
await Promise.race([
|
||||
Promise.all(
|
||||
[...document.images].map((image) =>
|
||||
image.complete ? Promise.resolve() : image.decode().catch(() => {}),
|
||||
),
|
||||
),
|
||||
),
|
||||
new Promise((resolve) => setTimeout(resolve, 3000)),
|
||||
]);
|
||||
window.scrollTo(0, 0);
|
||||
});
|
||||
await page.screenshot({ path: new URL(`${name}.png`, output).pathname, fullPage });
|
||||
console.log(
|
||||
`${name}.png ${await page.evaluate(
|
||||
() => `${document.documentElement.scrollWidth}x${document.documentElement.scrollHeight}`,
|
||||
)}`,
|
||||
);
|
||||
await context.close();
|
||||
new Promise((resolve) => setTimeout(resolve, 3000)),
|
||||
]);
|
||||
window.scrollTo(0, 0);
|
||||
});
|
||||
const outputName = `editorial-polish-${target.name}-${variant.name}.png`;
|
||||
const outputPath = new URL(outputName, output).pathname;
|
||||
if (selector) {
|
||||
await page.locator(selector).screenshot({ path: outputPath });
|
||||
} else {
|
||||
await page.screenshot({ path: outputPath, fullPage: true });
|
||||
}
|
||||
console.log(
|
||||
`${outputName} ${await page.evaluate(
|
||||
() => `${document.documentElement.scrollWidth}x${document.documentElement.scrollHeight}`,
|
||||
)}`,
|
||||
);
|
||||
await context.close();
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
}
|
||||
|
||||
const desktop = { width: 1440, height: 900 };
|
||||
const mobile = { width: 375, height: 812 };
|
||||
for (const spec of [
|
||||
{ name: 'home-desktop-dark', path: '/', theme: 'dark', viewport: desktop },
|
||||
{ name: 'home-desktop-light', path: '/', theme: 'light', viewport: desktop },
|
||||
{ name: 'home-mobile-dark', path: '/', theme: 'dark', viewport: mobile },
|
||||
{ name: 'home-mobile-light', path: '/', theme: 'light', viewport: mobile },
|
||||
{ name: 'topic-code-desktop-dark', path: '/topic/code/', theme: 'dark', viewport: desktop },
|
||||
{
|
||||
name: 'topic-research-desktop-dark',
|
||||
path: '/topic/research/',
|
||||
theme: 'dark',
|
||||
viewport: desktop,
|
||||
},
|
||||
{ name: 'topic-gaming-desktop-dark', path: '/topic/gaming/', theme: 'dark', viewport: desktop },
|
||||
{ name: 'music-desktop-dark', path: '/music/', theme: 'dark', viewport: desktop },
|
||||
{ name: 'podcasts-desktop-dark', path: '/podcasts/', theme: 'dark', viewport: desktop },
|
||||
{ name: 'about-desktop-dark', path: '/about/', theme: 'dark', viewport: desktop },
|
||||
]) {
|
||||
await capture(spec);
|
||||
}
|
||||
const reviewTargets = [
|
||||
{ name: 'home', path: '/' },
|
||||
{ name: 'music', path: '/music/' },
|
||||
{ name: 'post', path: '/una-cuerda-rota-tambien-puede-decidir-el-arreglo/' },
|
||||
{ name: 'footer', path: '/', selector: 'footer.wp-block-template-part' },
|
||||
];
|
||||
const reviewVariants = [
|
||||
{ name: 'desktop-dark', theme: 'dark', viewport: { width: 1440, height: 900 } },
|
||||
{ name: 'desktop-light', theme: 'light', viewport: { width: 1440, height: 900 } },
|
||||
{ name: 'mobile-dark', theme: 'dark', viewport: { width: 375, height: 812 } },
|
||||
{ name: 'mobile-light', theme: 'light', viewport: { width: 375, height: 812 } },
|
||||
];
|
||||
|
||||
await browser.close();
|
||||
for (const target of reviewTargets) {
|
||||
for (const variant of reviewVariants) {
|
||||
await capture(target, variant);
|
||||
}
|
||||
}
|
||||
@@ -76,6 +76,41 @@ test( 'the visual layer is separately enqueued and covers responsive accessible
|
||||
assert.match( components, /html\[data-theme="light"\]/ );
|
||||
} );
|
||||
|
||||
test( 'editorial review capture stays bounded to approved pages, variants, and filenames', () => {
|
||||
const capture = read( 'scripts/capture-visual-review.mjs' );
|
||||
|
||||
for ( const target of [ 'home', 'music', 'post', 'footer' ] ) {
|
||||
assert.match( capture, new RegExp( `name: '${ target }'` ) );
|
||||
}
|
||||
assert.match( capture, /path: '\/'/ );
|
||||
assert.match( capture, /path: '\/music\/'/ );
|
||||
assert.match( capture, /path: '\/una-cuerda-rota-tambien-puede-decidir-el-arreglo\/'/ );
|
||||
assert.match( capture, /selector: 'footer\.wp-block-template-part'/ );
|
||||
for ( const variant of [ 'desktop-dark', 'desktop-light', 'mobile-dark', 'mobile-light' ] ) {
|
||||
assert.match( capture, new RegExp( `name: '${ variant }'` ) );
|
||||
}
|
||||
assert.match(
|
||||
capture,
|
||||
/`editorial-polish-\$\{\s*target\.name\s*\}-\$\{\s*variant\.name\s*\}\.png`/,
|
||||
);
|
||||
assert.doesNotMatch( capture, /name: 'topic-|name: 'podcasts'|name: 'about'/ );
|
||||
} );
|
||||
|
||||
test( 'editorial review capture isolates browser compositing between theme variants', () => {
|
||||
const capture = read( 'scripts/capture-visual-review.mjs' );
|
||||
|
||||
assert.ok(
|
||||
capture.indexOf( 'const browser = await chromium.launch()' ) >
|
||||
capture.indexOf( 'async function capture' ),
|
||||
'Chromium must launch inside capture so a dark render cannot corrupt the next light screenshot',
|
||||
);
|
||||
assert.match(
|
||||
capture,
|
||||
/const browser = await chromium\.launch\(\);[\s\S]*?try \{[\s\S]*?finally \{\s*await browser\.close\(\);\s*\}/,
|
||||
'Every isolated browser must close even when navigation or capture fails',
|
||||
);
|
||||
} );
|
||||
|
||||
test( 'the page canvas is atmospheric rather than a repeating grid', () => {
|
||||
const components = read( 'assets/css/components.css' );
|
||||
|
||||
|
||||
Reference in new issue
Block a user