Add test harness: setup lib, dev mode, automated test runner

This commit is contained in:
2026-03-04 22:00:59 +00:00
parent f8aed56faf
commit 448e27ed8e
4 changed files with 217 additions and 0 deletions

43
test/dev.mjs Normal file
View File

@@ -0,0 +1,43 @@
#!/usr/bin/env node
// Developer mode: set up loop device, stream fa2json output through jq,
// tear down on exit. Optionally launch a terminal at the mount point.
//
// Usage:
// sudo node test/dev.mjs
// sudo node test/dev.mjs --terminal konsole
// sudo node test/dev.mjs --terminal "konsole -e bash"
import { spawn } from 'node:child_process';
import { createInterface } from 'node:readline';
import { setup, spawnFa2json } from './lib/setup.mjs';
const terminalArg = (() => {
const i = process.argv.indexOf('--terminal');
return i !== -1 ? process.argv.slice(i + 1).join(' ') : null;
})();
const { mnt, teardown } = await setup();
console.error(`Mount point: ${mnt}`);
// Pipe fa2json stdout through jq for pretty coloured output
const fa2json = spawnFa2json(mnt);
const jq = spawn('jq', ['-C', '--unbuffered', '.'], { stdio: ['pipe', 'inherit', 'inherit'] });
fa2json.stdout.pipe(jq.stdin);
fa2json.on('exit', async () => {
jq.stdin.end();
await teardown();
process.exit(0);
});
// Launch optional terminal at mount point
if (terminalArg) {
const [cmd, ...args] = terminalArg.split(' ');
spawn(cmd, [...args, '--workdir', mnt], { detached: true, stdio: 'ignore' }).unref();
console.error(`Launched: ${terminalArg} --workdir ${mnt}`);
}
// Clean teardown on Ctrl+C
process.on('SIGINT', async () => {
fa2json.kill('SIGTERM');
});