Skip to content

Commit

Permalink
feat(frontend): load and display accessibility issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jmiguelv committed Jul 5, 2024
1 parent 4817f2b commit 9d8dcdc
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 32 deletions.
29 changes: 21 additions & 8 deletions frontend/src/routes/_qa/+page.server.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
import { DEBUG } from '$env/static/private';
import { error } from '@sveltejs/kit';
import { existsSync, readFileSync } from 'fs';
import fs from 'fs';
import path from 'path';

/** @type {import('./$types').PageServerLoad} */
export async function load() {
if (DEBUG !== 'true') {
return { prerender: [] };
return { prerender: {}, axe: [] };
}

const errorFilePath = 'src/lib/prerender-errors.json';
const prerenderFilePath = 'src/lib/prerender-errors.json';
let prerender = {};

if (!existsSync(errorFilePath)) {
return { prerender: [] };
}
const axeDirPath = 'test-results';
let axe = [];

try {
const prerender = JSON.parse(readFileSync(errorFilePath, 'utf-8'));
return { prerender: Object.values(prerender) };
if (fs.existsSync(prerenderFilePath)) {
prerender = JSON.parse(fs.readFileSync(prerenderFilePath, 'utf-8'));
}

if (fs.existsSync(axeDirPath)) {
for (const file of fs.readdirSync(axeDirPath)) {
if (file.endsWith('.axe.json')) {
const filePath = path.join(axeDirPath, file);
axe = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
}
}
}

return { prerender: Object.values(prerender), axe };
} catch (e) {
error(404, 'Could not load prerender-errors.json');
}
Expand Down
84 changes: 60 additions & 24 deletions frontend/src/routes/_qa/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,66 @@
<article>
<h1>QA</h1>

<section>
<hgroup>
<h2>Build errors</h2>
<p><strong>{data.prerender.length}</strong> build errors found!</p>
</hgroup>
<table>
<thead>
<tr>
<th>Timestamp</th>
<th>Path</th>
<th>Referrer</th>
<th>Message</th>
</tr>
</thead>
<tbody>
{#each data.prerender as error}
{#if data.prerender}
<section id="qa">
<hgroup>
<h2>Build errors</h2>
<p><strong>{data.prerender.length}</strong> build errors found!</p>
</hgroup>
<table>
<thead>
<tr>
<td>{error.timestamp}</td>
<td>{error.path}</td>
<td><BaseLink href={error.referrer}>{error.referrer}</BaseLink></td>
<td>{error.message}</td>
<th>Timestamp</th>
<th>Path</th>
<th>Referrer</th>
<th>Message</th>
</tr>
{/each}
</tbody>
</table>
</section>
</thead>
<tbody>
{#each data.prerender as error}
<tr>
<td>{error.timestamp}</td>
<td>{error.path}</td>
<td><BaseLink href={error.referrer}>{error.referrer}</BaseLink></td>
<td>{error.message}</td>
</tr>
{/each}
</tbody>
</table>
</section>
{/if}

{#if Object.keys(data.axe).length > 0}
<section id="axe">
<h2>Accessibility issues</h2>
{#each Object.keys(data.axe) as page}
<hgroup>
<h3><BaseLink href={page}>{page}</BaseLink></h3>
<p><strong>{data.axe[page].length}</strong> accessibility issues found!</p>
</hgroup>
<table>
<thead>
<tr>
<th>ID</th>
<th>Impact</th>
<th>Description</th>
<th>Target</th>
<th>Help</th>
</tr>
</thead>
<tbody>
{#each data.axe[page] as violation}
<tr>
<td>{violation.id}</td>
<td>{violation.impact}</td>
<td>{violation.description}</td>
<td>{violation.nodes[0].target}</td>
<td><a href={violation.helpUrl}>{violation.help}</a></td>
</tr>
{/each}
</tbody>
</table>
{/each}
</section>
{/if}
</article>

0 comments on commit 9d8dcdc

Please sign in to comment.