diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 346585c..6ab9e0a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,8 +10,9 @@ jobs: fail-fast: false matrix: node-version: + - 24 + - 22 - 20 - - 18 steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 diff --git a/index.js b/index.js index f713b9b..4f21f12 100644 --- a/index.js +++ b/index.js @@ -7,7 +7,7 @@ export default async function pMap( signal, } = {}, ) { - return new Promise((resolve_, reject_) => { + return new Promise((_resolve, _reject) => { if (iterable[Symbol.iterator] === undefined && iterable[Symbol.asyncIterator] === undefined) { throw new TypeError(`Expected \`input\` to be either an \`Iterable\` or \`AsyncIterable\`, got (${typeof iterable})`); } @@ -39,14 +39,14 @@ export default async function pMap( }; const resolve = value => { - resolve_(value); + _resolve(value); cleanup(); }; const reject = reason => { isRejected = true; isResolved = true; - reject_(reason); + _reject(reason); cleanup(); }; diff --git a/index.test-d.ts b/index.test-d.ts index 7cf4f99..41fae76 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,5 +1,10 @@ import {expectType, expectAssignable} from 'tsd'; -import pMap, {pMapIterable, type Options, type Mapper, pMapSkip} from './index.js'; +import pMap, { + pMapIterable, + type Options, + type Mapper, + pMapSkip, +} from './index.js'; const sites = [ 'https://sindresorhus.com', diff --git a/package.json b/package.json index 6401a2a..844bf2e 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ }, "sideEffects": false, "engines": { - "node": ">=18" + "node": ">=20.17" }, "scripts": { "test": "xo && ava && tsd" @@ -52,6 +52,6 @@ "random-int": "^3.0.0", "time-span": "^5.1.0", "tsd": "^0.29.0", - "xo": "^0.56.0" + "xo": "^1.2.3" } } diff --git a/test.js b/test.js index 484bfeb..6f3f9d6 100644 --- a/test.js +++ b/test.js @@ -205,16 +205,15 @@ test('all pMapSkips', async t => { test('all mappers should run when concurrency is infinite, even after stop-on-error happened', async t => { const input = [1, async () => delay(300, {value: 2}), 3]; const mappedValues = []; - await t.throwsAsync( - pMap(input, async value => { - value = typeof value === 'function' ? await value() : value; - mappedValues.push(value); - if (value === 1) { - await delay(100); - throw new Error('Oops!'); - } - }), - ); + const promise = pMap(input, async value => { + value = typeof value === 'function' ? await value() : value; + mappedValues.push(value); + if (value === 1) { + await delay(100); + throw new Error('Oops!'); + } + }); + await t.throwsAsync(promise); await delay(500); t.deepEqual(mappedValues, [1, 3, 2]); }); @@ -468,15 +467,12 @@ test('no unhandled rejected promises from mapper throws - infinite concurrency', test('no unhandled rejected promises from mapper throws - concurrency 1', async t => { const input = [1, 2, 3]; const mappedValues = []; - await t.throwsAsync( - pMap(input, async value => { - mappedValues.push(value); - await delay(100); - throw new Error(`Oops! ${value}`); - }, - {concurrency: 1}), - {message: 'Oops! 1'}, - ); + const promise = pMap(input, async value => { + mappedValues.push(value); + await delay(100); + throw new Error(`Oops! ${value}`); + }, {concurrency: 1}); + await t.throwsAsync(promise, {message: 'Oops! 1'}); t.deepEqual(mappedValues, [1]); });