| 
 | 1 | +import { describe, test, expect } from "vitest";  | 
 | 2 | +import { FilesystemAdapter } from "./lib";  | 
 | 3 | + | 
 | 4 | +describe("FilesystemAdapter", () => {  | 
 | 5 | +	test("should be able to create a new instance", () => {  | 
 | 6 | +		const adapter = new FilesystemAdapter();  | 
 | 7 | +		expect(adapter).toBeDefined();  | 
 | 8 | +	});  | 
 | 9 | + | 
 | 10 | +	test("fullPath should return the full path of a file", () => {  | 
 | 11 | +		const adapter = new FilesystemAdapter("/root/dir");  | 
 | 12 | +		const file = adapter.file("file.txt");  | 
 | 13 | +		expect(adapter.getFullPath(file)).toBe("/root/dir/file.txt");  | 
 | 14 | +	});  | 
 | 15 | + | 
 | 16 | +	test("fullPath should return the full path of a directory", () => {  | 
 | 17 | +		const adapter = new FilesystemAdapter("/etc/loom");  | 
 | 18 | +		const dir = adapter.dir("dir");  | 
 | 19 | +		expect(adapter.getFullPath(dir)).toBe("/etc/loom/dir");  | 
 | 20 | +	});  | 
 | 21 | + | 
 | 22 | +	test("fullPath should fail to other adapters", () => {  | 
 | 23 | +		const adapter = new FilesystemAdapter("/etc/loom");  | 
 | 24 | +		const adapter2 = new FilesystemAdapter("/etc/loom");  | 
 | 25 | +		const dir2 = adapter2.dir("dir");  | 
 | 26 | +		expect(() => adapter.getFullPath(dir2)).toThrowError();  | 
 | 27 | +	});  | 
 | 28 | + | 
 | 29 | +	test("fullPath should return the full path also from other adapter if flag is set", () => {  | 
 | 30 | +		const adapter = new FilesystemAdapter("/etc/loom");  | 
 | 31 | +		const adapter2 = new FilesystemAdapter("/etc/loom");  | 
 | 32 | +		const dir2 = adapter2.dir("dir");  | 
 | 33 | +		expect(adapter.getFullPath(dir2, true)).toBe("/etc/loom/dir");  | 
 | 34 | +	});  | 
 | 35 | + | 
 | 36 | +	test("fullPath should return the full path of a file (cwd)", () => {  | 
 | 37 | +		const adapter = new FilesystemAdapter();  | 
 | 38 | +		const file = adapter.file("file.txt");  | 
 | 39 | +		expect(adapter.getFullPath(file)).toBe(process.cwd() + "/file.txt");  | 
 | 40 | +	});  | 
 | 41 | + | 
 | 42 | +	test("fullPath should return the full path of a directory (cwd)", () => {  | 
 | 43 | +		const adapter = new FilesystemAdapter();  | 
 | 44 | +		const dir = adapter.dir("dir");  | 
 | 45 | +		expect(adapter.getFullPath(dir)).toBe(process.cwd() + "/dir");  | 
 | 46 | +	});  | 
 | 47 | + | 
 | 48 | +	test("file should return a new LoomFile instance", () => {  | 
 | 49 | +		const adapter = new FilesystemAdapter();  | 
 | 50 | +		const file = adapter.file("file.txt");  | 
 | 51 | +		expect(file).toBeDefined();  | 
 | 52 | +	});  | 
 | 53 | + | 
 | 54 | +	test("dir should return a new Directory instance", () => {  | 
 | 55 | +		const adapter = new FilesystemAdapter();  | 
 | 56 | +		const dir = adapter.dir("dir");  | 
 | 57 | +		expect(dir).toBeDefined();  | 
 | 58 | +	});  | 
 | 59 | +});  | 
0 commit comments