@@ -6,6 +6,7 @@ import {generateScreenshots} from './generateScreenshots.js'
66import { loadPlugins , invokePlugin } from './pluginManager.js'
77import { getScansContext } from './scansContextProvider.js'
88import * as core from '@actions/core'
9+ import { FindingWithContext } from './types.d.js'
910
1011export async function findForUrl (
1112 url : string ,
@@ -29,7 +30,7 @@ export async function findForUrl(
2930
3031 const findings : Finding [ ] = [ ]
3132 const addFinding = async (
32- findingData : Finding ,
33+ findingData : FindingWithContext ,
3334 { includeScreenshots = false } : { includeScreenshots ?: boolean } = { } ,
3435 ) => {
3536 let screenshotId
@@ -61,11 +62,7 @@ export async function findForUrl(
6162 }
6263
6364 if ( scansContext . shouldPerformAxeScan ) {
64- runAxeScan ( {
65- includeScreenshots : includeScreenshotsInput ,
66- page,
67- findings,
68- } )
65+ runAxeScan ( { page, addFinding} )
6966 }
7067 } catch ( e ) {
7168 core . error ( `Error during accessibility scan: ${ e } ` )
@@ -76,32 +73,26 @@ export async function findForUrl(
7673}
7774
7875async function runAxeScan ( {
79- includeScreenshots,
8076 page,
81- findings ,
77+ addFinding ,
8278} : {
83- includeScreenshots : boolean
8479 page : playwright . Page
85- findings : Finding [ ]
80+ addFinding : ( findingData : FindingWithContext , options ?: { includeScreenshots ?: boolean } ) => Promise < void >
8681} ) {
8782 const url = page . url ( )
8883 core . info ( `Scanning ${ url } ` )
8984 const rawFindings = await new AxeBuilder ( { page} ) . analyze ( )
90- let screenshotId : string | undefined
91- if ( includeScreenshots ) {
92- screenshotId = await generateScreenshots ( page )
93- }
9485
95- const axeFindings = rawFindings ?. violations . map ( violation => ( {
96- scannerType : 'axe' ,
97- url ,
98- html : violation . nodes [ 0 ] . html . replace ( / ' / g , ''' ) ,
99- problemShort : violation . help . toLowerCase ( ) . replace ( / ' / g, ''' ) ,
100- problemUrl : violation . helpUrl . replace ( / ' / g, ''' ) ,
101- ruleId : violation . id ,
102- solutionShort : violation . description . toLowerCase ( ) . replace ( / ' / g , ''' ) ,
103- solutionLong : violation . nodes [ 0 ] . failureSummary ? .replace ( / ' / g, ''' ) ,
104- screenshotId ,
105- } ) )
106- findings . push ( ... ( axeFindings || [ ] ) )
86+ rawFindings ?. violations . forEach ( violation =>
87+ addFinding ( {
88+ scannerType : 'axe' ,
89+ url ,
90+ html : violation . nodes [ 0 ] . html . replace ( / ' / g, ''' ) ,
91+ problemShort : violation . help . toLowerCase ( ) . replace ( / ' / g, ''' ) ,
92+ problemUrl : violation . helpUrl . replace ( / ' / g , ''' ) ,
93+ ruleId : violation . id ,
94+ solutionShort : violation . description . toLowerCase ( ) . replace ( / ' / g, ''' ) ,
95+ solutionLong : violation . nodes [ 0 ] . failureSummary ?. replace ( / ' / g , ''' ) ,
96+ } ) ,
97+ )
10798}
0 commit comments