Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/actions/file/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type Finding = {
category?: FindingCategory
ruleId?: string
url: string
originalUrl: string
html?: string
nodes?: FindingNode[]
problemShort: string
Expand Down
17 changes: 12 additions & 5 deletions .github/actions/find/src/findForUrl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import type {ColorSchemePreference, Finding, FindingCategory, ReducedMotionPreference, UrlConfig} from './types.d.js'
import type {
ColorSchemePreference,
Finding,
FindingCategory,
FindingInput,
ReducedMotionPreference,
UrlConfig,
} from './types.d.js'
import {AxeBuilder} from '@axe-core/playwright'
import {accesslintAudit} from '@accesslint/playwright'
import playwright from 'playwright'
Expand Down Expand Up @@ -39,12 +46,12 @@ export async function findForUrl(
)

const findings: Finding[] = []
const addFinding = async (findingData: Finding) => {
const addFinding = async (findingData: FindingInput) => {
let screenshotId
if (includeScreenshots) {
screenshotId = await generateScreenshots(page)
}
findings.push({...findingData, screenshotId})
findings.push({...findingData, screenshotId, originalUrl: url})
}

try {
Expand Down Expand Up @@ -92,7 +99,7 @@ async function runAxeScan({
excludeSelectors,
}: {
page: playwright.Page
addFinding: (findingData: Finding, options?: {includeScreenshots?: boolean}) => Promise<void>
addFinding: (findingData: FindingInput, options?: {includeScreenshots?: boolean}) => Promise<void>
excludeSelectors?: string[]
}) {
const url = page.url()
Expand Down Expand Up @@ -129,7 +136,7 @@ async function runAccesslintScan({
addFinding,
}: {
page: playwright.Page
addFinding: (findingData: Finding, options?: {includeScreenshots?: boolean}) => Promise<void>
addFinding: (findingData: FindingInput, options?: {includeScreenshots?: boolean}) => Promise<void>
}) {
const url = page.url()
core.info(`Scanning ${url} with AccessLint`)
Expand Down
4 changes: 2 additions & 2 deletions .github/actions/find/src/pluginManager/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type {Finding} from '../types.d.js'
import type {FindingInput} from '../types.d.js'
import playwright from 'playwright'

export type PluginDefaultParams = {
page: playwright.Page
addFinding: (findingData: Finding) => Promise<void>
addFinding: (findingData: FindingInput) => Promise<void>
}

export type Plugin = {
Expand Down
3 changes: 3 additions & 0 deletions .github/actions/find/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ export type Finding = {
solutionLong?: string
screenshotId?: string
ruleId?: string
originalUrl: string
}

export type FindingInput = Omit<Finding, 'originalUrl'>

export type Cookie = {
name: string
value: string
Expand Down
22 changes: 22 additions & 0 deletions .github/actions/find/tests/findForUrl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,28 @@ describe('findForUrl', () => {
])
})

it('adds the original url to each finding', async () => {
actionInput = ''
clearAll()
vi.mocked(AxeBuilder.prototype.analyze).mockResolvedValueOnce({
violations: [
{
id: 'r',
help: 'h',
helpUrl: 'https://example.com',
description: 'd',
tags: [],
nodes: [{html: '<a></a>', target: ['a']}],
},
],
} as unknown as axe.AxeResults)

const findings = await findForUrl({url: 'https://original.example/page'})

expect(findings).toHaveLength(1)
expect(findings[0].originalUrl).toBe('https://original.example/page')
})

describe('axe finding categorization', () => {
function axeViolation(tags: string[]) {
return {
Expand Down
3 changes: 2 additions & 1 deletion tests/site-with-errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ describe('site-with-errors', () => {

it('cache has expected results', () => {
const actual = results.map(({issue: {url: issueUrl}, findings}) => {
const {problemUrl, solutionLong, screenshotId, nodes, ...finding} = findings[0]
const {problemUrl, solutionLong, screenshotId, nodes, originalUrl, ...finding} = findings[0]
// Check volatile fields for existence only
expect(issueUrl).toBeDefined()
expect(problemUrl).toBeDefined()
expect(originalUrl).toBeDefined()
// Axe-specific assertions
if (finding.scannerType === 'axe') {
expect(solutionLong).toBeDefined()
Expand Down
1 change: 1 addition & 0 deletions tests/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type Finding = {
scannerType: string
ruleId?: string
url: string
originalUrl: string
html?: string
nodes?: FindingNode[]
problemShort: string
Expand Down
Loading