@@ -52,9 +52,19 @@ const runContrastTest = (colorPairs: ContrastRequirement[], tokens: Tokens): con
5252 if ( ! tokens . hasOwnProperty ( colorB ) ) throw new Error ( `Color token not found ${ colorB } ` )
5353
5454 if ( parseToRgba ( tokens [ colorB ] . value ) [ 3 ] === 1 ) {
55- return {
55+ const testResults = testContrast (
56+ minimumContrast ,
57+ tokens [ colorA ] . value ,
58+ tokens [ colorB ] . value ,
59+ undefined ,
5660 contrastPair ,
57- ...testContrast ( minimumContrast , tokens [ colorA ] . value , tokens [ colorB ] . value , undefined , contrastPair ) ,
61+ )
62+ return {
63+ contrastPair :
64+ testResults . pass === '✅'
65+ ? `${ contrastPair } `
66+ : `${ colorA } (${ tokens [ colorA ] . value } ) vs. ${ colorB } (${ tokens [ colorB ] . value } )` ,
67+ ...testResults ,
5868 minimumContrastRatio,
5969 }
6070 }
@@ -64,11 +74,23 @@ const runContrastTest = (colorPairs: ContrastRequirement[], tokens: Tokens): con
6474 // overwrite background if custom canvas array is set
6575 if ( options ?. bg ) canvasColorArrays = options . bg
6676 // test transparent colorB with default bgs `canvasColors`
67- return canvasColorArrays . map ( bg => ( {
68- contrastPair : `${ contrastPair } on ${ bg } ` ,
69- ...testContrast ( minimumContrast , tokens [ colorA ] . value , tokens [ colorB ] . value , tokens [ bg ] . value , contrastPair ) ,
70- minimumContrastRatio,
71- } ) )
77+ return canvasColorArrays . map ( bg => {
78+ const testResults = testContrast (
79+ minimumContrast ,
80+ tokens [ colorA ] . value ,
81+ tokens [ colorB ] . value ,
82+ tokens [ bg ] . value ,
83+ contrastPair ,
84+ )
85+ return {
86+ contrastPair :
87+ testResults . pass === '✅'
88+ ? `${ contrastPair } on ${ bg } `
89+ : `${ colorA } (${ tokens [ colorA ] . value } ) vs. ${ colorB } (${ tokens [ colorB ] . value } ) on ${ bg } ` ,
90+ ...testResults ,
91+ minimumContrastRatio,
92+ }
93+ } )
7294 } )
7395}
7496/**
@@ -99,6 +121,7 @@ const testContrast = (
99121 // eslint-disable-next-line no-console
100122 console . error ( `${ contrastPair || '' } as ${ colorA } vs.${ colorB } : ${ err } ` )
101123 }
124+
102125 return {
103126 pass : contrast >= minimumContrast ? '✅' : '❌' ,
104127 contrastRatio : `${ contrast } :1` ,
0 commit comments