Skip to content

tests: add cypress-axe test for homepage #4362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b79a688
chore: add cypress-axe test for homepage
JoshuaKGoldberg Dec 29, 2021
9cd23c6
chore: add CI workflow
JoshuaKGoldberg Dec 30, 2021
790d724
chore: remove runs-on, let's hope the built-in chrome is sufficient
JoshuaKGoldberg Dec 30, 2021
9cfcb37
chore: missing runs-on
JoshuaKGoldberg Dec 30, 2021
65dffcc
chore: remove script ignores from yarn
JoshuaKGoldberg Dec 30, 2021
ff227da
chore: specify project
JoshuaKGoldberg Dec 30, 2021
4e2c718
chore: downgrade Cypress to 8.3.0
JoshuaKGoldberg Dec 31, 2021
8a5a2dc
chore: fix css, remove unnecessary build
JoshuaKGoldberg Dec 31, 2021
82c3019
chore: fix always() syntax in ci.yml
JoshuaKGoldberg Dec 31, 2021
aa68e2f
chore: err, move if up
JoshuaKGoldberg Dec 31, 2021
c6cd87a
chore: log stringified violations too
JoshuaKGoldberg Jan 2, 2022
5da6d09
chore: fix logo alt, and exclude stc
JoshuaKGoldberg Jan 2, 2022
8d135c4
Merge branch 'main' into cypress-axe
Jan 2, 2022
9d810de
chore: fix exclude: use an array
JoshuaKGoldberg Jan 7, 2022
7740e1a
Merge branch 'main'
JoshuaKGoldberg Feb 12, 2022
65a51d9
chore: expanded to dark mode too
JoshuaKGoldberg Feb 12, 2022
e2abbe9
chore: route is '/'
JoshuaKGoldberg Feb 12, 2022
0b448b6
Merge branch 'main' into cypress-axe
JoshuaKGoldberg Feb 12, 2022
5c7b20d
chore: fix lockfile and add a wait to checkAccessibility
JoshuaKGoldberg Feb 23, 2022
69f2d16
Merge branch 'main'
JoshuaKGoldberg Feb 23, 2022
55783b4
chore: use muted-color of #aaa
JoshuaKGoldberg Feb 23, 2022
e2c086d
Merge branch 'main' into cypress-axe
JoshuaKGoldberg Feb 23, 2022
9120cd0
Merge branch 'main' into cypress-axe
JoshuaKGoldberg Feb 24, 2022
b9b7c78
Merge branch 'main' into cypress-axe
JoshuaKGoldberg Feb 25, 2022
301f8fe
chore: up cy.wait to 500
JoshuaKGoldberg Mar 3, 2022
bb5371f
Merge branch 'main' into cypress-axe
JoshuaKGoldberg Mar 3, 2022
b91a294
Merge branch 'cypress-axe' of https://github.com/JoshuaKGoldberg/type…
JoshuaKGoldberg Mar 3, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 43 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
- name: Typecheck all packages
run: yarn typecheck

test_on_primary_node_version:
unit_test_on_primary_node_version:
name: Unit tests
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -310,13 +310,54 @@ jobs:

# eslint-plugin-internal is internal only - so don't care about compat on other versions

website_tests:
name: Website tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 2

- name: echo github.ref
run: echo ${{ github.ref }}

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-

- name: Install dependencies
run: yarn --ignore-engines --frozen-lockfile

- name: Cypress run
uses: cypress-io/github-action@v2
with:
project: ./packages/website
start: yarn start

- uses: actions/upload-artifact@v2
if: always()
with:
name: screenshots
path: |
packages/website/cypress/screenshots/
packages/website/cypress/videos/


publish_canary_version:
name: Publish the latest code as a canary version
runs-on: ubuntu-latest
needs:
[
typecheck,
test_on_primary_node_version,
unit_test_on_primary_node_version,
unit_tests_on_other_node_versions,
linting_and_style,
integration_tests,
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ yarn-error.log*
packages/website/.docusaurus
packages/website/.cache-loader
packages/website/build
packages/website/cypress/screenshots
packages/website/cypress/videos
packages/website/static/sandbox

# Runtime data
Expand Down
4 changes: 4 additions & 0 deletions packages/website/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"baseUrl": "http://localhost:3000",
"fixturesFolder": false
}
15 changes: 15 additions & 0 deletions packages/website/cypress/integration/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { checkAccessibility } from '../utils';

describe('Index', () => {
it('has no accessibility issues detected by aXe', () => {
cy.visit('/');
cy.injectAxe();

// 1. Check accessibility in default, light mode
checkAccessibility();

// 2. Check accessibility in dark mode
cy.contains('🌞').click();
checkAccessibility();
});
});
17 changes: 17 additions & 0 deletions packages/website/cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/// <reference types="cypress" />

