@mdfriday/foundry
Version:
The core engine of MDFriday. Convert Markdown and shortcodes into fully themed static sites – Hugo-style, powered by TypeScript.
230 lines • 10.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = require("../entity/fs");
const static_copier_1 = require("../vo/static-copier");
const incremental_file_collector_1 = require("../vo/incremental-file-collector");
// Mock dependencies
jest.mock('../entity/service');
jest.mock('../vo/static-copier');
jest.mock('../vo/incremental-file-collector');
jest.mock('../vo/walkway');
jest.mock('../entity/basefs');
describe('Fs Entity', () => {
let mockOriginFs;
let mockPrompts;
let mockWorkflows;
let mockContent;
let mockLayouts;
let mockStatics;
let mockAssets;
let mockWork;
let mockService;
let fs;
beforeEach(() => {
// Create mock filesystems
mockOriginFs = {
getOrigin: jest.fn(),
getSource: jest.fn(),
publish: jest.fn(),
};
mockPrompts = {};
mockWorkflows = {};
mockContent = {};
mockLayouts = {};
mockStatics = {};
mockAssets = {};
mockWork = {};
// Mock service
mockService = {
newFileMetaInfo: jest.fn(),
newFileMetaInfoWithContent: jest.fn(),
};
// Mock the newService function
const { newService } = require('../entity/service');
newService.mockReturnValue(mockService);
// Create Fs instance
fs = new fs_1.Fs(mockOriginFs, mockPrompts, mockWorkflows, mockContent, mockLayouts, mockStatics, mockAssets, mockWork);
});
afterEach(() => {
jest.clearAllMocks();
});
describe('constructor', () => {
it('should initialize all filesystem properties correctly', () => {
expect(fs.originFs).toBe(mockOriginFs);
expect(fs.prompts).toBe(mockPrompts);
expect(fs.workflows).toBe(mockWorkflows);
expect(fs.content).toBe(mockContent);
expect(fs.layouts).toBe(mockLayouts);
expect(fs.statics).toBe(mockStatics);
expect(fs.assets).toBe(mockAssets);
expect(fs.work).toBe(mockWork);
expect(fs.service).toBe(mockService);
});
});
describe('filesystem access methods', () => {
it('should return OS filesystem from originFs', () => {
const mockOsFs = {};
mockOriginFs.getOrigin.mockReturnValue(mockOsFs);
const result = fs.os();
expect(result).toBe(mockOsFs);
expect(mockOriginFs.getOrigin).toHaveBeenCalledTimes(1);
});
it('should return work filesystem', () => {
const result = fs.workFs();
expect(result).toBe(mockWork);
});
it('should return workflow filesystem', () => {
const result = fs.workflowFs();
expect(result).toBe(mockWorkflows);
});
it('should return prompt filesystem', () => {
const result = fs.promptFs();
expect(result).toBe(mockPrompts);
});
it('should return content filesystem', () => {
const result = fs.contentFs();
expect(result).toBe(mockContent);
});
it('should return layouts filesystem', () => {
const result = fs.layoutsFs();
expect(result).toBe(mockLayouts);
});
it('should return static filesystem', () => {
const result = fs.staticFs();
expect(result).toBe(mockStatics);
});
it('should return assets filesystem', () => {
const result = fs.assetsFs();
expect(result).toBe(mockAssets);
});
it('should return publish filesystem from originFs', () => {
const mockPublishFs = {};
mockOriginFs.publish.mockReturnValue(mockPublishFs);
const result = fs.publishFs();
expect(result).toBe(mockPublishFs);
expect(mockOriginFs.publish).toHaveBeenCalledTimes(1);
});
});
describe('copyStatic', () => {
it('should create StaticCopier and call copy', () => {
const mockFroms = [{}, {}];
const mockTo = {};
const mockCopyResult = Promise.resolve();
const mockStaticCopier = {
copy: jest.fn().mockReturnValue(mockCopyResult),
};
static_copier_1.StaticCopier.mockImplementation(() => mockStaticCopier);
const result = fs.copyStatic(mockFroms, mockTo);
expect(static_copier_1.StaticCopier).toHaveBeenCalledWith(mockFroms, mockTo);
expect(mockStaticCopier.copy).toHaveBeenCalledTimes(1);
expect(result).toBe(mockCopyResult);
});
});
describe('FileMetaInfo creation methods', () => {
it('should create FileMetaInfo with filename', () => {
const filename = 'test.txt';
const mockFileMetaInfo = {};
mockService.newFileMetaInfo.mockReturnValue(mockFileMetaInfo);
const result = fs.newFileMetaInfo(filename);
expect(result).toBe(mockFileMetaInfo);
expect(mockService.newFileMetaInfo).toHaveBeenCalledWith(filename);
});
it('should create FileMetaInfo with content', () => {
const content = 'test content';
const mockFileMetaInfo = {};
mockService.newFileMetaInfoWithContent.mockReturnValue(mockFileMetaInfo);
const result = fs.newFileMetaInfoWithContent(content);
expect(result).toBe(mockFileMetaInfo);
expect(mockService.newFileMetaInfoWithContent).toHaveBeenCalledWith(content);
});
});
describe('getFileMetaInfos', () => {
it('should collect FileMetaInfos for given paths', async () => {
const paths = ['path1', 'path2'];
const mockResult = new Map([['path1', {}]]);
incremental_file_collector_1.collectFileMetaInfos.mockResolvedValue(mockResult);
const result = await fs.getFileMetaInfos(paths);
expect(result).toBe(mockResult);
expect(incremental_file_collector_1.collectFileMetaInfos).toHaveBeenCalledWith(paths, mockContent);
});
});
describe('newBasePathFs', () => {
it('should create new base path filesystem', () => {
const mockSource = {};
const path = '/test/path';
const mockBaseFs = {};
// Get the mocked newBaseFs function
const { newBaseFs } = require('../entity/basefs');
newBaseFs.mockReturnValue(mockBaseFs);
const result = fs.newBasePathFs(mockSource, path);
expect(result).toBe(mockBaseFs);
expect(newBaseFs).toHaveBeenCalledWith(mockSource, [path]);
});
});
describe('walk methods', () => {
let mockWalkway;
let mockCallback;
let mockConfig;
beforeEach(() => {
mockWalkway = {
walkWith: jest.fn().mockResolvedValue(undefined),
};
const { newWalkway } = require('../vo/walkway');
newWalkway.mockReturnValue(mockWalkway);
mockCallback = {
walkFn: jest.fn(),
};
mockConfig = {};
});
it('should walk prompts filesystem', async () => {
const start = '/prompts';
await fs.walkPrompts(start, mockCallback, mockConfig);
const { newWalkway } = require('../vo/walkway');
expect(newWalkway).toHaveBeenCalledWith(mockPrompts, mockCallback);
expect(mockWalkway.walkWith).toHaveBeenCalledWith(start, mockConfig);
});
it('should walk workflows filesystem', async () => {
const start = '/workflows';
await fs.walkWorkflows(start, mockCallback, mockConfig);
const { newWalkway } = require('../vo/walkway');
expect(newWalkway).toHaveBeenCalledWith(mockWorkflows, mockCallback);
expect(mockWalkway.walkWith).toHaveBeenCalledWith(start, mockConfig);
});
it('should walk layouts filesystem', async () => {
const start = '/layouts';
await fs.walkLayouts(start, mockCallback, mockConfig);
const { newWalkway } = require('../vo/walkway');
expect(newWalkway).toHaveBeenCalledWith(mockLayouts, mockCallback);
expect(mockWalkway.walkWith).toHaveBeenCalledWith(start, mockConfig);
});
it('should walk content filesystem', async () => {
const start = '/content';
await fs.walkContent(start, mockCallback, mockConfig);
const { newWalkway } = require('../vo/walkway');
expect(newWalkway).toHaveBeenCalledWith(mockContent, mockCallback);
expect(mockWalkway.walkWith).toHaveBeenCalledWith(start, mockConfig);
});
it('should walk statics filesystem', async () => {
const start = '/statics';
await fs.walkStatics(start, mockCallback, mockConfig);
const { newWalkway } = require('../vo/walkway');
expect(newWalkway).toHaveBeenCalledWith(mockStatics, mockCallback);
expect(mockWalkway.walkWith).toHaveBeenCalledWith(start, mockConfig);
});
it('should use default root path when start is empty', async () => {
const start = '';
await fs.walk(mockContent, start, mockCallback, mockConfig);
const { newWalkway } = require('../vo/walkway');
expect(newWalkway).toHaveBeenCalledWith(mockContent, mockCallback);
expect(mockWalkway.walkWith).toHaveBeenCalledWith('/', mockConfig);
});
it('should use provided start path when not empty', async () => {
const start = '/custom/path';
await fs.walk(mockContent, start, mockCallback, mockConfig);
const { newWalkway } = require('../vo/walkway');
expect(newWalkway).toHaveBeenCalledWith(mockContent, mockCallback);
expect(mockWalkway.walkWith).toHaveBeenCalledWith(start, mockConfig);
});
});
});
//# sourceMappingURL=entity-fs.test.js.map