mirror of
https://github.com/nicotsx/zerobyte.git
synced 2026-06-04 06:28:45 -04:00
* chore: migrate to vitest * test: speed up some suites by sharing sessions and mocking expensive non-tested actions * test: refactor some tests to verify behavior instead of implementation details * chore: fix linting issues
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { describe, expect, test } from "vitest";
|
|
import { findCommonAncestor } from "@zerobyte/core/utils";
|
|
|
|
describe("findCommonAncestor", () => {
|
|
test("returns root for empty path lists", () => {
|
|
expect(findCommonAncestor([])).toBe("/");
|
|
});
|
|
|
|
test("returns the original path for single-item lists", () => {
|
|
expect(findCommonAncestor(["/var/lib/zerobyte/volumes/vol123/_data"])).toBe(
|
|
"/var/lib/zerobyte/volumes/vol123/_data",
|
|
);
|
|
});
|
|
|
|
test("returns the deepest shared ancestor for multiple absolute paths", () => {
|
|
expect(
|
|
findCommonAncestor([
|
|
"/var/lib/zerobyte/volumes/vol123/_data/Documents/report.pdf",
|
|
"/var/lib/zerobyte/volumes/vol123/_data/Photos/summer.jpg",
|
|
"/var/lib/zerobyte/volumes/vol123/_data/Music/track.mp3",
|
|
]),
|
|
).toBe("/var/lib/zerobyte/volumes/vol123/_data");
|
|
});
|
|
|
|
test("returns root when absolute paths only share the filesystem root", () => {
|
|
expect(findCommonAncestor(["/etc/hosts", "/usr/local/bin"])).toBe("/");
|
|
});
|
|
|
|
test("throws when any path is relative", () => {
|
|
expect(() => findCommonAncestor(["/var/lib/zerobyte", "relative/path"])).toThrow(
|
|
'Path "relative/path" is not absolute.',
|
|
);
|
|
});
|
|
});
|