Skip to content

Commit effdb30

Browse files
committed
Uses hard-coded list of scans
1 parent 4eab30a commit effdb30

3 files changed

Lines changed: 21 additions & 12 deletions

File tree

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ type Plugin = {
2020
default: (options: PluginDefaultParams) => Promise<void>
2121
}
2222

23+
// Built-in plugin names shipped with the scanner.
24+
// Used to skip duplicates when loading custom plugins.
25+
const BUILT_IN_PLUGINS = ['reflow-scan']
26+
2327
const plugins: Plugin[] = []
2428
let pluginsLoaded = false
2529

@@ -75,25 +79,29 @@ export async function loadCustomPlugins() {
7579
return
7680
}
7781

78-
await loadPluginsFromPath({pluginsPath})
82+
await loadPluginsFromPath({pluginsPath, skipBuiltInPlugins: BUILT_IN_PLUGINS})
7983
}
8084

8185
// exported for mocking/testing. not for actual use
82-
export async function loadPluginsFromPath({pluginsPath}: {pluginsPath: string}) {
86+
export async function loadPluginsFromPath({
87+
pluginsPath,
88+
skipBuiltInPlugins,
89+
}: {
90+
pluginsPath: string
91+
skipBuiltInPlugins?: string[]
92+
}) {
8393
try {
8494
const res = fs.readdirSync(pluginsPath)
8595
for (const pluginFolder of res) {
8696
const pluginFolderPath = path.join(pluginsPath, pluginFolder)
8797

8898
if (fs.existsSync(pluginFolderPath) && fs.lstatSync(pluginFolderPath).isDirectory()) {
89-
core.info(`Found plugin: ${pluginFolder}`)
90-
const plugin = await dynamicImport(path.join(pluginsPath, pluginFolder, 'index.js'))
91-
// Prevents a plugin from running twice
92-
if (plugins.some(p => p.name === plugin.name)) {
93-
core.info(`Skipping duplicate plugin: ${plugin.name}`)
99+
if (skipBuiltInPlugins?.includes(pluginFolder)) {
100+
core.info(`Skipping built-in plugin: ${pluginFolder}`)
94101
continue
95102
}
96-
plugins.push(plugin)
103+
core.info(`Found plugin: ${pluginFolder}`)
104+
plugins.push(await dynamicImport(path.join(pluginsPath, pluginFolder, 'index.js')))
97105
}
98106
}
99107
} catch (e) {

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe('loadPlugins', () => {
6767
})
6868
})
6969

70-
describe('when built-in and custom plugins share the same name', () => {
70+
describe('when a custom plugin folder matches a built-in plugin name', () => {
7171
beforeEach(() => {
7272
// @ts-expect-error - we don't need the full fs readdirsync
7373
// method signature here
@@ -79,13 +79,14 @@ describe('loadPlugins', () => {
7979
})
8080
})
8181

82-
it('skips the duplicate and only loads the plugin once', async () => {
82+
it('skips the built-in name in custom plugins and only loads it once', async () => {
8383
pluginManager.clearCache()
8484
const infoSpy = vi.spyOn(core, 'info').mockImplementation(() => {})
8585
const plugins = await pluginManager.loadPlugins()
86+
// Built-in loads it, custom skips the folder by name
8687
expect(plugins.length).toBe(1)
8788
expect(plugins[0].name).toBe('reflow-scan')
88-
expect(infoSpy).toHaveBeenCalledWith('Skipping duplicate plugin: reflow-scan')
89+
expect(infoSpy).toHaveBeenCalledWith('Skipping built-in plugin: reflow-scan')
8990
})
9091
})
9192
})

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ Trigger the workflow manually or automatically based on your configuration. The
126126
| `include_screenshots` | No | Whether to capture screenshots of scanned pages and include links to them in filed issues. Screenshots are stored on the `gh-cache` branch of the repository running the workflow. Default: `false` | `true` |
127127
| `reduced_motion` | No | Playwright `reducedMotion` setting for scan contexts. Allowed values: `reduce`, `no-preference` | `reduce` |
128128
| `color_scheme` | No | Playwright `colorScheme` setting for scan contexts. Allowed values: `light`, `dark`, `no-preference` | `dark` |
129-
| `scans` | No | An array of scans (or plugins) to be performed. If not provided, only Axe will be performed. | `'["axe", "reflow-scan", ...other plugins]'` |
129+
| `scans` | No | An array of scans (or plugins) to be performed. If not provided, only Axe will be performed. | `'["axe", "reflow-scan"]'` |
130130

131131
---
132132

0 commit comments

Comments
 (0)