// Minimal test harness (temporary until Node 18 + Vitest restored)
export const results = [];
const pending = [];
let currentSuite = null;
export function describe(name, fn){
const suite = { suite: name, tests: [] };
results.push(suite);
currentSuite = suite;
fn(test);
currentSuite = null;
}
export function test(title, fn){
const suite = currentSuite || { suite: 'root', tests: [] };
if(!results.includes(suite)) results.push(suite);
try {
const ret = fn();
if(ret && typeof ret.then === 'function') {
// async
const p = ret.then(()=> suite.tests.push({ title, ok: true }))
.catch(e=> suite.tests.push({ title, ok:false, error:e }));
pending.push(p);
return p;
}
suite.tests.push({ title, ok:true });
} catch(e) {
suite.tests.push({ title, ok:false, error:e });
}
}
export function expect(received){
return {
toBe(val){ if(received !== val) throw new Error(`Expected ${received} to be ${val}`); },
toEqual(val){ const r = JSON.stringify(received); const v = JSON.stringify(val); if(r!==v) throw new Error(`Expected ${r} to equal ${v}`); },
toBeTruthy(){ if(!received) throw new Error(`Expected value to be truthy`); },
toBeFalsy(){ if(received) throw new Error(`Expected value to be falsy`); },
toContain(item){ if(!Array.isArray(received) || !received.includes(item)) throw new Error(`Expected array to contain ${item}`); }
};
}
export async function runTests(){
if(pending.length) {
await Promise.allSettled(pending);
}
report();
}
export function report(){
let fail = 0, pass = 0;
for(const s of results){
console.log(`\n# ${s.suite}`);
for(const t of s.tests){
if(t.ok){ pass++; console.log('✔', t.title); }
else { fail++; console.log('✖', t.title, '-', t.error?.message); }
}
}
console.log(`\nSummary: ${pass} passed, ${fail} failed`);
if(fail>0) process.exit(1);
}