From bf57536760e8cf89fbbab43dde130dab9cb9380f Mon Sep 17 00:00:00 2001 From: Lam Wei Li Date: Sat, 23 Jul 2022 16:16:59 +0800 Subject: [PATCH] test: polyfill `Promise.allSettled` for Node.js <12 --- test/sandbox-coverage.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/sandbox-coverage.js b/test/sandbox-coverage.js index 1632f42..eed7544 100644 --- a/test/sandbox-coverage.js +++ b/test/sandbox-coverage.js @@ -13,3 +13,21 @@ sandbox.configure({ }, }, }); + +// polyfill for Node.js <12 +Promise.allSettled = + Promise.allSettled || + ((promises) => + Promise.all( + promises.map((p) => + p + .then((value) => ({ + status: 'fulfilled', + value, + })) + .catch((reason) => ({ + status: 'rejected', + reason, + })) + ) + ));