-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathsite-with-errors.test.ts
More file actions
166 lines (158 loc) · 6.94 KB
/
Copy pathsite-with-errors.test.ts
File metadata and controls
166 lines (158 loc) · 6.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import type {Endpoints} from '@octokit/types'
import type {Result} from './types.d.js'
import fs from 'node:fs'
import {describe, it, expect, beforeAll} from 'vitest'
import {Octokit} from '@octokit/core'
import {throttling} from '@octokit/plugin-throttling'
const OctokitWithThrottling = Octokit.plugin(throttling)
function createOctokit(): InstanceType<typeof OctokitWithThrottling> {
return new OctokitWithThrottling({
auth: process.env.GITHUB_TOKEN,
throttle: {
onRateLimit: (retryAfter, options, octokit, retryCount) => {
octokit.log.warn(`Request quota exhausted for request ${options.method} ${options.url}`)
if (retryCount < 3) {
octokit.log.info(`Retrying after ${retryAfter} seconds!`)
return true
}
},
onSecondaryRateLimit: (retryAfter, options, octokit, retryCount) => {
octokit.log.warn(`Secondary rate limit hit for request ${options.method} ${options.url}`)
if (retryCount < 3) {
octokit.log.info(`Retrying after ${retryAfter} seconds!`)
return true
}
},
},
})
}
describe('site-with-errors', () => {
let results: Result[]
beforeAll(() => {
expect(process.env.CACHE_PATH).toBeDefined()
expect(fs.existsSync(process.env.CACHE_PATH!)).toBe(true)
results = JSON.parse(fs.readFileSync(process.env.CACHE_PATH!, 'utf-8'))
})
it('cache has expected results', () => {
const actual = results.map(({issue: {url: issueUrl}, findings}) => {
const {problemUrl, solutionLong, screenshotId, ...finding} = findings[0]
// Check volatile fields for existence only
expect(issueUrl).toBeDefined()
expect(problemUrl).toBeDefined()
expect(solutionLong).toBeDefined()
// Check `problemUrl`, ignoring axe version
expect(problemUrl.startsWith('https://dequeuniversity.com/rules/axe/')).toBe(true)
expect(problemUrl.endsWith(`/${finding.ruleId}?application=playwright`)).toBe(true)
// screenshotId is only present when include_screenshots is enabled
if (screenshotId !== undefined) {
expect(screenshotId).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/)
}
return finding
})
const expected = [
{
scannerType: 'axe',
url: 'http://127.0.0.1:4000/',
html: '<span class="post-meta">Jul 30, 2025</span>',
problemShort: 'elements must meet minimum color contrast ratio thresholds',
ruleId: 'color-contrast',
solutionShort:
'ensure the contrast between foreground and background colors meets wcag 2 aa minimum contrast ratio thresholds',
},
{
scannerType: 'axe',
url: 'http://127.0.0.1:4000/',
html: '<html lang="en">',
problemShort: 'page should contain a level-one heading',
ruleId: 'page-has-heading-one',
solutionShort: 'ensure that the page, or at least one of its frames contains a level-one heading',
},
{
scannerType: 'axe',
url: 'http://127.0.0.1:4000/jekyll/update/2025/07/30/welcome-to-jekyll.html',
html: `<time class="dt-published" datetime="2025-07-30T17:32:33+00:00" itemprop="datePublished">Jul 30, 2025
</time>`,
problemShort: 'elements must meet minimum color contrast ratio thresholds',
ruleId: 'color-contrast',
solutionShort:
'ensure the contrast between foreground and background colors meets wcag 2 aa minimum contrast ratio thresholds',
},
{
scannerType: 'axe',
url: 'http://127.0.0.1:4000/about/',
html: '<a href="https://jekyllrb.com/">jekyllrb.com</a>',
problemShort: 'elements must meet minimum color contrast ratio thresholds',
ruleId: 'color-contrast',
solutionShort:
'ensure the contrast between foreground and background colors meets wcag 2 aa minimum contrast ratio thresholds',
},
{
scannerType: 'axe',
url: 'http://127.0.0.1:4000/404.html',
html: '<li class="p-name">Accessibility Scanner Demo</li>',
problemShort: 'elements must meet minimum color contrast ratio thresholds',
ruleId: 'color-contrast',
solutionShort:
'ensure the contrast between foreground and background colors meets wcag 2 aa minimum contrast ratio thresholds',
},
{
scannerType: 'axe',
url: 'http://127.0.0.1:4000/404.html',
html: '<h1 class="post-title"></h1>',
problemShort: 'headings should not be empty',
ruleId: 'empty-heading',
solutionShort: 'ensure headings have discernible text',
},
]
// Check that:
// - every expected object exists (no more and no fewer), and
// - each object has all fields, and
// - field values match expectations exactly
// A specific order is _not_ enforced.
expect(actual).toHaveLength(expected.length)
expect(actual).toEqual(expect.arrayContaining(expected))
})
it('GITHUB_TOKEN environment variable is set', () => {
expect(process.env.GITHUB_TOKEN).toBeDefined()
})
describe.runIf(!!process.env.GITHUB_TOKEN)('issues', () => {
let issues: Endpoints['GET /repos/{owner}/{repo}/issues/{issue_number}']['response']['data'][]
beforeAll(async () => {
const octokit = createOctokit()
issues = await Promise.all(
results.map(async ({issue: {url: issueUrl}}) => {
expect(issueUrl).toBeDefined()
const {owner, repo, issueNumber} =
/https:\/\/github\.com\/(?<owner>[^/]+)\/(?<repo>[^/]+)\/issues\/(?<issueNumber>\d+)/.exec(
issueUrl!,
)!.groups!
const {data: issue} = await octokit.request('GET /repos/{owner}/{repo}/issues/{issue_number}', {
owner,
repo,
issue_number: parseInt(issueNumber, 10),
})
expect(issue).toBeDefined()
return issue
}),
)
})
it('issues exist and have expected title, state, and assignee', async () => {
const actualTitles = issues.map(({title}) => title)
const expectedTitles = [
'Accessibility issue: Elements must meet minimum color contrast ratio thresholds on /',
'Accessibility issue: Page should contain a level-one heading on /',
'Accessibility issue: Elements must meet minimum color contrast ratio thresholds on /404.html',
'Accessibility issue: Headings should not be empty on /404.html',
'Accessibility issue: Elements must meet minimum color contrast ratio thresholds on /about/',
'Accessibility issue: Elements must meet minimum color contrast ratio thresholds on /jekyll/update/2025/07/30/welcome-to-jekyll.html',
]
expect(actualTitles).toHaveLength(expectedTitles.length)
expect(actualTitles).toEqual(expect.arrayContaining(expectedTitles))
for (const issue of issues) {
expect(issue.state).toBe('open')
expect(issue.assignees).toBeDefined()
expect(issue.assignees!.some(a => a.login === 'Copilot')).toBe(true)
}
})
})
})