initial commit

This commit is contained in:
2026-09-12 14:29:44 +02:00
commit b65af3aae7
14 changed files with 1746 additions and 0 deletions
+66
View File
@@ -0,0 +1,66 @@
/* Rebuilds tests/harness.html from tests/fixture.json and the current sources.
*
* Everything is inlined rather than linked, so the harness renders identically
* under file:// and headless screenshots, with no subresource loading rules to
* worry about. Run it after any change to src/.
*
* node tests/build-harness.js && tests/shot.sh
*/
const fs = require('fs');
const path = require('path');
const root = path.join(__dirname, '..');
const read = (p) => fs.readFileSync(path.join(root, p), 'utf8');
const fixturePath = path.join(__dirname, 'fixture.json');
if (!fs.existsSync(fixturePath)) {
console.error('missing tests/fixture.json — capture it with tools/make-fixture.js');
process.exit(1);
}
const fixture = JSON.parse(fs.readFileSync(fixturePath, 'utf8'));
const vars = Object.entries(fixture.vars || {})
.map(([k, v]) => ` ${k}: ${v};`).join('\n');
const html = `<!doctype html>
<meta charset="utf-8">
<title>Piscine Graph Tweaks — harness</title>
<style>
:root {
${vars}
}
body {
margin: 0;
background: ${fixture.bodyBackground || '#1f2020'};
font: 14px system-ui, sans-serif;
color: #ccc;
}
.harness-note { padding: 10px 14px; color: #8b919d; }
.graph-wrap { padding: 0 14px 40px; }
${read('src/panel.css')}
</style>
<div class="harness-note">
harness — fixture captured ${fixture.capturedAt || '?'} from ${fixture.url || '?'}
</div>
<div class="graph-wrap">
${fixture.svg}
</div>
<script>
${read('src/viewer.js')}
</script>
<script>
${read('src/content.js')}
</script>
<script>
// #viewer in the URL opens the full screen view straight away, so a headless
// screenshot can capture it without a click.
if (location.hash === '#viewer') {
setTimeout(() => window.__pgtViewer && window.__pgtViewer.toggle(window.__pgtNodes || []), 400);
}
</script>
`;
fs.writeFileSync(path.join(__dirname, 'harness.html'), html);
console.log('tests/harness.html written (' + html.length + ' bytes)');
Executable
+19
View File
@@ -0,0 +1,19 @@
#!/bin/sh
# Screenshot the harness with headless Firefox.
# tests/shot.sh [output.png] [width,height] [#hash]
# A dedicated profile is used so it never collides with the running browser.
set -eu
cd "$(dirname "$0")"
out=${1:-shot.png}
size=${2:-1600,1000}
hash=${3:-}
profile=${TMPDIR:-/tmp}/pgt-ff-profile
mkdir -p "$profile"
timeout 120 firefox --headless --no-remote --profile "$profile" \
--screenshot "$PWD/$out" --window-size "$size" \
"file://$PWD/harness.html$hash" >/dev/null 2>&1
echo "$PWD/$out"