Skip to content

Commit 8402e61

Browse files
committed
copilot PR feedback
- update plugin manager tests to account for new isDirectory check
1 parent 4e43b7f commit 8402e61

4 files changed

Lines changed: 25 additions & 17 deletions

File tree

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export async function findForUrl(
2222
await page.goto(url)
2323
console.log(`Scanning ${page.url()}`)
2424

25-
let findings: Finding[] = []
25+
const findings: Finding[] = []
2626
const addFinding = (findingData: Finding) => {
2727
findings.push(findingData)
2828
}
@@ -58,18 +58,18 @@ export async function findForUrl(
5858
screenshotId = await generateScreenshots(page)
5959
}
6060

61-
findings =
62-
rawFindings?.violations.map(violation => ({
63-
scannerType: 'axe',
64-
url,
65-
html: violation.nodes[0].html.replace(/'/g, '''),
66-
problemShort: violation.help.toLowerCase().replace(/'/g, '''),
67-
problemUrl: violation.helpUrl.replace(/'/g, '''),
68-
ruleId: violation.id,
69-
solutionShort: violation.description.toLowerCase().replace(/'/g, '''),
70-
solutionLong: violation.nodes[0].failureSummary?.replace(/'/g, '''),
71-
screenshotId,
72-
})) || []
61+
const axeFindings = rawFindings?.violations.map(violation => ({
62+
scannerType: 'axe',
63+
url,
64+
html: violation.nodes[0].html.replace(/'/g, '''),
65+
problemShort: violation.help.toLowerCase().replace(/'/g, '''),
66+
problemUrl: violation.helpUrl.replace(/'/g, '''),
67+
ruleId: violation.id,
68+
solutionShort: violation.description.toLowerCase().replace(/'/g, '''),
69+
solutionLong: violation.nodes[0].failureSummary?.replace(/'/g, '''),
70+
screenshotId,
71+
}))
72+
findings.push(...(axeFindings || []))
7373
} catch (e) {
7474
console.error('Error during accessibility scan:', e)
7575
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,11 @@ export async function loadPluginsFromPath({readPath, importPath}: {readPath: str
7272
try {
7373
const res = fs.readdirSync(readPath)
7474
for (const pluginFolder of res) {
75-
console.log('Found plugin: ', pluginFolder)
76-
plugins.push(await dynamicImport(path.join(importPath, pluginFolder, '/index.js')))
75+
const pluginFolderPath = path.join(importPath, pluginFolder)
76+
if (fs.lstatSync(pluginFolderPath).isDirectory()) {
77+
console.log('Found plugin: ', pluginFolder)
78+
plugins.push(await dynamicImport(path.join(importPath, pluginFolder, '/index.js')))
79+
}
7780
}
7881
} catch (e) {
7982
// - log errors here for granular info

.github/actions/find/src/scansContextProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ let scansContext: ScansContext | undefined
1010
export function getScansContext() {
1111
if (!scansContext) {
1212
const scansJson = core.getInput('scans', {required: false})
13-
const scansToPerform = JSON.parse(scansJson || '{}')
14-
// - if we dont have a scans input
13+
const scansToPerform = JSON.parse(scansJson || '[]')
14+
// - if we don't have a scans input
1515
// or we do have a scans input, but it only has 1 item and its 'axe'
1616
// then we only want to run 'axe' and not the plugins
1717
// - keep in mind, 'onlyAxeScan' is not the same as 'shouldPerformAxeScan'

.github/actions/find/tests/pluginManager.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ describe('loadPlugins', () => {
1717
vi.spyOn(fs, 'readdirSync').mockImplementation(readPath => {
1818
return [readPath + '/plugin-1', readPath + '/plugin-2']
1919
})
20+
vi.spyOn(fs, 'lstatSync').mockImplementation(() => {
21+
return {
22+
isDirectory: () => true,
23+
} as unknown as fs.Stats
24+
})
2025
})
2126

2227
describe('when plugins are not loaded', () => {

0 commit comments

Comments
 (0)