/**
* @type {Cypress.PluginConfig}
*/
module.exports = on => {
on('task', {
log(message) {
console.log(message);
return null;
},
table(message) {
console.table(message);
return null;
},
});
};
1 change: 1 addition & 0 deletions packages/website/cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'cypress-axe';
1 change: 1 addition & 0 deletions packages/website/cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './commands';
28 changes: 28 additions & 0 deletions packages/website/cypress/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function terminalLog(violations) {
cy.task(
'log',
`${violations.length} accessibility violation${
violations.length === 1 ? '' : 's'
} detected`,
);
for (const violation of violations) {
cy.task('log', JSON.stringify(violation, null, 4));
}

cy.task(
'table',
violations.map(({ description, id, impact, nodes }) => ({
description,
id,
impact,
nodes: nodes.length,
})),
);
}

export function checkAccessibility() {
// Wait for any pending paints and ticks to clear
cy.wait(500);

cy.checkA11y(undefined, undefined, terminalLog);
}
2 changes: 1 addition & 1 deletion packages/website/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const config = {
title: 'TypeScript ESLint',
// hideOnScroll: true,
logo: {
alt: 'TypeScript ESLint',
alt: 'TypeScript ESLint logo',
height: '32px',
src: 'img/logo.svg',
width: '32px',
Expand Down
6 changes: 5 additions & 1 deletion packages/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"lint": "eslint . --ext .js,.ts --ignore-path ../../.eslintignore",
"serve": "docusaurus serve",
"start": "docusaurus start",
"swizzle": "docusaurus swizzle"
"swizzle": "docusaurus swizzle",
"test": "cypress run",
"test:open": "cypress open"
},
"dependencies": {
"@babel/runtime": "7.17.2",
Expand Down Expand Up @@ -39,6 +41,8 @@
"@types/react-helmet": "^6.1.4",
"@types/react-router-dom": "^5.3.2",
"copy-webpack-plugin": "^9.1.0",
"cypress": "8.3.0",
"cypress-axe": "^0.13.0",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-react": "^7.27.1",
"eslint-plugin-react-hooks": "^4.3.0",
Expand Down
11 changes: 9 additions & 2 deletions packages/website/src/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@import './prism.css';

/* You can override the default Infima variables here. */
:root {
html:root {
--ifm-color-primary: #3578e5;
--ifm-color-primary-dark: #1b62d4;
--ifm-color-primary-darker: #1751af;
Expand All @@ -17,11 +17,14 @@
--ifm-color-primary-lighter: #80aaef;
--ifm-color-primary-lightest: #a5c3f3;
--ifm-code-font-size: 95%;

--ifm-color-info: var(--ifm-color-primary-dark);
--ifm-link-color: var(--ifm-color-primary-dark);
--ifm-link-color: var(--ifm-color-primary-dark);

--code-line-decoration: rgba(53, 120, 229, 0.1);
--code-editor-bg: #ffffff;

--docsearch-muted-color: #666;
}

html[data-theme='dark'] {
Expand All @@ -37,6 +40,8 @@ html[data-theme='dark'] {
--ifm-code-background: rgb(40, 42, 54);
--ifm-code-color: rgb(248, 248, 242);
--ifm-color-info: var(--ifm-color-primary-light);
--ifm-link-color: var(--ifm-color-primary-light);
--ifm-link-color: var(--ifm-color-primary-light);
--ifm-menu-color-active: var(--ifm-color-primary-light);
--ifm-navbar-link-hover-color: var(--ifm-color-primary-light);

Expand All @@ -55,6 +60,8 @@ html[data-theme='dark'] {
--ifm-color-secondary-darkest: rgb(164, 166, 168);

scrollbar-color: #454a4d #202324;

--docsearch-muted-color: #aaa;
}

.docusaurus-highlight-code-line {
Expand Down
26 changes: 12 additions & 14 deletions packages/website/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,18 @@ const features: FeatureItem[] = [
</p>
</div>
<div className="col col--offset-2 col--8">
<p>
<code>typescript-eslint</code>:
<ul>
<li>allows ESLint to parse TypeScript syntax</li>
<li>
creates a set of tools for ESLint rules to be able to use
TypeScript's type information
</li>
<li>
provides a large list of lint rules that are specific to
TypeScript and/or use that type information
</li>
</ul>
</p>
<code>typescript-eslint</code>:
<ul>
<li>allows ESLint to parse TypeScript syntax</li>
<li>
creates a set of tools for ESLint rules to be able to use
TypeScript's type information
</li>
<li>
provides a large list of lint rules that are specific to
TypeScript and/or use that type information
</li>
</ul>
</div>
</div>
),
Expand Down
Loading