67 lines
1.9 KiB
JavaScript
67 lines
1.9 KiB
JavaScript
/* 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)');
|