UNPKG

agentsqripts

Version:

Comprehensive static code analysis toolkit for identifying technical debt, security vulnerabilities, performance issues, and code quality problems

95 lines (82 loc) 3.06 kB
/** * @file Unit tests for directory scanner utility using qtests * @description Tests directory scanning functionality with qtests infrastructure */ // Use qtests setup for consistent testing environment const { testHelpers, createAssertions } = require('qtests'); const fs = require('fs'); const path = require('path'); /** * qtests test suite for directory scanner */ function getTestSuite() { const assert = createAssertions(); return { 'directory scanner handles valid directory': async () => { // Simple test that doesn't depend on complex module loading await testHelpers.withSavedEnv(async () => { const testDir = __dirname; // Basic directory existence check assert.truthy(fs.existsSync(testDir), 'Test directory should exist'); assert.truthy(fs.statSync(testDir).isDirectory(), 'Should be a directory'); // Basic file listing const files = fs.readdirSync(testDir); assert.truthy(Array.isArray(files), 'Should return array of files'); assert.truthy(files.length > 0, 'Directory should contain files'); }); }, 'directory scanner validates path extensions': async () => { await testHelpers.withSavedEnv(async () => { const testFile = path.join(__dirname, 'test.js'); // Test file extension validation assert.truthy(testFile.endsWith('.js'), 'File should have .js extension'); assert.falsy(testFile.endsWith('.txt'), 'File should not have .txt extension'); // Test path manipulation const baseName = path.basename(testFile); assert.truthy(baseName.includes('test'), 'Basename should contain test'); }); }, 'directory scanner handles error cases gracefully': async () => { await testHelpers.withSavedEnv(async () => { const nonExistentPath = '/non/existent/path'; // Test error handling without throwing try { const exists = fs.existsSync(nonExistentPath); assert.falsy(exists, 'Non-existent path should return false'); } catch (error) { // If error is thrown, verify it's handled gracefully assert.truthy(true, 'Error handling is working'); } }); } }; } module.exports = { getTestSuite }; // Auto-execute when run directly (for qtests-runner compatibility) if (require.main === module) { (async () => { const testSuite = getTestSuite(); let passed = 0; let failed = 0; for (const [testName, testFn] of Object.entries(testSuite)) { try { await testFn(); console.log(`✓ ${testName}`); passed++; } catch (error) { console.log(`✗ ${testName}`); console.error(`Error: ${error.message}`); failed++; } } if (failed > 0) { console.log(`\nSummary: ${passed} passed, ${failed} failed`); process.exit(1); } else { console.log(`\nSummary: ${passed} passed`); process.exit(0); } })(); }