test: verify CHRNX editorial polish

This commit is contained in:
chrnx committed 2026-08-12 16:10:55 -05:00
1 parent c5720b21ca
commit cb545c316c
2 files changed
+72 -28

No files matched your search

+37 -28
View File
@@ -10,9 +10,11 @@ if (!['localhost', '127.0.0.1'].includes(host)) {
const output = new URL('../tmp/imagegen/', import.meta.url); const output = new URL('../tmp/imagegen/', import.meta.url);
await mkdir(output, { recursive: true }); await mkdir(output, { recursive: true });
const browser = await chromium.launch(); async function capture(target, variant) {
const { path, selector } = target;
async function capture({ name, path, theme, viewport, fullPage = true }) { const { theme, viewport } = variant;
const browser = await chromium.launch();
try {
const context = await browser.newContext({ const context = await browser.newContext({
viewport, viewport,
colorScheme: theme, colorScheme: theme,
@@ -23,7 +25,10 @@ async function capture({ name, path, theme, viewport, fullPage = true }) {
theme, theme,
); );
const page = await context.newPage(); const page = await context.newPage();
await page.goto(new URL(path, baseURL).href, { waitUntil: 'networkidle' }); 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 page.addStyleTag({ await page.addStyleTag({
content: '*,*::before,*::after{animation:none!important;transition:none!important}', content: '*,*::before,*::after{animation:none!important;transition:none!important}',
}); });
@@ -43,35 +48,39 @@ async function capture({ name, path, theme, viewport, fullPage = true }) {
]); ]);
window.scrollTo(0, 0); window.scrollTo(0, 0);
}); });
await page.screenshot({ path: new URL(`${name}.png`, output).pathname, fullPage }); 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( console.log(
`${name}.png ${await page.evaluate( `${outputName} ${await page.evaluate(
() => `${document.documentElement.scrollWidth}x${document.documentElement.scrollHeight}`, () => `${document.documentElement.scrollWidth}x${document.documentElement.scrollHeight}`,
)}`, )}`,
); );
await context.close(); await context.close();
} finally {
await browser.close();
}
} }
const desktop = { width: 1440, height: 900 }; const reviewTargets = [
const mobile = { width: 375, height: 812 }; { name: 'home', path: '/' },
for (const spec of [ { name: 'music', path: '/music/' },
{ name: 'home-desktop-dark', path: '/', theme: 'dark', viewport: desktop }, { name: 'post', path: '/una-cuerda-rota-tambien-puede-decidir-el-arreglo/' },
{ name: 'home-desktop-light', path: '/', theme: 'light', viewport: desktop }, { name: 'footer', path: '/', selector: 'footer.wp-block-template-part' },
{ name: 'home-mobile-dark', path: '/', theme: 'dark', viewport: mobile }, ];
{ name: 'home-mobile-light', path: '/', theme: 'light', viewport: mobile }, const reviewVariants = [
{ name: 'topic-code-desktop-dark', path: '/topic/code/', theme: 'dark', viewport: desktop }, { name: 'desktop-dark', theme: 'dark', viewport: { width: 1440, height: 900 } },
{ { name: 'desktop-light', theme: 'light', viewport: { width: 1440, height: 900 } },
name: 'topic-research-desktop-dark', { name: 'mobile-dark', theme: 'dark', viewport: { width: 375, height: 812 } },
path: '/topic/research/', { name: 'mobile-light', theme: 'light', viewport: { width: 375, height: 812 } },
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);
}
await browser.close(); for (const target of reviewTargets) {
for (const variant of reviewVariants) {
await capture(target, variant);
}
}
+35
View File
@@ -76,6 +76,41 @@ test( 'the visual layer is separately enqueued and covers responsive accessible
assert.match( components, /html\[data-theme="light"\]/ ); 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', () => { test( 'the page canvas is atmospheric rather than a repeating grid', () => {
const components = read( 'assets/css/components.css' ); const components = read( 'assets/css/components.css' );