UNPKG

@prism-engineer/router

Version:

Type-safe Express.js router with automatic client generation

107 lines 5.95 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const vitest_1 = require("vitest"); const router_1 = require("../../router"); const path_1 = __importDefault(require("path")); (0, vitest_1.describe)('Router System - Route Loading', () => { let router; (0, vitest_1.beforeEach)(() => { router = (0, router_1.createRouter)(); vitest_1.vi.clearAllMocks(); }); (0, vitest_1.it)('should load routes from a single directory with JavaScript pattern', async () => { const fixturesPath = path_1.default.join(process.cwd(), 'dist/tests/router/fixtures/api'); await router.loadRoutes(fixturesPath, /\.js$/); (0, vitest_1.expect)(router.app).toBeDefined(); (0, vitest_1.expect)(typeof router.loadRoutes).toBe('function'); }); (0, vitest_1.it)('should load routes with specific filename pattern', async () => { const fixturesPath = path_1.default.join(process.cwd(), 'dist/tests/router/fixtures/api'); // Load only files matching 'hello.js' await router.loadRoutes(fixturesPath, /hello\.js$/); (0, vitest_1.expect)(router.app).toBeDefined(); }); (0, vitest_1.it)('should load routes from nested directories', async () => { const fixturesPath = path_1.default.join(process.cwd(), 'dist/tests/router/fixtures/api/v1'); await router.loadRoutes(fixturesPath, /\.js$/); (0, vitest_1.expect)(router.app).toBeDefined(); }); (0, vitest_1.it)('should load routes with JavaScript pattern', async () => { const fixturesPath = path_1.default.join(process.cwd(), 'dist/tests/router/fixtures/api'); // This should find .js files in our compiled test setup await router.loadRoutes(fixturesPath, /\.js$/); (0, vitest_1.expect)(router.app).toBeDefined(); }); (0, vitest_1.it)('should handle non-existent directories', async () => { const nonExistentPath = path_1.default.join(__dirname, 'fixtures/nonexistent'); await (0, vitest_1.expect)(router.loadRoutes(nonExistentPath, /\.ts$/)).rejects.toThrow(); }); (0, vitest_1.it)('should load routes with complex regex patterns', async () => { const fixturesPath = path_1.default.join(__dirname, 'fixtures/api'); // Load files ending with either .ts or .js await router.loadRoutes(fixturesPath, /\.(ts|js)$/); (0, vitest_1.expect)(router.app).toBeDefined(); }); (0, vitest_1.it)('should load routes from multiple patterns sequentially', async () => { const fixturesPath = path_1.default.join(__dirname, 'fixtures/api'); // Load different patterns await router.loadRoutes(fixturesPath, /hello\.ts$/); await router.loadRoutes(fixturesPath, /users\.ts$/); (0, vitest_1.expect)(router.app).toBeDefined(); }); (0, vitest_1.it)('should handle case-sensitive pattern matching', async () => { const fixturesPath = path_1.default.join(__dirname, 'fixtures/api'); // Case-sensitive pattern await router.loadRoutes(fixturesPath, /\.TS$/); (0, vitest_1.expect)(router.app).toBeDefined(); }); (0, vitest_1.it)('should load routes with exclusion patterns', async () => { const fixturesPath = path_1.default.join(__dirname, 'fixtures'); // Pattern that excludes malformed files await router.loadRoutes(fixturesPath, /^(?!.*malformed).*\.ts$/); (0, vitest_1.expect)(router.app).toBeDefined(); }); (0, vitest_1.it)('should handle deeply nested directory structures', async () => { const nestedPath = path_1.default.join(__dirname, 'fixtures/api/v1'); await router.loadRoutes(nestedPath, /\.ts$/); (0, vitest_1.expect)(router.app).toBeDefined(); }); (0, vitest_1.it)('should preserve route loading order', async () => { const fixturesPath = path_1.default.join(__dirname, 'fixtures/api'); // Load routes in specific order await router.loadRoutes(fixturesPath, /hello\.ts$/); await router.loadRoutes(fixturesPath, /users\.ts$/); (0, vitest_1.expect)(router.app).toBeDefined(); }); (0, vitest_1.it)('should handle special characters in file paths', async () => { const fixturesPath = path_1.default.join(__dirname, 'fixtures/api'); // Pattern that handles various file naming conventions await router.loadRoutes(fixturesPath, /[a-zA-Z0-9_-]+\.ts$/); (0, vitest_1.expect)(router.app).toBeDefined(); }); (0, vitest_1.it)('should validate pattern parameter is required', async () => { const fixturesPath = path_1.default.join(__dirname, 'fixtures/api'); await (0, vitest_1.expect)(router.loadRoutes(fixturesPath, null)).rejects.toThrow(); }); (0, vitest_1.it)('should validate directory parameter is required', async () => { await (0, vitest_1.expect)(router.loadRoutes('', /\.ts$/)).rejects.toThrow(); }); (0, vitest_1.it)('should handle symbolic links in directories', async () => { const fixturesPath = path_1.default.join(__dirname, 'fixtures/api'); // This should work even if there are symbolic links await router.loadRoutes(fixturesPath, /\.ts$/); (0, vitest_1.expect)(router.app).toBeDefined(); }); (0, vitest_1.it)('should handle very large directories efficiently', async () => { const fixturesPath = path_1.default.join(__dirname, 'fixtures/api'); const startTime = Date.now(); await router.loadRoutes(fixturesPath, /\.ts$/); const endTime = Date.now(); // Should complete within reasonable time (less than 1 second for small directories) (0, vitest_1.expect)(endTime - startTime).toBeLessThan(1000); }); }); //# sourceMappingURL=route-loading.test.js.map