loqatevars
Version:
Locate JavaScript files with 'const' or 'process.env' usage in LLM-generated codebases
27 lines (21 loc) • 826 B
JavaScript
const { asyncPool } = require('../lib/utils');
jest.setTimeout(10000);
describe('asyncPool error handling', () => {
test('continues processing when a task rejects', async () => {
const tasks = [
() => Promise.resolve('first'),
() => Promise.reject(new Error('fail')),
() => new Promise(res => setTimeout(() => res('last'), 10))
];
const results = await asyncPool(2, tasks);
expect(results.length).toBe(3);
expect(results[0].status).toBe('fulfilled');
expect(results[1].status).toBe('rejected');
expect(results[2].status).toBe('fulfilled');
expect(results[2].value).toBe('last');
});
test('rejects for non-positive limit', async () => {
await expect(asyncPool(0, [() => Promise.resolve()]))
.rejects.toHaveProperty('code', 'INVALID_POOL_LIMIT');
});
});