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.
79 lines (67 loc) • 2.35 kB
JavaScript
require('qtests/setup');
const { test, expect, describe, beforeAll, afterAll } = require('@jest/globals');
const fs = require('fs');
const path = require('path');
const os = require('os');
const utils = require('../utils');
const localVars = require('../../config/localVars'); // constant values
let tmpDir;
let filePaths;
beforeAll(() => {
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'unqommented-'));
filePaths = [];
for (let i = 0; i < 12; i += 1) {
const f = path.join(tmpDir, `file${i}.js`);
fs.writeFileSync(f, 'const x = 1;');
filePaths.push(f);
}
});
afterAll(() => {
fs.rmSync(tmpDir, { recursive: true, force: true });
});
describe('findUncommentedFiles concurrency', () => {
test('respects concurrency limit and runs multiple concurrently', async () => {
const invocationOrder = [];
let active = 0;
let maxActive = 0;
jest.spyOn(utils, 'hasUncommentedCode').mockImplementation(async file => {
invocationOrder.push(path.basename(file));
active += 1;
if (active > maxActive) {
maxActive = active;
}
await new Promise(res => setTimeout(res, 20));
active -= 1;
return true;
});
await utils.findUncommentedFiles(tmpDir);
expect(maxActive).toBeLessThanOrEqual(localVars.CONCURRENCY_LIMIT);
if (filePaths.length > 1) {
expect(maxActive).toBeGreaterThan(1);
}
expect(invocationOrder.length).toBe(filePaths.length);
utils.hasUncommentedCode.mockRestore();
});
test('respects concurrency limit when streaming results', async () => {
const { PassThrough } = require('stream');
const stream = new PassThrough();
let active = 0;
let maxActive = 0;
jest.spyOn(utils, 'hasUncommentedCode').mockImplementation(async file => {
active += 1;
if (active > maxActive) { maxActive = active; }
await new Promise(res => setTimeout(res, 20));
active -= 1;
return true;
});
const result = await utils.findUncommentedFiles(tmpDir, stream);
stream.resume();
await new Promise(res => stream.end(res));
expect(maxActive).toBeLessThanOrEqual(localVars.CONCURRENCY_LIMIT);
if (filePaths.length > 1) {
expect(maxActive).toBeGreaterThan(1);
}
expect(result.uncommentedFiles).toEqual([]);
utils.hasUncommentedCode.mockRestore();
});
});