Skip to content
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

Fixed Lighthouse testing local and in CI #3355

Merged
merged 15 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion .github/workflows/lighthouse-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ jobs:
run: yarn install
- name: Build pages
run: yarn build
- name: Build urls
run: node ./lighthouse/lighthouse-get-urls.js
- name: Run Lighthouse CI
run: ./lighthouse/lighthouse.sh
run: |
npm install -g @lhci/[email protected]
lhci autorun --config=./lighthouse/lighthouserc.js
env:
LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ yarn start

Once the server has started, navigate to <http://localhost:3030>

## Lighthouse Testing - local

This project uses [LHCI](https://www.npmjs.com/package/@lhci/cli).

```bash
yarn global add @lhci/cli
yarn test-lighthouse
```

## Testing - macros and scripts

This project uses [jest](https://jestjs.io/docs/cli) and supports its command line options.
Expand Down
7 changes: 4 additions & 3 deletions lighthouse/lighthouse-get-urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ async function getURLs() {
for (const directory of directories) {
const folders = await readdir(directory.path);
for (const folder of folders) {
const files = await glob(`${directory.path}/${folder}/**/*.html`, { ignore: `${directory.path}/${folder}/index.html` });
for (const file of files) {
data.urls.push(file.replace('./build/', 'http://localhost:9000/'));
const files = await glob(`${directory.path}/${folder}/**/*.html`);
const filteredFiles = files.filter((path) => !path.includes('index.html') && !path.includes('example-skip-to-content.html'));
for (const file of filteredFiles) {
data.urls.push(file.replace('build/', 'http://localhost/'));
}
}
}
Expand Down
14 changes: 0 additions & 14 deletions lighthouse/lighthouse.sh

This file was deleted.

2 changes: 2 additions & 0 deletions lighthouse/lighthouserc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module.exports = {
ci: {
collect: {
staticDistDir: './build',
url: require('./urls.json').urls,
numberOfRuns: 1,
settings: {
onlyCategories: ['accessibility'],
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"test:no-build": "TEST_PORT=3020 TEST_WITH_PUPPETEER=1 jest '.*\\.spec\\.js'",
"test:with-log": "yarn test --no-color 2>test.log",
"test:start-server": "TEST_PORT=3020 gulp start-dev-server",
"test-lighthouse": "yarn build && node ./lighthouse/lighthouse-get-urls.js && lhci autorun --config=./lighthouse/lighthouserc.js",
"build": "yarn && yarn tidy-clean && NODE_ENV=production gulp build",
"build-serve": "yarn build && gulp start-dev-server",
"npm-bundle": "NODE_ENV=production yarn tidy-clean && NODE_ENV=production gulp build-package && babel-node ci/generate-npm-package.js",
Expand Down
Loading