fix: complete CHRNX responsive edge states
This commit is contained in:
15 files changed
+384
-35
No files matched your search
@@ -1,5 +1,8 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { mkdtempSync, readFileSync, readdirSync, rmSync, statSync } from 'node:fs';
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { test } from 'node:test';
|
||||
|
||||
const read = ( path ) => readFileSync( new URL( `../../${ path }`, import.meta.url ), 'utf8' );
|
||||
@@ -18,6 +21,13 @@ test( 'local visual fixtures define stable pages and representative editorial st
|
||||
assert.ok( posts.some( ( post ) => post.content.includes( 'wp:code' ) ) );
|
||||
assert.ok( posts.some( ( post ) => post.fixtureState === 'missing-media' ) );
|
||||
assert.ok( posts.some( ( post ) => post.fixtureState === 'missing-podcast-meta' ) );
|
||||
assert.ok( posts.some( ( post ) => post.fixtureState === 'missing-excerpt' && !( 'excerpt' in post ) ) );
|
||||
assert.ok( posts.some( ( post ) => post.fixtureState === 'missing-topic' && !( 'topic' in post ) ) );
|
||||
assert.ok( posts.some( ( post ) => post.fixtureState === 'missing-language' && !( 'language' in post ) ) );
|
||||
assert.ok( posts.some( ( post ) => post.fixtureState === 'unbroken-code' && /[A-Z0-9]{256}/.test( post.content ) ) );
|
||||
assert.ok( posts.some( ( post ) => /^https:\/\//.test( post.canonicalEpisodeUrl ?? '' ) ) );
|
||||
assert.ok( posts.some( ( post ) => post.fixtureState === 'missing-podcast-meta' && !( 'canonicalEpisodeUrl' in post ) ) );
|
||||
assert.equal( new Set( posts.map( ( post ) => post.fixtureKey ) ).size, posts.length );
|
||||
for ( const topic of [ 'code', 'research', 'gaming', 'literature', 'music', 'podcasts', 'life' ] ) {
|
||||
assert.ok( posts.some( ( post ) => post.topic === topic ), `missing ${ topic } fixture` );
|
||||
}
|
||||
@@ -29,7 +39,10 @@ test( 'the seed entrypoint is explicitly local-only and uses a stable fixture ke
|
||||
|
||||
assert.match( shell, /localhost|127\.0\.0\.1/ );
|
||||
assert.match( shell, /wp eval-file/ );
|
||||
assert.match( shell, /featured-1/ );
|
||||
assert.match( shell, /subscribe-unavailable/ );
|
||||
assert.match( php, /_chrnx_fixture_key/ );
|
||||
assert.match( php, /canonical_episode_url/ );
|
||||
assert.match( php, /show_on_front/ );
|
||||
assert.match( php, /page_on_front/ );
|
||||
assert.match( php, /page_for_posts/ );
|
||||
@@ -46,15 +59,45 @@ test( 'the visual layer is separately enqueued and covers responsive accessible
|
||||
assert.match( components, /html\[data-theme="light"\]/ );
|
||||
} );
|
||||
|
||||
test( 'all approved portraits expose reproducible WebP and AVIF derivatives', () => {
|
||||
for ( const topic of [ 'code', 'gaming', 'life', 'literature', 'podcasts', 'research' ] ) {
|
||||
const manifest = JSON.parse( read( `assets/images/generated/alter-ego-${ topic }.json` ) );
|
||||
assert.equal( manifest.source, `alter-ego-${ topic }.png` );
|
||||
assert.deepEqual( manifest.formats, [ 'avif', 'webp' ] );
|
||||
assert.deepEqual( manifest.widths, [ 384, 768 ] );
|
||||
test( 'all approved portraits rebuild byte-identically within payload bounds', () => {
|
||||
const output = mkdtempSync( join( tmpdir(), 'chrnx-image-test-' ) );
|
||||
const unsafeOutput = join( output, 'unsafe-output' );
|
||||
try {
|
||||
assert.throws( () => execFileSync( './scripts/build-responsive-images.sh', [ unsafeOutput ], { cwd: new URL( '../..', import.meta.url ) } ) );
|
||||
execFileSync( './scripts/build-responsive-images.sh', [ output ], { cwd: new URL( '../..', import.meta.url ) } );
|
||||
const names = readdirSync( output ).sort();
|
||||
assert.equal( names.length, 35 );
|
||||
let total = 0;
|
||||
for ( const name of names ) {
|
||||
const generated = readFileSync( join( output, name ) );
|
||||
const committed = readFileSync( new URL( `../../assets/images/generated/${ name }`, import.meta.url ) );
|
||||
assert.deepEqual( generated, committed, `${ name } must rebuild byte-identically` );
|
||||
if ( /\.(?:avif|webp)$/.test( name ) ) {
|
||||
assert.ok( statSync( join( output, name ) ).size <= 160 * 1024, `${ name } exceeds 160 KiB` );
|
||||
const expectedWidth = Number( name.match( /-(384|768)\.(?:avif|webp)$/ )[ 1 ] );
|
||||
const dimensions = execFileSync( 'sips', [ '-g', 'pixelWidth', '-g', 'pixelHeight', join( output, name ) ], { encoding: 'utf8' } );
|
||||
assert.match( dimensions, new RegExp( `pixelWidth: ${ expectedWidth }` ) );
|
||||
assert.match( dimensions, /pixelHeight: [1-9][0-9]*/ );
|
||||
if ( name.endsWith( '.webp' ) ) {
|
||||
assert.equal( generated.subarray( 0, 4 ).toString(), 'RIFF' );
|
||||
assert.equal( generated.subarray( 8, 12 ).toString(), 'WEBP' );
|
||||
} else {
|
||||
assert.equal( generated.subarray( 4, 12 ).toString(), 'ftypavif' );
|
||||
}
|
||||
total += generated.length;
|
||||
}
|
||||
}
|
||||
assert.ok( total <= 1.7 * 1024 * 1024, `derivatives exceed 1.7 MiB: ${ total }` );
|
||||
} finally {
|
||||
rmSync( output, { recursive: true, force: true } );
|
||||
}
|
||||
} );
|
||||
|
||||
test( 'post-card CSS fallbacks never reuse approved section portraits', () => {
|
||||
const components = read( 'assets/css/components.css' );
|
||||
assert.doesNotMatch( components, /url\([^)]*(?:alter-ego-|the-no-names-musician-cutout)/ );
|
||||
} );
|
||||
|
||||
test( 'front page and section pages connect the real editorial patterns', () => {
|
||||
const front = read( 'templates/front-page.html' );
|
||||
assert.match( front, /chrnx\/home-intro/ );
|
||||
|
||||
Reference in new issue
Block a user