build(docs-infra): update scripts using Lighthouse to ES modules (#43607)

Update the AIO scripts that use Lighthouse (i.e. `audit-web-app.js` and
`test-aio-a11y.js`) to ES modules. This allows consuming
`lighthouse/lighthouse-cli` [v8.5.0+][1], which also switched to ES
modules.

NOTE:
Switching the `test-aio-a11y.js` script to ES modules is not strictly
necessary, since it invokes `audit-web-app.mjs` via a shell command, but
it was done for consistency.

[1]: https://github.com/GoogleChrome/lighthouse/releases/tag/v8.5.0

PR Close #43607
This commit is contained in:
George Kalpakas
2021-10-01 22:25:38 +03:00
committed by Dylan Hunn
parent 353d699766
commit c997fef08a
4 changed files with 18 additions and 16 deletions
+4 -4
View File
@@ -35,7 +35,7 @@
"set-opensearch-url": "node --eval \"const sh = require('shelljs'); sh.set('-e'); sh.sed('-i', /PLACEHOLDER_URL/g, process.argv[1], 'dist/assets/opensearch.xml');\"",
"presmoke-tests": "yarn update-webdriver",
"smoke-tests": "protractor tests/deployment/e2e/protractor.conf.js --suite smoke --baseUrl",
"test-a11y-score": "node scripts/test-aio-a11y",
"test-a11y-score": "node scripts/test-aio-a11y.mjs",
"test-a11y-score-localhost": "run-p --race \"~~light-server -s dist -p 4200 --quiet\" \"test-a11y-score http://localhost:4200\" --",
"test-pwa-score": "run-s \"~~audit-web-app {1} all:0,pwa:{2} {3}\" --",
"test-pwa-score-localhost": "run-p --race \"~~light-server -s dist -p 4200 --quiet\" \"test-pwa-score http://localhost:4200 {1} {2}\" --",
@@ -69,7 +69,7 @@
"build-404-page": "node scripts/build-404-page",
"update-webdriver": "node ../scripts/webdriver-manager-update.js",
"security-lint": "tsec -p tsconfig.app.json",
"~~audit-web-app": "node scripts/audit-web-app",
"~~audit-web-app": "node scripts/audit-web-app.mjs",
"~~check-env": "node scripts/check-environment",
"~~clean-generated": "node --eval \"require('shelljs').rm('-rf', 'src/generated')\"",
"pre~~build": "yarn ~~build-ce-es5-polyfills && yarn ~~build-ngsw-config",
@@ -162,8 +162,8 @@
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.5.0",
"light-server": "^2.9.1",
"lighthouse": "^8.1.0",
"lighthouse-logger": "^1.2.0",
"lighthouse": "^8.5.1",
"lighthouse-logger": "^1.3.0",
"lodash": "^4.17.21",
"lunr": "^2.3.9",
"npm-run-all": "^4.1.5",
@@ -1,10 +1,9 @@
#!/bin/env node
'use strict';
/**
* Usage:
* ```sh
* node scripts/audit-web-app <url> <min-scores> [<log-file>]
* node scripts/audit-web-app.mjs <url> <min-scores> [<log-file>]
* ```
*
* Runs audits against the specified URL on specific categories (accessibility, best practices, performance, PWA, SEO).
@@ -27,10 +26,10 @@
*/
// Imports
const lighthouse = require('lighthouse');
const printer = require('lighthouse/lighthouse-cli/printer');
const logger = require('lighthouse-logger');
const puppeteer = require('puppeteer');
import lighthouse from 'lighthouse';
import * as printer from 'lighthouse/lighthouse-cli/printer.js';
import logger from 'lighthouse-logger';
import puppeteer from 'puppeteer';
// Constants
const AUDIT_CATEGORIES = ['accessibility', 'best-practices', 'performance', 'pwa', 'seo'];
@@ -1,10 +1,9 @@
#!/bin/env node
'use strict';
/**
* Usage:
* ```sh
* node scripts/test-aio-a11y <origin>
* node scripts/test-aio-a11y.mjs <origin>
* ```
*
* Runs accessibility audits on several (pre-defined) pages on the specified origin. It fails, if
@@ -15,7 +14,10 @@
*/
// Imports
const sh = require('shelljs');
import {dirname} from 'path';
import sh from 'shelljs';
import {fileURLToPath} from 'url';
sh.set('-e');
// Constants
@@ -32,7 +34,8 @@ const MIN_SCORES_PER_PAGE = {
};
// Run
const auditWebAppCmd = `"${process.execPath}" "${__dirname}/audit-web-app"`;
const __dirname = dirname(fileURLToPath(import.meta.url));
const auditWebAppCmd = `"${process.execPath}" "${__dirname}/audit-web-app.mjs"`;
const origin = process.argv[2];
for (const [page, minScore] of Object.entries(MIN_SCORES_PER_PAGE)) {
sh.exec(`${auditWebAppCmd} ${origin}/${page} accessibility:${minScore}`);
+2 -2
View File
@@ -7487,7 +7487,7 @@ light-server@^2.9.1:
strip-json-comments "^3.1.1"
ws "^7.3.1"
lighthouse-logger@^1.0.0, lighthouse-logger@^1.2.0, lighthouse-logger@^1.3.0:
lighthouse-logger@^1.0.0, lighthouse-logger@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/lighthouse-logger/-/lighthouse-logger-1.3.0.tgz#ba6303e739307c4eee18f08249524e7dafd510db"
integrity sha512-BbqAKApLb9ywUli+0a+PcV04SyJ/N1q/8qgCNe6U97KbPCS1BTksEuHFLYdvc8DltuhfxIUBqDZsC0bBGtl3lA==
@@ -7500,7 +7500,7 @@ lighthouse-stack-packs@^1.5.0:
resolved "https://registry.yarnpkg.com/lighthouse-stack-packs/-/lighthouse-stack-packs-1.5.0.tgz#c191f2b94db21602254baaebfb0bb90307a00ffa"
integrity sha512-ntVOqFsrrTQYrNf+W+sNE9GjddW+ab5QN0WrrCikjMFsUvEQ28CvT0SXcHPZXFtcsb1lMSuVaNCmEuj7oXtYGQ==
lighthouse@^8.1.0:
lighthouse@^8.5.1:
version "8.5.1"
resolved "https://registry.yarnpkg.com/lighthouse/-/lighthouse-8.5.1.tgz#0cf4f2d3ebf67e40cd14fcbb027c9d5fb3cfa912"
integrity sha512-phe3g77N5AE5pf5TARUBb9uHLvvzwpd2z/S0G+6KrC5ShEe2laSxkiiTLo/jYxsrmy5kL7qohVztdOuafy4HGQ==