UNPKG

@mdfriday/foundry

Version:

The core engine of MDFriday. Convert Markdown and shortcodes into fully themed static sites – Hugo-style, powered by TypeScript.

197 lines 9.83 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); const ConfigModule = __importStar(require("../index")); describe('Config Module Exports', () => { describe('Type Exports', () => { it('should export all type interfaces', () => { // Check if types are properly exported by trying to use them expect(typeof ConfigModule.ConfigError).toBe('function'); expect(ConfigModule.ErrConfigNotFound).toBeDefined(); expect(ConfigModule.ErrInvalidConfig).toBeDefined(); expect(ConfigModule.ErrWorkspaceNotFound).toBeDefined(); expect(ConfigModule.ErrConfigFileNotFound).toBeDefined(); expect(ConfigModule.ErrInvalidConfigFormat).toBeDefined(); }); }); describe('Entity Exports', () => { it('should export Config entity and factory', () => { expect(typeof ConfigModule.Config).toBe('function'); expect(typeof ConfigModule.newConfig).toBe('function'); }); it('should export Root entity and factory', () => { expect(typeof ConfigModule.Root).toBe('function'); expect(typeof ConfigModule.newRoot).toBe('function'); }); it('should export Module entity and factory', () => { expect(typeof ConfigModule.Module).toBe('function'); expect(typeof ConfigModule.newModule).toBe('function'); }); it('should export Service entity and factory', () => { expect(typeof ConfigModule.Service).toBe('function'); expect(typeof ConfigModule.newService).toBe('function'); }); it('should export Language entity and factory', () => { expect(typeof ConfigModule.Language).toBe('function'); expect(typeof ConfigModule.newLanguage).toBe('function'); }); it('should export Taxonomy entity and factory', () => { expect(typeof ConfigModule.Taxonomy).toBe('function'); expect(typeof ConfigModule.newTaxonomy).toBe('function'); }); }); describe('Factory Exports', () => { it('should export loadConfigWithParams factory function', () => { expect(typeof ConfigModule.loadConfigWithParams).toBe('function'); }); }); describe('Value Object Exports', () => { it('should export all value object modules', () => { // These are star exports, so we check for specific known exports expect(ConfigModule.DefaultRootConfig).toBeDefined(); expect(ConfigModule.decodeRootConfig).toBeDefined(); expect(ConfigModule.EmptyModuleConfig).toBeDefined(); expect(ConfigModule.decodeModuleConfig).toBeDefined(); expect(ConfigModule.DefaultServiceConfig).toBeDefined(); expect(ConfigModule.decodeServiceConfig).toBeDefined(); }); }); describe('Module Integration', () => { it('should allow creating entities using exported factories', () => { // Test that exported factories can be used together const rootData = { baseURL: 'https://test.com', title: 'Integration Test', theme: ['test-theme'] }; const root = ConfigModule.newRoot(rootData); expect(root).toBeInstanceOf(ConfigModule.Root); expect(root.baseUrl()).toBe('https://test.com'); expect(root.siteTitle()).toBe('Integration Test'); }); it('should allow using value object functions', () => { const rootConfig = ConfigModule.decodeRootConfig({ baseURL: 'https://vo-test.com', title: 'VO Test' }); expect(rootConfig.baseURL).toBe('https://vo-test.com'); expect(rootConfig.title).toBe('VO Test'); const moduleConfig = ConfigModule.decodeModuleConfig({ mounts: [{ source: 'content', target: 'content' }] }); expect(moduleConfig.mounts).toHaveLength(1); expect(moduleConfig.mounts[0].source).toBe('content'); }); it('should allow using service configuration', () => { const serviceConfig = ConfigModule.decodeServiceConfig({ services: { googleAnalytics: { id: 'GA-TEST123' } } }); expect(serviceConfig.googleAnalytics.id).toBe('GA-TEST123'); }); it('should provide default configurations', () => { expect(ConfigModule.DefaultRootConfig.contentDir).toBe('content'); expect(ConfigModule.DefaultRootConfig.defaultContentLanguage).toBe('en'); expect(ConfigModule.DefaultRootConfig.buildDrafts).toBe(false); expect(ConfigModule.EmptyModuleConfig.mounts).toEqual([]); expect(ConfigModule.EmptyModuleConfig.imports).toEqual([]); expect(ConfigModule.DefaultServiceConfig.disqus.disable).toBe(false); expect(ConfigModule.DefaultServiceConfig.googleAnalytics.disable).toBe(false); expect(ConfigModule.DefaultServiceConfig.rss.limit).toBe(0); }); it('should handle error types correctly', () => { const customError = new ConfigModule.ConfigError('Custom test error', 'CUSTOM_ERROR'); expect(customError).toBeInstanceOf(Error); expect(customError.name).toBe('ConfigError'); expect(customError.message).toBe('Custom test error'); expect(customError.code).toBe('CUSTOM_ERROR'); // Test predefined errors expect(() => { throw ConfigModule.ErrConfigNotFound; }).toThrow('configuration not found'); expect(() => { throw ConfigModule.ErrInvalidConfig; }).toThrow('invalid configuration'); }); }); describe('API Consistency', () => { it('should have consistent naming pattern for factories', () => { // All entity factories should follow the "new{EntityName}" pattern expect(typeof ConfigModule.newConfig).toBe('function'); expect(typeof ConfigModule.newRoot).toBe('function'); expect(typeof ConfigModule.newModule).toBe('function'); expect(typeof ConfigModule.newService).toBe('function'); expect(typeof ConfigModule.newLanguage).toBe('function'); expect(typeof ConfigModule.newTaxonomy).toBe('function'); }); it('should have consistent naming pattern for value object decoders', () => { // All VO decoders should follow the "decode{VoName}Config" pattern expect(typeof ConfigModule.decodeRootConfig).toBe('function'); expect(typeof ConfigModule.decodeModuleConfig).toBe('function'); expect(typeof ConfigModule.decodeServiceConfig).toBe('function'); }); it('should have consistent naming pattern for default configurations', () => { // All default configs should follow the "Default{Name}Config" pattern expect(ConfigModule.DefaultRootConfig).toBeDefined(); expect(ConfigModule.DefaultServiceConfig).toBeDefined(); expect(ConfigModule.EmptyModuleConfig).toBeDefined(); // Special case for empty }); }); describe('Type Safety', () => { it('should maintain type safety across exports', () => { // This is more of a compile-time check, but we can verify runtime behavior const root = ConfigModule.newRoot({ baseURL: 'https://type-safety.test', buildDrafts: true }); // These should be properly typed expect(typeof root.baseUrl()).toBe('string'); expect(typeof root.shouldBuildDrafts()).toBe('boolean'); expect(Array.isArray(root.getThemes())).toBe(true); }); it('should handle optional parameters correctly', () => { const rootWithoutParams = ConfigModule.newRoot({ title: 'No Params Test' }); const rootWithParams = ConfigModule.newRoot({ title: 'With Params Test' }, { author: 'Test Author' }); expect(rootWithoutParams.configParams()).toEqual({}); expect(rootWithParams.configParams()).toEqual({ author: 'Test Author' }); }); }); }); //# sourceMappingURL=index.test.js.map