Deterministic test isolation
Deterministic test isolation means a test owns its state, dependencies and lifetime. Results should not depend on execution order, other tests or the current date. Create an independent temporary directory, database or namespace for each test. Reset fixture data from a known seed and use finally blocks or cleanup hooks. Parallel tests must not share mutable singleton state unless the test explicitly checks concurrency. Fixed inputs and controlled synchronization are better than sleeps for proving ordering. SQLite in-memory connections provide a real relational fixture but do not replicate every PostgreSQL behavior. Do not reset a shared production database or use a global cleanup wildcard. A transaction rollback cannot reset external effects such as already-delivered messages. Sources: https://nodejs.org/download/release/v22.16.0/docs/api/sqlite.html.
Formal Syntax & Structure
new DatabaseSync(":memory:"); db.close()Working Example
import {DatabaseSync} from 'node:sqlite';import assert from 'node:assert/strict';const a=new DatabaseSync(':memory:'),b=new DatabaseSync(':memory:');try{for(const db of [a,b])db.exec('CREATE TABLE items(id INTEGER PRIMARY KEY)');a.exec('INSERT INTO items VALUES(1)');const count=db=>db.prepare('SELECT count(*) AS n FROM items').get().n;assert.equal(count(a),1);assert.equal(count(b),0);console.log(count(a),count(b));}finally{a.close();b.close();}