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

34
test/lib/setup.mjs Normal file
View File

@@ -0,0 +1,34 @@
import { execSync, spawn } from 'node:child_process';
import { mkdtempSync, mkdirSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
const FA2JSON = new URL('../../fa2json', import.meta.url).pathname;
export async function setup() {
// Create image file and format
const img = execSync('mktemp /tmp/fa2json-test-XXXXXX.img').toString().trim();
execSync(`truncate -s 10M ${img}`);
execSync(`mkfs.ext4 -q ${img}`);
// Create mount point and mount
const mnt = execSync('mktemp -d /tmp/fa2json-mnt-XXXXXX').toString().trim();
execSync(`sudo mount ${img} ${mnt}`);
// Hand ownership to current user, then sync before fa2json starts
execSync(`sudo chown ${process.getuid()} ${mnt}`);
execSync('sync');
async function teardown() {
try { execSync(`sudo umount ${mnt}`); } catch {}
try { execSync(`rm -f ${img}`); } catch {}
try { execSync(`rmdir ${mnt}`); } catch {}
}
return { img, mnt, teardown };
}
export function spawnFa2json(mnt) {
const proc = spawn('sudo', [FA2JSON, mnt], { stdio: ['ignore', 'pipe', 'inherit'] });
return proc;
}