unqommented
Version:
A Node.js utility that quickly identifies files with uncommented code in your codebase. Designed for developers who want to efficiently tell LLMs exactly which files need comments added.
50 lines (41 loc) • 1.59 kB
JavaScript
require('qtests/setup');
jest.mock('qerrors', () => ({ qerrors: jest.fn() }));
const { qerrors } = require('qerrors');
const { test, expect, describe, beforeAll, afterAll } = require('@jest/globals');
const fs = require('fs');
const path = require('path');
const utils = require('../utils');
const localVars = require('../../config/localVars');
const TEST_DIR = './test-dir-read-error';
beforeAll(() => {
if (!fs.existsSync(TEST_DIR)) {
fs.mkdirSync(TEST_DIR);
}
fs.writeFileSync(path.join(TEST_DIR, 'good.js'), 'const good = 1;');
fs.writeFileSync(path.join(TEST_DIR, 'bad.js'), 'const bad = 2;');
});
afterAll(() => {
fs.rmSync(TEST_DIR, { recursive: true, force: true });
});
describe('findUncommentedFiles read error handling', () => {
test('logs warning and skips unreadable file', async () => {
const realCreateStream = fs.createReadStream;
jest.spyOn(fs, 'createReadStream').mockImplementation((filePath, options) => {
if (filePath === path.resolve(TEST_DIR, 'bad.js')) {
throw new Error('read error');
}
return realCreateStream(filePath, options);
});
const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
const result = await utils.findUncommentedFiles(TEST_DIR);
expect(warnSpy).not.toHaveBeenCalled();
expect(qerrors).toHaveBeenCalledWith(
expect.any(Error),
'findUncommentedFiles',
{ file: path.resolve(TEST_DIR, 'bad.js') }
);
expect(result.uncommentedFiles).toEqual(['good.js']);
warnSpy.mockRestore();
fs.createReadStream.mockRestore();
});
});