@prism-engineer/router
Version:
Type-safe Express.js router with automatic client generation
167 lines • 9.35 kB
JavaScript
;
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 Parsing', () => {
let router;
(0, vitest_1.beforeEach)(() => {
router = (0, router_1.createRouter)();
vitest_1.vi.clearAllMocks();
});
(0, vitest_1.it)('should parse valid route files successfully', async () => {
const fixturesPath = path_1.default.join(__dirname, 'fixtures/api');
await (0, vitest_1.expect)(router.loadRoutes(fixturesPath, /hello\.ts$/)).resolves.not.toThrow();
});
(0, vitest_1.it)('should parse route files with proper exports', async () => {
const fixturesPath = path_1.default.join(__dirname, 'fixtures/api');
await router.loadRoutes(fixturesPath, /users\.ts$/);
(0, vitest_1.expect)(router.app).toBeDefined();
});
(0, vitest_1.it)('should handle route files with multiple exports', async () => {
const fixturesPath = path_1.default.join(__dirname, 'fixtures/admin');
await router.loadRoutes(fixturesPath, /dashboard\.ts$/);
(0, vitest_1.expect)(router.app).toBeDefined();
});
(0, vitest_1.it)('should validate route structure during parsing', async () => {
const validPath = path_1.default.join(__dirname, 'fixtures/api');
// Valid route files should parse without issues
await (0, vitest_1.expect)(router.loadRoutes(validPath, /hello\.ts$/)).resolves.not.toThrow();
});
(0, vitest_1.it)('should handle malformed route files gracefully', async () => {
const malformedPath = path_1.default.join(__dirname, 'fixtures');
// Should not throw even if malformed files exist
await (0, vitest_1.expect)(router.loadRoutes(malformedPath, /malformed\.ts$/)).resolves.not.toThrow();
});
(0, vitest_1.it)('should parse route files with complex path structures', async () => {
const nestedPath = path_1.default.join(__dirname, 'fixtures/api/v1');
await router.loadRoutes(nestedPath, /posts\.ts$/);
(0, vitest_1.expect)(router.app).toBeDefined();
});
(0, vitest_1.it)('should handle route files with TypeScript imports', async () => {
const fixturesPath = path_1.default.join(__dirname, 'fixtures/api');
// All fixture files use TypeScript imports
await router.loadRoutes(fixturesPath, /\.ts$/);
(0, vitest_1.expect)(router.app).toBeDefined();
});
(0, vitest_1.it)('should parse route files with external dependencies', async () => {
const fixturesPath = path_1.default.join(__dirname, 'fixtures/api');
// Routes use @sinclair/typebox and other dependencies
await router.loadRoutes(fixturesPath, /\.ts$/);
(0, vitest_1.expect)(router.app).toBeDefined();
});
(0, vitest_1.it)('should validate route method specification', async () => {
const fixturesPath = path_1.default.join(__dirname, 'fixtures/api');
// Should parse routes with proper method specification
await router.loadRoutes(fixturesPath, /hello\.ts$/);
(0, vitest_1.expect)(router.app).toBeDefined();
});
(0, vitest_1.it)('should validate route path specification', async () => {
const fixturesPath = path_1.default.join(__dirname, 'fixtures/api');
// Should parse routes with proper path specification
await router.loadRoutes(fixturesPath, /users\.ts$/);
(0, vitest_1.expect)(router.app).toBeDefined();
});
(0, vitest_1.it)('should parse route files with handler functions', async () => {
const fixturesPath = path_1.default.join(__dirname, 'fixtures/api');
// All routes should have valid handler functions
await router.loadRoutes(fixturesPath, /\.ts$/);
(0, vitest_1.expect)(router.app).toBeDefined();
});
(0, vitest_1.it)('should handle route files with response schemas', async () => {
const fixturesPath = path_1.default.join(__dirname, 'fixtures/api/v2');
// v2 routes have detailed response schemas
await router.loadRoutes(fixturesPath, /posts\.ts$/);
(0, vitest_1.expect)(router.app).toBeDefined();
});
(0, vitest_1.it)('should parse route files with request schemas', async () => {
const fixturesPath = path_1.default.join(__dirname, 'fixtures/api');
// Users route should have request schema parsing
await router.loadRoutes(fixturesPath, /users\.ts$/);
(0, vitest_1.expect)(router.app).toBeDefined();
});
(0, vitest_1.it)('should validate export structure in route files', async () => {
const fixturesPath = path_1.default.join(__dirname, 'fixtures/api');
// Should handle both named and default exports appropriately
await router.loadRoutes(fixturesPath, /\.ts$/);
(0, vitest_1.expect)(router.app).toBeDefined();
});
(0, vitest_1.it)('should handle route files with different naming conventions', async () => {
const patterns = [
/hello\.ts$/, // Simple name
/users\.ts$/, // Plural name
/posts\.ts$/ // Resource name
];
for (const pattern of patterns) {
const fixturesPath = path_1.default.join(__dirname, 'fixtures/api');
await (0, vitest_1.expect)(router.loadRoutes(fixturesPath, pattern)).resolves.not.toThrow();
}
});
(0, vitest_1.it)('should parse route files with version-specific implementations', async () => {
const v1Path = path_1.default.join(__dirname, 'fixtures/api/v1');
const v2Path = path_1.default.join(__dirname, 'fixtures/api/v2');
// Should parse different versions successfully
await router.loadRoutes(v1Path, /posts\.ts$/);
await router.loadRoutes(v2Path, /posts\.ts$/);
(0, vitest_1.expect)(router.app).toBeDefined();
});
(0, vitest_1.it)('should handle route files with minimal configurations', async () => {
const fixturesPath = path_1.default.join(__dirname, 'fixtures/api');
// Hello route has minimal configuration
await router.loadRoutes(fixturesPath, /hello\.ts$/);
(0, vitest_1.expect)(router.app).toBeDefined();
});
(0, vitest_1.it)('should handle route files with complex configurations', async () => {
const fixturesPath = path_1.default.join(__dirname, 'fixtures/admin');
// Dashboard route has more complex configuration
await router.loadRoutes(fixturesPath, /dashboard\.ts$/);
(0, vitest_1.expect)(router.app).toBeDefined();
});
(0, vitest_1.it)('should validate file extension during parsing', async () => {
const fixturesPath = path_1.default.join(__dirname, 'fixtures/api');
// Only .ts files should be parsed with TypeScript pattern
await router.loadRoutes(fixturesPath, /\.ts$/);
(0, vitest_1.expect)(router.app).toBeDefined();
});
(0, vitest_1.it)('should handle concurrent route file parsing', async () => {
const fixturesPath = path_1.default.join(__dirname, 'fixtures/api');
// Multiple concurrent parsing operations
const promises = [
router.loadRoutes(fixturesPath, /hello\.ts$/),
router.loadRoutes(fixturesPath, /users\.ts$/)
];
await (0, vitest_1.expect)(Promise.all(promises)).resolves.not.toThrow();
});
(0, vitest_1.it)('should preserve route parsing order within files', async () => {
const fixturesPath = path_1.default.join(__dirname, 'fixtures/api');
// Routes should be parsed in file order
await router.loadRoutes(fixturesPath, /\.ts$/);
(0, vitest_1.expect)(router.app).toBeDefined();
});
(0, vitest_1.it)('should handle route files with conditional exports', async () => {
const fixturesPath = path_1.default.join(__dirname, 'fixtures');
// Malformed file has conditional/partial exports
await (0, vitest_1.expect)(router.loadRoutes(fixturesPath, /malformed\.ts$/)).resolves.not.toThrow();
});
(0, vitest_1.it)('should validate route configuration completeness', async () => {
const fixturesPath = path_1.default.join(__dirname, 'fixtures/api');
// Complete route configurations should parse successfully
await router.loadRoutes(fixturesPath, /\.ts$/);
(0, vitest_1.expect)(router.app).toBeDefined();
});
(0, vitest_1.it)('should handle parsing errors without crashing', async () => {
const fixturesPath = path_1.default.join(__dirname, 'fixtures');
// Should handle files that might have parsing issues
await (0, vitest_1.expect)(router.loadRoutes(fixturesPath, /\.ts$/)).resolves.not.toThrow();
});
(0, vitest_1.it)('should parse route files with modern JavaScript features', async () => {
const fixturesPath = path_1.default.join(__dirname, 'fixtures/api');
// Routes use async/await, destructuring, etc.
await router.loadRoutes(fixturesPath, /\.ts$/);
(0, vitest_1.expect)(router.app).toBeDefined();
});
});
//# sourceMappingURL=route-parsing.test.js.map