From 90ca26ac7f5fd93ad61d4184936ba7d13440417d Mon Sep 17 00:00:00 2001 From: Matteo Pieroni Date: Tue, 3 Sep 2024 08:46:58 +0100 Subject: [PATCH] fix(apca-silver-plus): don't reverse in place (#132) --- .changeset/sharp-bats-remember.md | 5 +++++ src/apca-silver-plus.ts | 5 +++-- src/index.test.ts | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 .changeset/sharp-bats-remember.md diff --git a/.changeset/sharp-bats-remember.md b/.changeset/sharp-bats-remember.md new file mode 100644 index 0000000..7f4564c --- /dev/null +++ b/.changeset/sharp-bats-remember.md @@ -0,0 +1,5 @@ +--- +"apca-check": patch +--- + +fix: bug with array reversal diff --git a/src/apca-silver-plus.ts b/src/apca-silver-plus.ts index 9945c70..9f8d3f5 100644 --- a/src/apca-silver-plus.ts +++ b/src/apca-silver-plus.ts @@ -30,8 +30,9 @@ const APCASilverPlusConformanceThresholdFn: ConformanceThresholdFn = ( // Go over the table backwards to find the first matching font size and then the weight. // The value null is returned when the combination of font size and weight does not have // any elegible APCA luminosity silver compliant thresholds (represented by -1 in the table). - silverPlusAPCALookupTable.reverse(); - for (const [rowSize, ...rowWeights] of silverPlusAPCALookupTable) { + const reversedTable = [...silverPlusAPCALookupTable].reverse(); + + for (const [rowSize, ...rowWeights] of reversedTable) { if (size >= rowSize) { for (const [idx, keywordWeight] of [ 900, 800, 700, 600, 500, 400, 300, 200, 100, diff --git a/src/index.test.ts b/src/index.test.ts index d5010a8..b281e17 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -235,5 +235,22 @@ describe("apca-check", () => { await expect(apcaViolations[0].nodes.length).to.equal(3); }); + + it("should handle both valid code and violations", async () => { + const el: HTMLElement = await fixture( + html`
+

Some copy

+

Some copy

+
`, + ); + + const results = await runAxe(el); + + const apcaViolations = results.violations.filter((violation) => + violation.id.includes("color-contrast-apca-silver"), + ); + + await expect(apcaViolations[0].nodes.length).to.equal(1); + }); }); });