UNPKG

loqatevars

Version:

Locate JavaScript files with 'const' or 'process.env' usage in LLM-generated codebases

51 lines (39 loc) 1.41 kB
const fs = require('fs-extra'); const path = require('path'); const os = require('os'); jest.mock('../lib/utils.js'); const { main } = require('../cli.js'); const utils = require('../lib/utils.js'); describe('CLI default behavior', () => { let mockLog; let mockExit; let testDir; let originalArgv; beforeEach(() => { mockLog = jest.spyOn(console, 'log').mockImplementation(); mockExit = jest.spyOn(process, 'exit').mockImplementation(); testDir = fs.mkdtempSync(path.join(os.tmpdir(), 'cli-default-')); originalArgv = process.argv; }); afterEach(() => { mockLog.mockRestore(); mockExit.mockRestore(); fs.removeSync(testDir); process.argv = originalArgv; }); test('main uses defaults and outputs matches', async () => { process.argv = ['node', 'cli.js']; const originalCwd = process.cwd; process.cwd = () => testDir; fs.writeFileSync(path.join(testDir, 'a.js'), 'const a = 1;'); fs.writeFileSync(path.join(testDir, 'b.js'), 'process.env.B'); utils.findMatchingFiles.mockResolvedValue(['a.js', 'b.js']); await main(); expect(utils.findMatchingFiles).toHaveBeenCalledWith(testDir, ['**/localVars.js'], ['.js']); const output = mockLog.mock.calls.join('\\n'); expect(output).toContain('a.js'); expect(output).toContain('b.js'); expect(mockExit).not.toHaveBeenCalled(); process.cwd = originalCwd; }); });