Skip to content

Commit 88c9363

Browse files
committed
Name some types for readability
1 parent ac972a3 commit 88c9363

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

.github/actions/find/package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {Finding} from './types.d.js'
1+
import type {ColorSchemePreference, Finding, ReducedMotionPreference} from './types.d.js'
22
import {AxeBuilder} from '@axe-core/playwright'
33
import playwright from 'playwright'
44
import {AuthContext} from './AuthContext.js'
@@ -8,8 +8,8 @@ export async function findForUrl(
88
url: string,
99
authContext?: AuthContext,
1010
includeScreenshots: boolean = false,
11-
reducedMotion?: 'reduce' | 'no-preference',
12-
colorScheme?: 'light' | 'dark' | 'no-preference',
11+
reducedMotion?: ReducedMotionPreference,
12+
colorScheme?: ColorSchemePreference,
1313
): Promise<Finding[]> {
1414
const browser = await playwright.chromium.launch({
1515
headless: true,

.github/actions/find/src/index.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {AuthContextInput} from './types.js'
1+
import type {AuthContextInput, ColorSchemePreference, ReducedMotionPreference} from './types.js'
22
import * as core from '@actions/core'
33
import {AuthContext} from './AuthContext.js'
44
import {findForUrl} from './findForUrl.js'
@@ -12,20 +12,24 @@ export default async function () {
1212

1313
const includeScreenshots = core.getInput('include_screenshots', {required: false}) !== 'false'
1414
const reducedMotionInput = core.getInput('reduced_motion', {required: false})
15-
let reducedMotion: 'reduce' | 'no-preference' | undefined
15+
let reducedMotion: ReducedMotionPreference | undefined
1616
if (reducedMotionInput) {
17-
if (!['reduce', 'no-preference'].includes(reducedMotionInput)) {
18-
throw new Error("Input 'reduced_motion' must be one of: 'reduce', 'no-preference'")
17+
if (!['reduce', 'no-preference', null].includes(reducedMotionInput)) {
18+
throw new Error(
19+
"Input 'reduced_motion' must be one of: 'reduce', 'no-preference', or null per Playwright documentation.",
20+
)
1921
}
20-
reducedMotion = reducedMotionInput as 'reduce' | 'no-preference'
22+
reducedMotion = reducedMotionInput as ReducedMotionPreference
2123
}
2224
const colorSchemeInput = core.getInput('color_scheme', {required: false})
23-
let colorScheme: 'light' | 'dark' | 'no-preference' | undefined
25+
let colorScheme: ColorSchemePreference | undefined
2426
if (colorSchemeInput) {
25-
if (!['light', 'dark', 'no-preference'].includes(colorSchemeInput)) {
26-
throw new Error("Input 'color_scheme' must be one of: 'light', 'dark', 'no-preference'")
27+
if (!['light', 'dark', 'no-preference', null].includes(colorSchemeInput)) {
28+
throw new Error(
29+
"Input 'color_scheme' must be one of: 'light', 'dark', 'no-preference', or null per Playwright documentation.",
30+
)
2731
}
28-
colorScheme = colorSchemeInput as 'light' | 'dark' | 'no-preference'
32+
colorScheme = colorSchemeInput as ColorSchemePreference
2933
}
3034

3135
const findings = []

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,7 @@ export type AuthContextInput = {
3131
cookies?: Cookie[]
3232
localStorage?: LocalStorage
3333
}
34+
35+
export type ReducedMotionPreference = 'reduce' | 'no-preference' | null
36+
37+
export type ColorSchemePreference = 'light' | 'dark' | 'no-preference' | null

0 commit comments

Comments
 (0)