Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

Commit 77772dd

Browse files
jbedarddevversion
authored andcommitted
test: run audit tests from isolated js script
1 parent 41f7205 commit 77772dd

File tree

4 files changed

+73
-80
lines changed

4 files changed

+73
-80
lines changed

.circleci/config.yml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,6 @@ jobs:
8989
- browser-tools/install-browser-tools
9090
- run: yarn test --watch false --progress=false
9191

92-
audit_pages_for_a11y:
93-
<<: *job_defaults
94-
steps:
95-
- attach_workspace:
96-
at: *workspace_location
97-
- checkout
98-
- restore_cache:
99-
key: *cache_key
100-
- *yarn_install
101-
- run: yarn test:audit:a11y:ci
102-
10392
lighthouse_audits:
10493
<<: *job_defaults
10594
steps:
@@ -118,9 +107,6 @@ workflows:
118107
- lint
119108
- build
120109
- test
121-
- audit_pages_for_a11y:
122-
requires:
123-
- build
124110
- lighthouse_audits:
125111
requires:
126112
- build

package.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,8 @@
2424
"publish-beta": "bash ./tools/deploy.sh stable beta",
2525
"scenes:generate": "ng e2e --port 4201 scenes && yarn scenes:optimize",
2626
"scenes:optimize": "node tools/optimize-scene-screenshots",
27-
"test:audit:a11y": "node tools/audit-docs-a11y",
28-
"test:audit:a11y:localhost": "run-p --race \"~~light-server -s dist/material-angular-io -p 4200 --quiet\" \"test:audit:a11y http://localhost:4200\" --",
29-
"test:audit:a11y:ci": "run-p --race \"~~light-server -s ../dist/material-angular-io -p 4200 --quiet\" \"test:audit:a11y http://localhost:4200\" --",
30-
"test:audit": "node tools/audit-docs",
31-
"test:audit:localhost": "run-p --race \"start:static\" \"test:audit http://localhost:4200 2000\" --",
32-
"test:audit:ci": "run-p --race \"~~light-server -s ../dist/material-angular-io -p 4200 --quiet\" \"test:audit http://localhost:4200\" --",
33-
"~~light-server": "light-server --bind=localhost --historyindex=/index.html --no-reload"
27+
"test:audit:localhost": "node tools/audit-docs dist/material-angular-io",
28+
"test:audit:ci": "node tools/audit-docs ../dist/material-angular-io"
3429
},
3530
"private": true,
3631
"dependencies": {

tools/audit-docs-a11y.js

Lines changed: 0 additions & 46 deletions
This file was deleted.

tools/audit-docs.js

Lines changed: 71 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,27 @@
2323
const sh = require('shelljs');
2424
sh.set('-e');
2525

26+
const lightServer = require('light-server');
27+
2628
// Constants
29+
30+
// Individual page a11y scores
31+
const MIN_A11Y_SCORES_PER_PAGE = {
32+
'' : 100,
33+
'components/categories' : 91,
34+
'cdk/categories' : 91,
35+
'guides' : 100,
36+
'guide/creating-a-custom-form-field-control' : 97,
37+
'guide/getting-started' : 96,
38+
'cdk/a11y/overview' : 85,
39+
'cdk/a11y/api' : 89,
40+
'cdk/a11y/examples' : 85,
41+
'components/button/overview' : 92,
42+
'components/button/api' : 89,
43+
'components/button/examples' : 90,
44+
};
45+
46+
2747
/**
2848
* @type {{minScores: {performance: number, accessibility: number, 'best-practices': number, pwa: number, seo: number}, url: string}[]}
2949
*/
@@ -37,7 +57,11 @@ const MIN_SCORES_PER_PAGE = [
3757
'best-practices': 100,
3858
'accessibility': 100
3959
}
40-
}
60+
},
61+
...Object.entries(MIN_A11Y_SCORES_PER_PAGE).map(([url, accessibility]) => ({
62+
url,
63+
minScores: {accessibility}
64+
}))
4165
];
4266

4367
/**
@@ -55,18 +79,52 @@ function formatScores(scores) {
5579
return formattedScores;
5680
}
5781

82+
83+
// Launch the light-server to run tests again
84+
const bundle = process.argv[2];
85+
const delay = process.argv[3];
86+
87+
const bind = 'localhost';
88+
const port = 4200;
89+
const origin = `http://${bind}:${port}`;
90+
91+
console.log('Launch audit HTTP server...');
92+
93+
lightServer({
94+
port,
95+
bind,
96+
serve: bundle,
97+
quiet: true,
98+
noReload: true,
99+
historyindex: '/index.html',
100+
101+
// Defaults from .bin/light-server
102+
interval: 500,
103+
delay: 0,
104+
proxypaths: ['/'],
105+
watchexps: []
106+
})
107+
.start()
108+
58109
// Run the a11y audit against the above pages
59110
const lighthouseAuditCmd = `"${process.execPath}" "${__dirname}/lighthouse-audit"`;
60-
const origin = process.argv[2];
61-
const delay = process.argv[3];
62-
if (delay) {
63-
setTimeout(_main, delay);
64-
} else {
65-
_main();
66-
}
67111

68-
function _main() {
69-
MIN_SCORES_PER_PAGE.map((urlsAndScores) => {
70-
sh.exec(`${lighthouseAuditCmd} ${origin}/${urlsAndScores.url} ${formatScores(urlsAndScores.minScores)}`);
71-
});
72-
}
112+
setTimeout(async function() {
113+
console.log('Run audit tests...');
114+
115+
try {
116+
for (const {url, minScores} of MIN_SCORES_PER_PAGE) {
117+
await new Promise((resolve, reject) => {
118+
const cp = sh.exec(`${lighthouseAuditCmd} ${origin}/${url} ${formatScores(minScores)}`, {async: true});
119+
120+
cp.on('error', reject);
121+
cp.on('exit', err => (err ? reject : resolve)(err));
122+
});
123+
}
124+
125+
process.exit(0);
126+
} catch(e) {
127+
console.log('Audit failure: ', e);
128+
process.exit(1);
129+
}
130+
}, delay);

0 commit comments

Comments
 (0)