Skip to content

Commit be91558

Browse files
committed
refactor to debug failures
1 parent 9131d52 commit be91558

3 files changed

Lines changed: 24 additions & 28 deletions

File tree

.github/actions/find/src/findForUrl.ts

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {generateScreenshots} from './generateScreenshots.js'
66
import {loadPlugins, invokePlugin} from './pluginManager.js'
77
import {getScansContext} from './scansContextProvider.js'
88
import * as core from '@actions/core'
9+
import {FindingWithContext} from './types.d.js'
910

1011
export 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

7875
async 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, '&apos;'),
99-
problemShort: violation.help.toLowerCase().replace(/'/g, '&apos;'),
100-
problemUrl: violation.helpUrl.replace(/'/g, '&apos;'),
101-
ruleId: violation.id,
102-
solutionShort: violation.description.toLowerCase().replace(/'/g, '&apos;'),
103-
solutionLong: violation.nodes[0].failureSummary?.replace(/'/g, '&apos;'),
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, '&apos;'),
91+
problemShort: violation.help.toLowerCase().replace(/'/g, '&apos;'),
92+
problemUrl: violation.helpUrl.replace(/'/g, '&apos;'),
93+
ruleId: violation.id,
94+
solutionShort: violation.description.toLowerCase().replace(/'/g, '&apos;'),
95+
solutionLong: violation.nodes[0].failureSummary?.replace(/'/g, '&apos;'),
96+
}),
97+
)
10798
}

.github/actions/find/src/pluginManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as fs from 'fs'
22
import * as path from 'path'
33
import {fileURLToPath} from 'url'
44
import {dynamicImport} from './dynamicImport.js'
5-
import type {Finding} from './types.d.js'
5+
import type {FindingWithContext} from './types.d.js'
66
import playwright from 'playwright'
77
import * as core from '@actions/core'
88

@@ -12,7 +12,7 @@ const __dirname = path.dirname(__filename)
1212

1313
type PluginDefaultParams = {
1414
page: playwright.Page
15-
addFinding: (findingData: Finding) => void
15+
addFinding: (findingData: FindingWithContext) => void
1616
// - this will be coming soon
1717
// runAxeScan: (options: {includeScreenshots: boolean; page: playwright.Page; findings: Finding[]}) => Promise<void>
1818
}

.github/actions/find/src/types.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ export type Finding = {
88
screenshotId?: string
99
}
1010

11+
export type FindingWithContext = Finding & {
12+
scannerType: string
13+
ruleId?: string
14+
}
15+
1116
export type Cookie = {
1217
name: string
1318
value: string

0 commit comments

Comments
 (0)