From 13969c7070034c1b321998e466f9e5a128ace44c Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sat, 20 Jun 2026 16:33:36 -0400 Subject: refactor(theme-studio): dedup the inline-integrity test scaffolding Two test-DRY cleanups. The seven near-identical test_page_carries_*_verbatim methods in test_generate.py collapse into one subTest loop over the inlined-body names. The strip-exports helper -- reimplemented three times across the colormath, app-core, and app-util inline-integrity tests, each annotated 'same strip generate.py applies' -- moves to one shared inline-strip.mjs (stripInlinedBody), so the three copies can no longer drift from generate.py's strip_exports. --- scripts/theme-studio/test-app-core.mjs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'scripts/theme-studio/test-app-core.mjs') diff --git a/scripts/theme-studio/test-app-core.mjs b/scripts/theme-studio/test-app-core.mjs index 09ddf5aec..217ea0e6b 100644 --- a/scripts/theme-studio/test-app-core.mjs +++ b/scripts/theme-studio/test-app-core.mjs @@ -819,35 +819,34 @@ test('slugify: Error — an all-disallowed name falls back to "theme"', () => { // Guards the one-source-of-truth contract, same as the colormath integrity test: // the page must carry app-core.js's body (sans exports) verbatim. Requires // `python3 generate.py` to have run first. -const stripExports = (s) => - s.split('\n').filter((l) => !(l.startsWith('export') || l.startsWith('import'))).join('\n').replace(/\s+$/, ''); +import { stripInlinedBody } from './inline-strip.mjs'; test('inline-integrity: theme-studio.html contains the app-core.js body verbatim', () => { - const body = stripExports(readFileSync(here + 'app-core.js', 'utf8')); + const body = stripInlinedBody(readFileSync(here + 'app-core.js', 'utf8')); const html = readFileSync(here + 'theme-studio.html', 'utf8'); assert.ok(html.includes(body), 'generated page is missing the app-core.js body verbatim'); }); test('inline-integrity: theme-studio.html contains palette-generator-core.js verbatim', () => { - const body = stripExports(readFileSync(here + 'palette-generator-core.js', 'utf8')); + const body = stripInlinedBody(readFileSync(here + 'palette-generator-core.js', 'utf8')); const html = readFileSync(here + 'theme-studio.html', 'utf8'); assert.ok(html.includes(body), 'generated page is missing palette-generator-core.js verbatim'); }); test('inline-integrity: theme-studio.html contains palette-generator-ui.js verbatim', () => { - const body = stripExports(readFileSync(here + 'palette-generator-ui.js', 'utf8')); + const body = stripInlinedBody(readFileSync(here + 'palette-generator-ui.js', 'utf8')); const html = readFileSync(here + 'theme-studio.html', 'utf8'); assert.ok(html.includes(body), 'generated page is missing palette-generator-ui.js verbatim'); }); test('inline-integrity: theme-studio.html contains palette-actions.js verbatim', () => { - const body = stripExports(readFileSync(here + 'palette-actions.js', 'utf8')); + const body = stripInlinedBody(readFileSync(here + 'palette-actions.js', 'utf8')); const html = readFileSync(here + 'theme-studio.html', 'utf8'); assert.ok(html.includes(body), 'generated page is missing palette-actions.js verbatim'); }); test('inline-integrity: theme-studio.html contains browser-gates.js verbatim', () => { - const body = stripExports(readFileSync(here + 'browser-gates.js', 'utf8')); + const body = stripInlinedBody(readFileSync(here + 'browser-gates.js', 'utf8')); const html = readFileSync(here + 'theme-studio.html', 'utf8'); assert.ok(html.includes(body), 'generated page is missing browser-gates.js verbatim'); }); -- cgit v1.2.3