diff --git a/.github/workflows/lighthouse-ci.yml b/.github/workflows/lighthouse-ci.yml index 661548623f..0436b896e8 100644 --- a/.github/workflows/lighthouse-ci.yml +++ b/.github/workflows/lighthouse-ci.yml @@ -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/cli@0.14.x + lhci autorun --config=./lighthouse/lighthouserc.js env: LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }} diff --git a/README.md b/README.md index 5be9bcc5ac..f2c6bd7d98 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,15 @@ yarn start Once the server has started, navigate to +## 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. diff --git a/lighthouse/lighthouse-get-urls.js b/lighthouse/lighthouse-get-urls.js index bd6dfc0710..aa68906ca7 100644 --- a/lighthouse/lighthouse-get-urls.js +++ b/lighthouse/lighthouse-get-urls.js @@ -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/')); } } } diff --git a/lighthouse/lighthouse.sh b/lighthouse/lighthouse.sh deleted file mode 100755 index cb17c08fc3..0000000000 --- a/lighthouse/lighthouse.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -node ./lighthouse/lighthouse-get-urls.js -npx http-server -p 9000 ./build & -npm install -g @lhci/cli@0.12.x -lhci healthcheck --fatal -for url in $(jq '.urls[]' ./lighthouse/urls.json); do sem - lhci collect "--url=$url" --additive --config=./lighthouse/lighthouserc.js & -done -sem --wait -lhci assert --config=./lighthouse/lighthouserc.js -lhci upload --config=./lighthouse/lighthouserc.js -EXIT_CODE=$? -kill $! -exit $EXIT_CODE diff --git a/lighthouse/lighthouserc.js b/lighthouse/lighthouserc.js index 17da4d3b4c..42987617d4 100644 --- a/lighthouse/lighthouserc.js +++ b/lighthouse/lighthouserc.js @@ -1,6 +1,8 @@ module.exports = { ci: { collect: { + staticDistDir: './build', + url: require('./urls.json').urls, numberOfRuns: 1, settings: { onlyCategories: ['accessibility'], diff --git a/package.json b/package.json index e0771811f5..91056488cb 100644 --- a/package.json +++ b/package.json @@ -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",