UNPKG

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.

55 lines (45 loc) 1.72 kB
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 os = require('os'); const utils = require('../utils'); let tmpDir; let targetFile; beforeAll(() => { tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'unqommented-')); targetFile = path.join(tmpDir, 'uncommented.js'); fs.writeFileSync(targetFile, 'const x = 1;'); }); afterAll(() => { fs.rmSync(tmpDir, { recursive: true, force: true }); }); describe('findUncommentedFiles EMFILE retry failure', () => { test('records error and returns null when retry fails', async () => { const spy = jest .spyOn(utils, 'hasUncommentedCode') .mockImplementationOnce(() => { const err = new Error('too many open files'); err.code = 'EMFILE'; return Promise.reject(err); }) .mockImplementationOnce(() => { const err = new Error('still too many'); err.code = 'EMFILE'; return Promise.reject(err); }); let unhandled = false; const handler = () => { unhandled = true; }; process.on('unhandledRejection', handler); const result = await utils.findUncommentedFiles(tmpDir); process.removeListener('unhandledRejection', handler); expect(unhandled).toBe(false); expect(result.uncommentedFiles).toEqual([]); expect(result.errors).toEqual([{ file: targetFile, error: 'still too many' }]); expect(qerrors).toHaveBeenCalledWith(expect.any(Error), 'findUncommentedFiles', { file: targetFile }); spy.mockRestore(); qerrors.mockClear(); }); });