fix: make tempDir unique across fast test runs

Use a counter to ensure each tempDir call gets a unique directory name,
preventing collisions when tests run within the same millisecond.
This commit is contained in:
jiayiyan
2026-05-18 16:24:37 +08:00
parent 43969446e9
commit c2ae76d8b7
+2 -1
View File
@@ -15,8 +15,9 @@ function makeSpawn(result: MockSpawnResult) {
return mock(async (_cmd: string, _args: string[], _opts: SpawnCliConfig) => result); return mock(async (_cmd: string, _args: string[], _opts: SpawnCliConfig) => result);
} }
let tempDirCounter = 0;
function tempDir(): string { function tempDir(): string {
const dir = join(tmpdir(), `differ-test-${Date.now()}`); const dir = join(tmpdir(), `differ-test-${Date.now()}-${tempDirCounter++}`);
mkdirSync(dir, { recursive: true }); mkdirSync(dir, { recursive: true });
return dir; return dir;
} }