test: add unit tests for TechStackDetector module - #687
Conversation
84 tests covering: - Constructor and package.json caching - Empty profile structure validation - Database detection (Supabase, Prisma, pg, MongoDB, MySQL, SQLite) - RLS detection in SQL migrations - Environment variable detection - Frontend detection (React, Vue, Angular, Svelte, Next, Nuxt) - Build tool detection (Vite, Webpack, esbuild, Parcel) - Styling detection (Tailwind, styled-components, Emotion, SCSS) - Component library detection (shadcn, MUI, Chakra, Ant Design) - Backend detection (Express, Fastify, NestJS, Hono, Edge Functions) - API route detection (api/, pages/api/, app/api/) - TypeScript and test framework detection - Applicable phase computation - Confidence score calculation with cap at 100 - Static getSummary with all combinations - Full integration test (empty project + full-stack project)
- Extrai setupDeps para nível superior do describe (evita duplicação)
- Move jest.mock('fs-extra') antes dos requires por clareza
- Troca .resolves.not.toThrow() por .resolves.toBeUndefined()
- Env vars de banco: cobre .env, .env.local e .env.example - Rotas API: cobre api/, src/api/, pages/api/ e app/api/
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughThis PR adds a comprehensive Jest test suite for ChangesTechStackDetector Test Suite
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/core/orchestration/tech-stack-detector.test.js (1)
182-203: ⚡ Quick winConsolidate repeated filesystem mock setup into reusable helpers.
There are many near-identical
fs.pathExists.mockImplementationblocks (e.g., Line 182, Line 215, Line 232, Line 248, Line 319, etc.). Extracting a small helper for “existing paths” will reduce duplication and prevent test drift when path rules change.Refactor sketch
+function mockExistingPaths(paths) { + const normalized = new Set(paths.map((p) => path.normalize(p))); + fs.pathExists.mockImplementation(async (p) => normalized.has(path.normalize(p))); +} + +function mockPackageJson(dependencies = {}, devDependencies = {}) { + mockExistingPaths([path.join(PROJECT_ROOT, 'package.json')]); + fs.readJson.mockResolvedValue({ dependencies, devDependencies }); +}Then in tests:
- fs.pathExists.mockImplementation(async (p) => { - if (p === path.join(PROJECT_ROOT, 'package.json')) return true; - if (p === path.join(PROJECT_ROOT, 'tsconfig.json')) return true; - if (p === path.join(PROJECT_ROOT, 'tests')) return true; - return false; - }); + mockExistingPaths([ + path.join(PROJECT_ROOT, 'package.json'), + path.join(PROJECT_ROOT, 'tsconfig.json'), + path.join(PROJECT_ROOT, 'tests'), + ]);Also applies to: 215-220, 232-237, 248-253, 319-323, 335-340, 439-443, 473-477, 487-491, 535-539, 551-555, 570-573, 582-585, 604-607, 616-619, 628-631, 639-642, 858-863
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/core/orchestration/tech-stack-detector.test.js` around lines 182 - 203, Many tests repeat identical fs.pathExists.mockImplementation and fs.readJson.mockResolvedValue blocks; create a reusable helper (e.g., mockPathExists or setupFsMocks) that accepts an array of existing path suffixes and stubs fs.pathExists accordingly, and another helper for fs.readJson (e.g., mockReadJson) to return desired JSON; then replace repeated inline mocks in tests like the ones around detector._createEmptyProfile() / detector._detectDatabase() with calls to these helpers so all occurrences (including the blocks that check for 'supabase', 'migrations', 'package.json', etc.) are consolidated and easier to maintain.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tests/core/orchestration/tech-stack-detector.test.js`:
- Around line 182-203: Many tests repeat identical
fs.pathExists.mockImplementation and fs.readJson.mockResolvedValue blocks;
create a reusable helper (e.g., mockPathExists or setupFsMocks) that accepts an
array of existing path suffixes and stubs fs.pathExists accordingly, and another
helper for fs.readJson (e.g., mockReadJson) to return desired JSON; then replace
repeated inline mocks in tests like the ones around
detector._createEmptyProfile() / detector._detectDatabase() with calls to these
helpers so all occurrences (including the blocks that check for 'supabase',
'migrations', 'package.json', etc.) are consolidated and easier to maintain.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 5db07442-2318-47a1-91d1-75707873b30b
📒 Files selected for processing (1)
tests/core/orchestration/tech-stack-detector.test.js
📊 Coverage ReportCoverage report not available
Generated by PR Automation (Story 6.1) |
Summary
maininSynkraAI/aiox-core..aios-coreimport with current.aiox-coreresolution from the repository root.detect()behavior.Validation
npm test -- tests/core/orchestration/tech-stack-detector.test.js --runInBand --forceExitnpm run lint(passes with the existing 114 warnings, 0 errors)npm run typecheckgit diff --check origin/main...HEAD && git diff --checkSupersedes #503.
Summary by CodeRabbit
Tests