Skip to content

Commit 41bab60

Browse files
authored
test: add basic axe component tests (npmx-dev#87)
1 parent d602619 commit 41bab60

10 files changed

Lines changed: 838 additions & 6 deletions

File tree

CONTRIBUTING.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,32 @@ describe('featureName', () => {
227227
> [!TIP]
228228
> If you need access to the Nuxt context in your unit or component test, place your test in the `test/nuxt/` directory and run with `pnpm test:nuxt`
229229
230-
### E2e tests
230+
### Component accessibility tests
231+
232+
All new components should have a basic accessibility test in `test/nuxt/components.spec.ts`. These tests use [axe-core](https://github.com/dequelabs/axe-core) to catch common accessibility violations.
233+
234+
```typescript
235+
import MyComponent from '~/components/MyComponent.vue'
236+
237+
describe('MyComponent', () => {
238+
it('should have no accessibility violations', async () => {
239+
const component = await mountSuspended(MyComponent, {
240+
props: {
241+
/* required props */
242+
},
243+
})
244+
const results = await runAxe(component)
245+
expect(results.violations).toEqual([])
246+
})
247+
})
248+
```
249+
250+
The `runAxe` helper handles DOM isolation and disables page-level rules that don't apply to isolated component testing.
251+
252+
> [!IMPORTANT]
253+
> Just because axe-core doesn't find any obvious issues, it does not mean a component is accessible. Please do additional checks and use best practices.
254+
255+
### End to end tests
231256

232257
Write end-to-end tests using Playwright:
233258

app/app.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ button {
285285
border-left: 2px solid #262626;
286286
padding-left: 1rem;
287287
margin: 1.5rem 0;
288-
color: #666666;
288+
color: #8a8a8a;
289289
font-style: italic;
290290
}
291291

app/components/CodeViewer.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ watch(
6666
:id="`L${lineNum}`"
6767
:key="lineNum"
6868
:href="`#L${lineNum}`"
69+
tabindex="-1"
6970
class="line-number block px-3 py-0 font-mono text-sm leading-6 cursor-pointer transition-colors no-underline"
7071
:class="[
7172
isLineSelected(lineNum)

app/components/OgImage/Default.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div class="h-full w-full flex flex-col justify-center items-center bg-[#0a0a0a] text-[#fafafa]">
33
<h1 class="text-6xl font-medium tracking-tight" style="font-family: 'Geist Mono'">
4-
<span class="text-[#666666]" style="letter-spacing: -0.1em">./</span> npmx
4+
<span class="text-fg-subtle" style="letter-spacing: -0.1em">./</span> npmx
55
</h1>
66
<h1 class="text-3xl font-medium tracking-tight">a better browser for the npm registry</h1>
77

app/components/OgImage/Package.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ withDefaults(
2222
{{ name }}
2323
</h1>
2424

25-
<div class="flex items-center gap-6 mt-6 text-xl text-[#666666]">
25+
<div class="flex items-center gap-6 mt-6 text-xl text-fg-subtle">
2626
<span>v{{ version }}</span>
2727
<span v-if="downloads">{{ downloads }}/wk</span>
2828
<span v-if="license">{{ license }}</span>

app/components/PackageDownloadStats.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const config = computed(() => ({
5959
title: {
6060
text: lastDatapoint.value,
6161
fontSize: 12,
62-
color: '#666666',
62+
color: '#8A8A8A',
6363
bold: false,
6464
},
6565
verticalIndicator: {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"@vitest/browser-playwright": "^4.0.18",
6767
"@vitest/coverage-v8": "^4.0.18",
6868
"@vue/test-utils": "2.4.6",
69+
"axe-core": "^4.11.1",
6970
"happy-dom": "20.3.5",
7071
"lint-staged": "16.2.7",
7172
"marked": "17.0.1",

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)