Skip to content

Commit

Permalink
[SPIKE] Check all pages accessibility
Browse files Browse the repository at this point in the history
  • Loading branch information
domoscargin committed Jul 20, 2023
1 parent e2f5131 commit d519a77
Showing 1 changed file with 37 additions and 31 deletions.
68 changes: 37 additions & 31 deletions __tests__/accessibility-audit.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const fs = require('fs')
const path = require('path')

const { AxePuppeteer } = require('@axe-core/puppeteer')

const { goTo } = require('../lib/puppeteer-helpers.js')
Expand Down Expand Up @@ -26,39 +29,42 @@ async function analyze (page, path) {
return axe.analyze()
}

describe('Accessibility Audit', () => {
describe('Home page - layout.njk', () => {
it('validates', async () => {
const results = await analyze(page, '/')
expect(results).toHaveNoViolations()
})
})
function getDirectoriesWithIndexHTML (directory) {
const result = []

function traverse (currentDir, depth) {
if (depth === 0) {
return
}

const files = fs.readdirSync(currentDir)

if (files.includes('index.html')) {
result.push(currentDir)
}

describe('Component page - layout-pane.njk', () => {
it('validates', async () => {
const results = await analyze(page, '/components/radios/')
expect(results).toHaveNoViolations()
})
})
for (const file of files) {
const filePath = path.join(currentDir, file)
const stat = fs.statSync(filePath)

describe('Patterns page - layout-pane.njk', () => {
it('validates', async () => {
const results = await analyze(page, '/patterns/gender-or-sex/')
expect(results).toHaveNoViolations()
})
})
if (stat.isDirectory()) {
traverse(filePath, depth - 1)
}
}
}

describe('Get in touch page - layout-single-page.njk', () => {
it('validates', async () => {
const results = await analyze(page, '/get-in-touch/')
expect(results).toHaveNoViolations()
})
})
traverse(directory, 3)

describe('Site Map page - layout-sitemap.njk', () => {
it('validates', async () => {
const results = await analyze(page, '/sitemap/')
expect(results).toHaveNoViolations()
})
})
return result.map((dir) => path.relative(directory, dir))
}

// Usage example
const directory = 'deploy/public'
const relativeDirectories = getDirectoriesWithIndexHTML(directory)

describe('Accessibility Audit', () => {
it.each(relativeDirectories)('validates %s', async (path) => {
const results = await analyze(page, path)
expect(results).toHaveNoViolations()
}, 10000)
})

0 comments on commit d519a77

Please sign in to comment.