From ff9c383677b7fe8875faa292d5e5197fd3e40252 Mon Sep 17 00:00:00 2001 From: paraschi Date: Tue, 20 Aug 2024 16:18:51 +0300 Subject: [PATCH] fix: use allSettled --- src/backlinks/handler.js | 4 ++-- test/audits/backlinks.test.js | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/backlinks/handler.js b/src/backlinks/handler.js index 86fa774b..1060ea6e 100644 --- a/src/backlinks/handler.js +++ b/src/backlinks/handler.js @@ -19,8 +19,8 @@ import { retrieveSiteBySiteId } from '../utils/data-access.js'; import { enhanceBacklinksWithFixes, isStillBrokenURL } from '../support/utils.js'; export async function filterOutValidBacklinks(backlinks, log) { - const backlinkStatuses = await Promise.all(backlinks.map(async (backlink) => isStillBrokenURL(backlink.url_to, 'backlink', log))); - return backlinks.filter((_, index) => backlinkStatuses[index]); + const backlinkStatuses = await Promise.allSettled(backlinks.map(async (backlink) => isStillBrokenURL(backlink.url_to, 'Backlink', log))); + return backlinks.filter((_, index) => backlinkStatuses[index].status === 'fulfilled' && backlinkStatuses[index].value); } export default async function auditBrokenBacklinks(message, context) { diff --git a/test/audits/backlinks.test.js b/test/audits/backlinks.test.js index e92ab196..5d43a4cb 100644 --- a/test/audits/backlinks.test.js +++ b/test/audits/backlinks.test.js @@ -27,7 +27,6 @@ import auditBrokenBacklinks from '../../src/backlinks/handler.js'; use(sinonChai); use(chaiAsPromised); -// eslint-disable-next-line func-names describe('Backlinks Tests', function () { this.timeout(10000); let message; @@ -512,7 +511,7 @@ describe('Backlinks Tests', function () { expect(context.sqs.sendMessage).to.have.been.calledOnce; expect(context.sqs.sendMessage).to.have.been .calledWith(context.env.AUDIT_RESULTS_QUEUE_URL, expectedMessage); - expect(context.log.warn).to.have.been.calledWith('backlink https://foo.com/returns-429 returned status 429'); + expect(context.log.warn).to.have.been.calledWith('Backlink https://foo.com/returns-429 returned status 429'); expect(context.log.info).to.have.been.calledWith('Successfully audited site2 for broken-backlinks type audit'); });