Skip to content

Commit

Permalink
fix(utils.ts): add existsSync check before removing temp directory to…
Browse files Browse the repository at this point in the history
… prevent errors if directory does not exist (#401)
  • Loading branch information
matscube authored Sep 1, 2024
1 parent e063faa commit 68dc9c3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions test/unit/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mkdtemp, rm, writeFile } from 'fs';
import { existsSync, mkdtemp, rm, writeFile } from 'fs';
import { tmpdir } from 'os';
import path from 'path';
import { promisify } from 'util';
Expand All @@ -19,7 +19,11 @@ export async function prepareFile(
const tempDir = await fsMakeTempDir(path.join(tmpdir(), 'opencommit-test-'));
const filePath = path.resolve(tempDir, fileName);
await fsWriteFile(filePath, content);
const cleanup = async () => fsRemove(tempDir, { recursive: true });
const cleanup = async () => {
if (existsSync(tempDir)) {
await fsRemove(tempDir, { recursive: true });
}
};

return {
filePath,
Expand Down

0 comments on commit 68dc9c3

Please sign in to comment.