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);
|
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 context = await browser.newContext({
|
const browser = await chromium.launch();
|
||||||
viewport,
|
try {
|
||||||
colorScheme: theme,
|
const context = await browser.newContext({
|
||||||
reducedMotion: 'reduce',
|
viewport,
|
||||||
});
|
colorScheme: theme,
|
||||||
await context.addInitScript(
|
reducedMotion: 'reduce',
|
||||||
(preference) => localStorage.setItem('chrnx-theme', preference),
|
});
|
||||||
theme,
|
await context.addInitScript(
|
||||||
);
|
(preference) => localStorage.setItem('chrnx-theme', preference),
|
||||||
const page = await context.newPage();
|
theme,
|
||||||
await page.goto(new URL(path, baseURL).href, { waitUntil: 'networkidle' });
|
);
|
||||||
await page.addStyleTag({
|
const page = await context.newPage();
|
||||||
content: '*,*::before,*::after{animation:none!important;transition:none!important}',
|
const response = await page.goto(new URL(path, baseURL).href, { waitUntil: 'networkidle' });
|
||||||
});
|
if (!response?.ok()) {
|
||||||
await page.evaluate(async () => {
|
throw new Error(`Capture target ${path} returned HTTP ${response?.status() ?? 'unknown'}.`);
|
||||||
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([
|
await page.addStyleTag({
|
||||||
Promise.all(
|
content: '*,*::before,*::after{animation:none!important;transition:none!important}',
|
||||||
[...document.images].map((image) =>
|
});
|
||||||
image.complete ? Promise.resolve() : image.decode().catch(() => {}),
|
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)),
|
||||||
new Promise((resolve) => setTimeout(resolve, 3000)),
|
]);
|
||||||
]);
|
window.scrollTo(0, 0);
|
||||||
window.scrollTo(0, 0);
|
});
|
||||||
});
|
const outputName = `editorial-polish-${target.name}-${variant.name}.png`;
|
||||||
await page.screenshot({ path: new URL(`${name}.png`, output).pathname, fullPage });
|
const outputPath = new URL(outputName, output).pathname;
|
||||||
console.log(
|
if (selector) {
|
||||||
`${name}.png ${await page.evaluate(
|
await page.locator(selector).screenshot({ path: outputPath });
|
||||||
() => `${document.documentElement.scrollWidth}x${document.documentElement.scrollHeight}`,
|
} else {
|
||||||
)}`,
|
await page.screenshot({ path: outputPath, fullPage: true });
|
||||||
);
|
}
|
||||||
await context.close();
|
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 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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' );
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user