mirror of
https://github.com/noodlapp/noodl.git
synced 2026-01-11 23:02:53 +01:00
Co-Authored-By: Eric Tuvesson <eric.tuvesson@gmail.com> Co-Authored-By: mikaeltellhed <2311083+mikaeltellhed@users.noreply.github.com> Co-Authored-By: kotte <14197736+mrtamagotchi@users.noreply.github.com> Co-Authored-By: Anders Larsson <64838990+anders-topp@users.noreply.github.com> Co-Authored-By: Johan <4934465+joolsus@users.noreply.github.com> Co-Authored-By: Tore Knudsen <18231882+torekndsn@users.noreply.github.com> Co-Authored-By: victoratndl <99176179+victoratndl@users.noreply.github.com>
84 lines
2.3 KiB
TypeScript
84 lines
2.3 KiB
TypeScript
import { describe, expect } from "@jest/globals";
|
|
|
|
import { FileSystemNode } from "../src/filesystem-node";
|
|
|
|
describe("File System", function () {
|
|
it("isDirectoryEmpty: false", async function () {
|
|
// arrange
|
|
const filesystem = new FileSystemNode();
|
|
const sourcePath = filesystem.join(
|
|
process.cwd(),
|
|
"/tests/testfs/list_tests/folder1"
|
|
);
|
|
|
|
// act
|
|
const isEmpty = await filesystem.isDirectoryEmpty(sourcePath);
|
|
|
|
// assert
|
|
expect(isEmpty).toBeFalsy();
|
|
});
|
|
|
|
it("isDirectoryEmpty: true", async function () {
|
|
// arrange
|
|
const filesystem = new FileSystemNode();
|
|
const sourcePath = filesystem.join(
|
|
process.cwd(),
|
|
"/tests/testfs/empty_folder"
|
|
);
|
|
|
|
// We cant save empty folders in git
|
|
await filesystem.makeDirectory(sourcePath);
|
|
|
|
// act
|
|
const isEmpty = await filesystem.isDirectoryEmpty(sourcePath);
|
|
|
|
// assert
|
|
expect(isEmpty).toBeTruthy();
|
|
});
|
|
|
|
it("listDirectory", async function () {
|
|
// arrange
|
|
const filesystem = new FileSystemNode();
|
|
const sourcePath = filesystem.join(
|
|
process.cwd(),
|
|
"/tests/testfs/list_tests"
|
|
);
|
|
|
|
// act
|
|
const items = await filesystem.listDirectory(sourcePath);
|
|
|
|
// assert
|
|
expect(items.length).toBe(3);
|
|
expect(items[0].name).toBe("file2.txt");
|
|
expect(items[0].isDirectory).toBe(false);
|
|
expect(items[1].name).toBe("folder1");
|
|
expect(items[1].isDirectory).toBe(true);
|
|
expect(items[2].name).toBe("folder2");
|
|
expect(items[2].isDirectory).toBe(true);
|
|
});
|
|
|
|
it("listDirectoryFiles", async function () {
|
|
// arrange
|
|
const filesystem = new FileSystemNode();
|
|
const sourcePath = filesystem.join(
|
|
process.cwd(),
|
|
"/tests/testfs/list_tests"
|
|
);
|
|
|
|
// act
|
|
let items = await filesystem.listDirectoryFiles(sourcePath);
|
|
items = items.sort((a, b) => (a.name > b.name ? 1 : -1));
|
|
|
|
// assert
|
|
expect(items.length).toBe(4);
|
|
expect(items[0].name).toBe("file1.txt");
|
|
expect(items[0].isDirectory).toBe(false);
|
|
expect(items[1].name).toBe("file2.txt");
|
|
expect(items[1].isDirectory).toBe(false);
|
|
expect(items[2].name).toBe("file3.txt");
|
|
expect(items[2].isDirectory).toBe(false);
|
|
expect(items[3].name).toBe("file4.txt");
|
|
expect(items[3].isDirectory).toBe(false);
|
|
});
|
|
});
|