Write tests that are (1) behavior-focused rather than implementation-coupled, and (2) use safe, consistently cleaned fixtures.
Do
const cleaned = await fs.readFile(instructionsPath, 'utf8');
assert(!cleaned.includes('BMAD:START') && !cleaned.includes('BMAD generated content'), 'markers removed');
assert(cleaned.includes('User content before') && cleaned.includes('User content after'), 'user content preserved');
fs.mkdtemp() (or equivalent) for temp directories and ensure you clean up the full parent directory you created.
async function createXFixture() {
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'my-suite-'));
const dir = path.join(root, '_subdir');
await fs.ensureDir(dir);
return { root, dir };
}
// teardown
await fs.rm(fixture.root, { recursive: true, force: true });
Don’t
Result: tests remain stable under refactors, and temp resources don’t leak or create flaky behavior across suites.