Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion packages/code-analyzer-core/test/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import {deepEquals} from "../src/utils";
import {deepEquals, RealFileSystem, TempFolder} from "../src/utils";
import * as fs from "node:fs";
import * as os from "node:os";
import * as path from "node:path";

describe('deepEquals function tests', () => {
describe('primitive type comparison tests', () => {
Expand Down Expand Up @@ -151,4 +154,30 @@ describe('deepEquals function tests', () => {
expect(deepEquals(obj1, obj2)).toBe(false);
});
});
});

describe('file system and temp folder utilities', () => {
it('RealFileSystem.rmSync removes a directory recursively (covers rmSync)', () => {
const realFs = new RealFileSystem();
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'ca-core-rmSync-'));
const nested = path.join(dir, 'nested');
fs.mkdirSync(nested);
fs.writeFileSync(path.join(nested, 'file.txt'), 'x');
expect(fs.existsSync(dir)).toBe(true);

realFs.rmSync(dir, {recursive: true, force: true});
expect(fs.existsSync(dir)).toBe(false);
});

it('TempFolder.removeSyncIfNotKept removes root when not marked to keep (covers removeSyncIfNotKept)', async () => {
const temp = new TempFolder(); // uses RealFileSystem internally
const subPath = await temp.getPath('sub');
const root = path.dirname(subPath);
fs.mkdirSync(subPath, {recursive: true});
fs.writeFileSync(path.join(subPath, 'a.txt'), 'content');
expect(fs.existsSync(root)).toBe(true);

temp.removeSyncIfNotKept();
expect(fs.existsSync(root)).toBe(false);
});
});