Initial commit

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>
This commit is contained in:
Michael Cartner
2024-01-26 11:52:55 +01:00
commit b9c60b07dc
2789 changed files with 868795 additions and 0 deletions

View File

@@ -0,0 +1,83 @@
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);
});
});

View File

@@ -0,0 +1,59 @@
import { describe, expect } from "@jest/globals";
import { FileSystemNode } from "../src/filesystem-node";
describe("File System", function () {
it("readFile: text.txt", async function () {
// arrange
const filesystem = new FileSystemNode();
const sourcePath = filesystem.join(
process.cwd(),
"/tests/testfs/file_types/text.txt"
);
// act
const content = await filesystem.readFile(sourcePath);
// assert
expect(content).toBe("Hello World");
});
it("readFile not found", async function () {
// arrange
const filesystem = new FileSystemNode();
const sourcePath = filesystem.join(
process.cwd(),
"/tests/testfs/file_types/not_found.txt"
);
// act & assert
await expect(() => filesystem.readFile(sourcePath)).rejects.toThrow();
});
it("readJson: json.json", async function () {
// arrange
const filesystem = new FileSystemNode();
const sourcePath = filesystem.join(
process.cwd(),
"/tests/testfs/file_types/json.json"
);
// act
const content = await filesystem.readJson(sourcePath);
// assert
expect(content).toEqual({ hello: "world" });
});
it("readJson not found", async function () {
// arrange
const filesystem = new FileSystemNode();
const sourcePath = filesystem.join(
process.cwd(),
"/tests/testfs/file_types/not_found.json"
);
// act & assert
await expect(() => filesystem.readJson(sourcePath)).rejects.toThrow();
});
});

View File

@@ -0,0 +1,104 @@
import { describe, expect } from '@jest/globals';
import { FileSystemNode } from '../src/filesystem-node';
import { PlatformNode } from '../src/platform-node';
describe('File System', function () {
// TODO: Skipped because the folder contained package.json, which was picked up by lerna.
xit('can sync dirs', async function () {
const platform = new PlatformNode();
const filesystem = new FileSystemNode();
const tempDir = filesystem.join(platform.getTempPath(), 'noodlunittests-filesystem-' + Date.now());
const destPath = filesystem.join(tempDir, 'dst1');
const sourcePath = filesystem.join(process.cwd(), '/tests/testfs/fs_sync_dir_tests/dst1');
await filesystem.makeDirectory(tempDir);
await filesystem.copyFolder(sourcePath, destPath);
const files = {
'/dst1/popout-will-be-removed.svg': true,
'/dst1/should-be-removed/test.js': true,
'/dst1/project.json': true,
'/dst1/loginsplash.jpg': false,
'/dst1/test.js': false,
'/dst1/test/ajax-loader.gif': false,
'/dst1/one/delete-me/Roboto-Black.ttf': true,
'/dst1/one/two/loginsplash2.jpg': false
};
Object.keys(files).forEach((file) => {
const filePath = filesystem.join(tempDir, file);
const fileExists = filesystem.exists(filePath);
expect(fileExists).toBe(files[file]);
});
});
// TODO: Skipped because the folder contained package.json, which was picked up by lerna.
xit('can remove dirs without a slash ending', async function () {
const platform = new PlatformNode();
const filesystem = new FileSystemNode();
const tempDir = filesystem.join(platform.getTempPath(), 'noodlunittests-filesystem-' + Date.now());
const sourcePath = filesystem.join(process.cwd(), '/tests/testfs/fs_sync_dir_tests/dst1');
await filesystem.makeDirectory(tempDir);
await filesystem.copyFolder(sourcePath, tempDir);
filesystem.removeDirRecursive(tempDir);
expect(filesystem.exists(tempDir)).toBe(false);
});
// TODO: Skipped because the folder contained package.json, which was picked up by lerna.
xit('can remove dirs with a slash ending', async function () {
const platform = new PlatformNode();
const filesystem = new FileSystemNode();
const tempDir = filesystem.join(platform.getTempPath(), 'noodlunittests-filesystem-' + Date.now()) + '/';
const sourcePath = filesystem.join(process.cwd(), '/tests/testfs/fs_sync_dir_tests/dst1');
await filesystem.makeDirectory(tempDir);
await filesystem.copyFolder(sourcePath, tempDir);
filesystem.removeDirRecursive(tempDir);
expect(filesystem.exists(tempDir)).toBe(false);
});
// it("can copy dirs and ignore specific files", async function () {
// const platform = new PlatformNode();
// const filesystem = new FileSystemNode();
//
// const tempDir = filesystem.join(
// platform.getTempPath(),
// "noodlunittests-filesystem-" + Date.now()
// );
// const sourcePath = filesystem.join(
// process.cwd(),
// "/tests/testfs/fs_sync_dir_tests/dst1"
// );
//
// await filesystem.makeDirectory(tempDir);
// await filesystem.copyFolder(sourcePath, tempDir, {
// filter(src) {
// return !src.includes(path.sep + "test" + path.sep);
// },
// });
//
// expect(
// filesystem.exists(filesystem.resolve(tempDir, "test/ajax-loader.gif"))
// ).toBe(false);
// expect(
// filesystem.exists(filesystem.resolve(tempDir, "loginsplash.jpg"))
// ).toBe(true);
// expect(filesystem.exists(filesystem.resolve(tempDir, "project.json"))).toBe(
// true
// );
// expect(filesystem.exists(filesystem.resolve(tempDir, "test.js"))).toBe(
// true
// );
// });
});

View File

@@ -0,0 +1,3 @@
{
"hello": "world"
}

View File

@@ -0,0 +1 @@
Hello World

View File

@@ -0,0 +1 @@
Hello World