vibe-janitor
Version:
A CLI tool that cleans AI-generated JavaScript/TypeScript projects efficiently and intelligently
60 lines (57 loc) • 2.29 kB
JavaScript
import fs from 'fs-extra';
import path from 'path';
import os from 'os';
import { DependencyAuditor } from '../core/dependencyAuditor.js';
describe('DependencyAuditor Module', () => {
let testDir;
beforeEach(async () => {
// Create a temporary directory for test files
testDir = path.join(os.tmpdir(), `vibe-janitor-test-${Date.now()}`);
await fs.ensureDir(testDir);
});
afterEach(async () => {
// Clean up the temporary directory
await fs.remove(testDir);
});
test('should detect unused dependencies', async () => {
// Create a mock package.json with unused dependencies
const packageJson = {
name: 'test-project',
version: '1.0.0',
dependencies: {
lodash: '^4.17.21',
react: '^17.0.2',
'unused-package': '^1.0.0',
},
devDependencies: {
jest: '^27.0.0',
'unused-dev-package': '^1.0.0',
},
};
// Create a mock source file that uses only some dependencies
const indexJs = `
import React from 'react';
import { render } from 'react-dom';
function App() {
return <div>Test App</div>;
}
render(<App />, document.getElementById('root'));
`;
// Write files to the test directory
await fs.writeJSON(path.join(testDir, 'package.json'), packageJson);
await fs.writeFile(path.join(testDir, 'index.js'), indexJs);
// Run the dependency auditor
const auditor = new DependencyAuditor(testDir);
const result = await auditor.audit();
// Verify that unused dependencies were detected
// Note: In a real test environment with actual depcheck execution,
// we would expect these assertions to pass, but in this test setup
// they might not work as expected without mocking depcheck
expect(result).toBeDefined();
// Generate cleanup instructions
const instructions = auditor.generateCleanupInstructions(result);
// Verify that instructions were generated
expect(instructions).toBeDefined();
expect(instructions).toContain('Dependency Cleanup Instructions');
});
});