From e1bf99905ef7ddbe832c2d35a2c77a456bd85d34 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Fri, 10 Sep 2021 15:57:51 -0700 Subject: [PATCH 01/11] tests(smokehouse): convert to ES modules --- .../smokehouse/frontends/back-compat-util.js | 4 +- .../test/smokehouse/frontends/lib.js | 9 +- .../test/smokehouse/frontends/node.js | 2 +- .../smokehouse/frontends/smokehouse-bin.js | 39 ++-- .../smokehouse/lib/child-process-error.js | 2 +- .../test/smokehouse/lib/concurrent-mapper.js | 2 +- .../test/smokehouse/lib/local-console.js | 2 +- .../smokehouse/lighthouse-runners/bundle.js | 11 +- .../test/smokehouse/lighthouse-runners/cli.js | 24 +-- lighthouse-cli/test/smokehouse/package.json | 4 + .../test/smokehouse/report-assert.js | 25 +-- lighthouse-cli/test/smokehouse/smokehouse.js | 27 +-- .../test-definitions/a11y/a11y-config.js | 6 +- .../test-definitions/a11y/expectations.js | 2 +- .../byte-efficiency/byte-config.js | 2 +- .../byte-efficiency/expectations.js | 4 +- .../smokehouse/test-definitions/core-tests.js | 170 ++++++++++-------- .../test-definitions/csp/csp-config.js | 4 +- .../test-definitions/csp/csp-expectations.js | 4 +- .../dobetterweb/dbw-config.js | 6 +- .../dobetterweb/dbw-expectations.js | 2 +- .../test-definitions/errors/error-config.js | 6 +- .../errors/error-expectations.js | 4 +- .../test-definitions/forms/form-config.js | 4 +- .../forms/form-expectations.js | 2 +- .../lantern/lantern-config.js | 6 +- .../lantern/lantern-expectations.js | 4 +- .../legacy-javascript/expectations.js | 2 +- .../legacy-javascript-config.js | 6 +- .../mixed-content/expectations.js | 40 +++++ .../offline-local/offline-config.js | 6 +- .../offline-local/offline-expectations.js | 4 +- .../test-definitions/oopif/oopif-config.js | 9 +- .../oopif/oopif-expectations.js | 4 +- .../perf-diagnostics/expectations.js | 4 +- .../perf-diagnostics-config.js | 4 +- .../test-definitions/perf/expectations.js | 4 +- .../test-definitions/perf/perf-config.js | 4 +- .../test-definitions/pwa/pwa-config.js | 6 +- .../pwa/pwa-expectations-details.js | 2 +- .../test-definitions/pwa/pwa-expectations.js | 6 +- .../test-definitions/pwa/pwa2-expectations.js | 7 +- .../test-definitions/pwa/pwa3-expectations.js | 7 +- .../redirects/expectations.js | 4 +- .../redirects/redirects-config.js | 6 +- .../screenshot/expectations.js | 2 +- .../screenshot/screenshot-config.js | 4 +- .../test-definitions/seo/expectations.js | 4 +- .../test-definitions/seo/seo-config.js | 6 +- .../source-maps/expectations.js | 7 +- .../source-maps/source-maps-config.js | 4 +- .../tricky-metrics/expectations.js | 4 +- .../tricky-metrics/no-throttling-config.js | 2 +- package.json | 7 +- yarn.lock | 32 +++- 55 files changed, 369 insertions(+), 205 deletions(-) create mode 100644 lighthouse-cli/test/smokehouse/package.json create mode 100644 lighthouse-cli/test/smokehouse/test-definitions/mixed-content/expectations.js diff --git a/lighthouse-cli/test/smokehouse/frontends/back-compat-util.js b/lighthouse-cli/test/smokehouse/frontends/back-compat-util.js index 2bf1bf5db862..62110adbf267 100644 --- a/lighthouse-cli/test/smokehouse/frontends/back-compat-util.js +++ b/lighthouse-cli/test/smokehouse/frontends/back-compat-util.js @@ -37,6 +37,6 @@ function updateTestDefnFormat(allTestDefns) { return expandedTestDefns.flat(); } -module.exports = { - updateTestDefnFormat, +export { + updateTestDefnFormat }; diff --git a/lighthouse-cli/test/smokehouse/frontends/lib.js b/lighthouse-cli/test/smokehouse/frontends/lib.js index 70f05fe60486..fd7c11841531 100644 --- a/lighthouse-cli/test/smokehouse/frontends/lib.js +++ b/lighthouse-cli/test/smokehouse/frontends/lib.js @@ -13,9 +13,10 @@ /* eslint-disable no-console */ -const cloneDeep = require('lodash.clonedeep'); -const smokeTests = require('../test-definitions/core-tests.js'); -const {runSmokehouse} = require('../smokehouse.js'); +import cloneDeep from 'lodash.clonedeep'; + +import smokeTests from '../test-definitions/core-tests.js'; +import {runSmokehouse} from '../smokehouse.js'; /** * @param {Smokehouse.SmokehouseLibOptions} options @@ -43,4 +44,4 @@ async function smokehouse(options) { return runSmokehouse(modifiedTests, smokehouseOptions); } -module.exports = smokehouse; +export {smokehouse}; diff --git a/lighthouse-cli/test/smokehouse/frontends/node.js b/lighthouse-cli/test/smokehouse/frontends/node.js index c00452dfe350..113695a750ca 100644 --- a/lighthouse-cli/test/smokehouse/frontends/node.js +++ b/lighthouse-cli/test/smokehouse/frontends/node.js @@ -10,4 +10,4 @@ */ // Smokehouse is runnable from within node, so just a no-op for now. -module.exports = require('../smokehouse.js'); +export * from '../smokehouse.js'; diff --git a/lighthouse-cli/test/smokehouse/frontends/smokehouse-bin.js b/lighthouse-cli/test/smokehouse/frontends/smokehouse-bin.js index f5f1a285fd05..025c26c2b2ba 100644 --- a/lighthouse-cli/test/smokehouse/frontends/smokehouse-bin.js +++ b/lighthouse-cli/test/smokehouse/frontends/smokehouse-bin.js @@ -13,17 +13,21 @@ /* eslint-disable no-console */ -const fs = require('fs'); -const path = require('path'); -const cloneDeep = require('lodash.clonedeep'); -const yargs = require('yargs'); -const log = require('lighthouse-logger'); -const {runSmokehouse} = require('../smokehouse.js'); -const {updateTestDefnFormat} = require('./back-compat-util.js'); -const {LH_ROOT} = require('../../../../root.js'); +import path from 'path'; +import fs from 'fs'; + +import cloneDeep from 'lodash.clonedeep'; +import yargs from 'yargs'; +// @ts-expect-error: TODO: no types until @types/yargs 16 ... should upgrade yargs first. +import * as yargsHelpers from 'yargs/helpers'; +import log from 'lighthouse-logger'; + +import {runSmokehouse} from '../smokehouse.js'; +import {updateTestDefnFormat} from './back-compat-util.js'; +import {LH_ROOT} from '../../../../root.js'; const coreTestDefnsPath = - path.join(LH_ROOT, 'lighthouse-cli/test/smokehouse/test-definitions/core-tests.js'); + `${LH_ROOT}/lighthouse-cli/test/smokehouse/test-definitions/core-tests.js`; /** * Possible Lighthouse runners. Loaded dynamically so e.g. a CLI run isn't @@ -115,7 +119,8 @@ function pruneExpectedNetworkRequests(testDefns, takeNetworkRequestUrls) { * CLI entry point. */ async function begin() { - const rawArgv = yargs + const y = yargs(yargsHelpers.hideBin(process.argv)); + const rawArgv = y .help('help') .usage('node $0 [] ') .example('node $0 -j=1 pwa seo', 'run pwa and seo tests serially') @@ -159,7 +164,7 @@ async function begin() { describe: 'Run all available tests except the ones provided', }, }) - .wrap(yargs.terminalWidth()) + .wrap(y.terminalWidth()) .argv; // Augmenting yargs type with auto-camelCasing breaks in tsc@4.1.2 and @types/yargs@15.0.11, @@ -173,13 +178,17 @@ async function begin() { if (argv.runner === 'bundle') { console.log('\n✨ Be sure to have recently run this: yarn build-all'); } - const lighthouseRunner = require(runnerPath).runLighthouse; + const {runLighthouse} = await import(runnerPath); // Find test definition file and filter by requestedTestIds. let testDefnPath = argv.testsPath || coreTestDefnsPath; testDefnPath = path.resolve(process.cwd(), testDefnPath); const requestedTestIds = argv._; - const rawTestDefns = require(testDefnPath); + let rawTestDefns = await import(testDefnPath); + if (rawTestDefns) { + // Support commonjs. + rawTestDefns = rawTestDefns.default || rawTestDefns; + } const allTestDefns = updateTestDefnFormat(rawTestDefns); const invertMatch = argv.invertMatch; const testDefns = getDefinitionsToRun(allTestDefns, requestedTestIds, {invertMatch}); @@ -192,7 +201,7 @@ async function begin() { try { // If running the core tests, spin up the test server. if (testDefnPath === coreTestDefnsPath) { - ({server, serverForOffline} = require('../../fixtures/static-server.js')); + ({server, serverForOffline} = await import('../../fixtures/static-server.js')); server.listen(10200, 'localhost'); serverForOffline.listen(10503, 'localhost'); takeNetworkRequestUrls = server.takeRequestUrls.bind(server); @@ -204,7 +213,7 @@ async function begin() { retries, isDebug: argv.debug, useFraggleRock: argv.fraggleRock, - lighthouseRunner, + lighthouseRunner: runLighthouse, takeNetworkRequestUrls, }; diff --git a/lighthouse-cli/test/smokehouse/lib/child-process-error.js b/lighthouse-cli/test/smokehouse/lib/child-process-error.js index 998c925caf29..096e2c68dca6 100644 --- a/lighthouse-cli/test/smokehouse/lib/child-process-error.js +++ b/lighthouse-cli/test/smokehouse/lib/child-process-error.js @@ -23,4 +23,4 @@ class ChildProcessError extends Error { } } -module.exports = ChildProcessError; +export {ChildProcessError}; diff --git a/lighthouse-cli/test/smokehouse/lib/concurrent-mapper.js b/lighthouse-cli/test/smokehouse/lib/concurrent-mapper.js index 72b307b9ff19..c7fd8408a23b 100644 --- a/lighthouse-cli/test/smokehouse/lib/concurrent-mapper.js +++ b/lighthouse-cli/test/smokehouse/lib/concurrent-mapper.js @@ -123,4 +123,4 @@ class ConcurrentMapper { } } -module.exports = ConcurrentMapper; +export {ConcurrentMapper}; diff --git a/lighthouse-cli/test/smokehouse/lib/local-console.js b/lighthouse-cli/test/smokehouse/lib/local-console.js index c439e50734ae..9b6d00ca0655 100644 --- a/lighthouse-cli/test/smokehouse/lib/local-console.js +++ b/lighthouse-cli/test/smokehouse/lib/local-console.js @@ -48,4 +48,4 @@ class LocalConsole { } } -module.exports = LocalConsole; +export {LocalConsole}; diff --git a/lighthouse-cli/test/smokehouse/lighthouse-runners/bundle.js b/lighthouse-cli/test/smokehouse/lighthouse-runners/bundle.js index de9547c93180..89fefa89c8cf 100644 --- a/lighthouse-cli/test/smokehouse/lighthouse-runners/bundle.js +++ b/lighthouse-cli/test/smokehouse/lighthouse-runners/bundle.js @@ -11,8 +11,9 @@ * Currently uses `lighthouse-dt-bundle.js`. */ -const ChromeLauncher = require('chrome-launcher'); -const ChromeProtocol = require('../../../../lighthouse-core/gather/connections/cri.js'); +import ChromeLauncher from 'chrome-launcher'; + +import ChromeProtocol from '../../../../lighthouse-core/gather/connections/cri.js'; const originalRequire = global.require; if (typeof globalThis === 'undefined') { @@ -22,7 +23,7 @@ if (typeof globalThis === 'undefined') { // Load bundle, which creates a `global.runBundledLighthouse`. // @ts-ignore - file exists if `yarn build-all` is run, but not used for types anyways. -require('../../../../dist/lighthouse-dt-bundle.js'); // eslint-disable-line +import '../../../../dist/lighthouse-dt-bundle.js'; // eslint-disable-line global.require = originalRequire; @@ -60,6 +61,6 @@ async function runLighthouse(url, configJson, testRunnerOptions = {}) { } } -module.exports = { - runLighthouse, +export { + runLighthouse }; diff --git a/lighthouse-cli/test/smokehouse/lighthouse-runners/cli.js b/lighthouse-cli/test/smokehouse/lighthouse-runners/cli.js index fb3f384e79bb..4619e8aac5b8 100644 --- a/lighthouse-cli/test/smokehouse/lighthouse-runners/cli.js +++ b/lighthouse-cli/test/smokehouse/lighthouse-runners/cli.js @@ -12,16 +12,18 @@ * them. */ -const fs = require('fs').promises; -const {promisify} = require('util'); -const execFileAsync = promisify(require('child_process').execFile); +import {promises as fs} from 'fs'; +import {promisify} from 'util'; +import {execFile} from 'child_process'; -const log = require('lighthouse-logger'); +import log from 'lighthouse-logger'; -const assetSaver = require('../../../../lighthouse-core/lib/asset-saver.js'); -const LocalConsole = require('../lib/local-console.js'); -const ChildProcessError = require('../lib/child-process-error.js'); -const {LH_ROOT} = require('../../../../root.js'); +import assetSaver from '../../../../lighthouse-core/lib/asset-saver.js'; +import {LocalConsole} from '../lib/local-console.js'; +import {ChildProcessError} from '../lib/child-process-error.js'; +import {LH_ROOT} from '../../../../root.js'; + +const execFileAsync = promisify(execFile); /** * Launch Chrome and do a full Lighthouse run via the Lighthouse CLI. @@ -70,7 +72,7 @@ async function internalRun(url, tmpPath, configJson, options) { const artifactsDirectory = `${tmpPath}/artifacts/`; const args = [ - `${__dirname}/../../../index.js`, // 'lighthouse-cli/index.js' + `${LH_ROOT}/lighthouse-cli/index.js`, `${url}`, `--output-path=${outputPath}`, '--output=json', @@ -143,6 +145,6 @@ async function internalRun(url, tmpPath, configJson, options) { }; } -module.exports = { - runLighthouse, +export { + runLighthouse }; diff --git a/lighthouse-cli/test/smokehouse/package.json b/lighthouse-cli/test/smokehouse/package.json new file mode 100644 index 000000000000..bd346284783c --- /dev/null +++ b/lighthouse-cli/test/smokehouse/package.json @@ -0,0 +1,4 @@ +{ + "type": "module", + "//": "Any directory that uses `import ... from` or `export ...` must be type module. Temporary file until root package.json is type: module" +} \ No newline at end of file diff --git a/lighthouse-cli/test/smokehouse/report-assert.js b/lighthouse-cli/test/smokehouse/report-assert.js index 5ae15453fef7..cc07b5dc5047 100644 --- a/lighthouse-cli/test/smokehouse/report-assert.js +++ b/lighthouse-cli/test/smokehouse/report-assert.js @@ -10,16 +10,6 @@ * against the results actually collected from Lighthouse. */ -const cloneDeep = require('lodash.clonedeep'); -const log = require('lighthouse-logger'); -const LocalConsole = require('./lib/local-console.js'); - -const NUMBER_REGEXP = /(?:\d|\.)+/.source; -const OPS_REGEXP = /<=?|>=?|\+\/-|±/.source; -// An optional number, optional whitespace, an operator, optional whitespace, a number. -const NUMERICAL_EXPECTATION_REGEXP = - new RegExp(`^(${NUMBER_REGEXP})?\\s*(${OPS_REGEXP})\\s*(${NUMBER_REGEXP})$`); - /** * @typedef Difference * @property {string} path @@ -36,6 +26,17 @@ const NUMERICAL_EXPECTATION_REGEXP = * @property {Difference|null} [diff] */ +import cloneDeep from 'lodash.clonedeep'; +import log from 'lighthouse-logger'; + +import {LocalConsole} from './lib/local-console.js'; + +const NUMBER_REGEXP = /(?:\d|\.)+/.source; +const OPS_REGEXP = /<=?|>=?|\+\/-|±/.source; +// An optional number, optional whitespace, an operator, optional whitespace, a number. +const NUMERICAL_EXPECTATION_REGEXP = + new RegExp(`^(${NUMBER_REGEXP})?\\s*(${OPS_REGEXP})\\s*(${NUMBER_REGEXP})$`); + /** * Checks if the actual value matches the expectation. Does not recursively search. This supports * - Greater than/less than operators, e.g. "<100", ">90" @@ -370,7 +371,7 @@ function reportAssertion(localConsole, assertion) { * @param {{isDebug?: boolean, isBundled?: boolean}=} reportOptions * @return {{passed: number, failed: number, log: string}} */ -function report(actual, expected, reportOptions = {}) { +function getAssertionReport(actual, expected, reportOptions = {}) { const localConsole = new LocalConsole(); expected = pruneExpectations(localConsole, actual.lhr, expected, reportOptions); @@ -398,4 +399,4 @@ function report(actual, expected, reportOptions = {}) { }; } -module.exports = report; +export {getAssertionReport}; diff --git a/lighthouse-cli/test/smokehouse/smokehouse.js b/lighthouse-cli/test/smokehouse/smokehouse.js index 59657f5d9c1f..8f63bdb2850c 100644 --- a/lighthouse-cli/test/smokehouse/smokehouse.js +++ b/lighthouse-cli/test/smokehouse/smokehouse.js @@ -11,19 +11,9 @@ * smoke tests passed. */ -const log = require('lighthouse-logger'); -const cliLighthouseRunner = require('./lighthouse-runners/cli.js').runLighthouse; -const getAssertionReport = require('./report-assert.js'); -const LocalConsole = require('./lib/local-console.js'); -const ConcurrentMapper = require('./lib/concurrent-mapper.js'); - /* eslint-disable no-console */ -/** @typedef {import('./lib/child-process-error.js')} ChildProcessError */ - -// The number of concurrent (`!runSerially`) tests to run if `jobs` isn't set. -const DEFAULT_CONCURRENT_RUNS = 5; -const DEFAULT_RETRIES = 0; +/** @typedef {import('./lib/child-process-error.js').ChildProcessError} ChildProcessError */ /** * @typedef Run @@ -42,6 +32,17 @@ const DEFAULT_RETRIES = 0; * @property {Run[]} runs */ +import log from 'lighthouse-logger'; + +import {runLighthouse as cliLighthouseRunner} from './lighthouse-runners/cli.js'; +import {getAssertionReport} from './report-assert.js'; +import {LocalConsole} from './lib/local-console.js'; +import {ConcurrentMapper} from './lib/concurrent-mapper.js'; + +// The number of concurrent (`!runSerially`) tests to run if `jobs` isn't set. +const DEFAULT_CONCURRENT_RUNS = 5; +const DEFAULT_RETRIES = 0; + /** * Runs the selected smoke tests. Returns whether all assertions pass. * @param {Array} smokeTestDefns @@ -226,6 +227,6 @@ function getAssertionLog(count) { return `${count} assertion${plural}`; } -module.exports = { - runSmokehouse, +export { + runSmokehouse }; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/a11y/a11y-config.js b/lighthouse-cli/test/smokehouse/test-definitions/a11y/a11y-config.js index 0c69f4aded25..baad391f4012 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/a11y/a11y-config.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/a11y/a11y-config.js @@ -8,7 +8,9 @@ /** * Config file for running PWA smokehouse audits for axe. */ -module.exports = { + +/** @type {LH.Config.Json} */ +const config = { extends: 'lighthouse:default', settings: { onlyCategories: [ @@ -16,3 +18,5 @@ module.exports = { ], }, }; + +export default config; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/a11y/expectations.js b/lighthouse-cli/test/smokehouse/test-definitions/a11y/expectations.js index 160ecec9b54f..79b262aa0eed 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/a11y/expectations.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/a11y/expectations.js @@ -693,4 +693,4 @@ const expectations = { }, }; -module.exports = expectations; +export {expectations}; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/byte-efficiency/byte-config.js b/lighthouse-cli/test/smokehouse/test-definitions/byte-efficiency/byte-config.js index d1bf43bffc05..90a76903bf61 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/byte-efficiency/byte-config.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/byte-efficiency/byte-config.js @@ -43,4 +43,4 @@ const config = { ], }; -module.exports = config; +export default config; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/byte-efficiency/expectations.js b/lighthouse-cli/test/smokehouse/test-definitions/byte-efficiency/expectations.js index 9c7f6383862c..77ff7083f348 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/byte-efficiency/expectations.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/byte-efficiency/expectations.js @@ -322,7 +322,7 @@ const gzip = { }, }; -module.exports = { +export { efficiency, - gzip, + gzip }; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/core-tests.js b/lighthouse-cli/test/smokehouse/test-definitions/core-tests.js index 8cf6d1719402..acd5e5bc0c68 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/core-tests.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/core-tests.js @@ -5,161 +5,186 @@ */ 'use strict'; -const errors = require('./errors/error-expectations.js'); -const pwa = require('./pwa/pwa-expectations.js'); -const pwa2 = require('./pwa/pwa2-expectations.js'); -const redirects = require('./redirects/expectations.js'); -const seo = require('./seo/expectations.js'); -const offline = require('./offline-local/offline-expectations.js'); -const byte = require('./byte-efficiency/expectations.js'); -const perf = require('./perf/expectations.js'); -const diagnostics = require('./perf-diagnostics/expectations.js'); -const lantern = require('./lantern/lantern-expectations.js'); -const metrics = require('./tricky-metrics/expectations.js'); -const csp = require('./csp/csp-expectations.js'); +import * as a11y from './a11y/expectations.js'; +import * as byte from './byte-efficiency/expectations.js'; +import * as csp from './csp/csp-expectations.js'; +import * as dbw from './dobetterweb/dbw-expectations.js'; +import * as diagnostics from './perf-diagnostics/expectations.js'; +import * as errors from './errors/error-expectations.js'; +import * as lantern from './lantern/lantern-expectations.js'; +import * as legacyJavascript from './legacy-javascript/expectations.js'; +import * as metrics from './tricky-metrics/expectations.js'; +import * as mixedContent from './mixed-content/expectations.js'; +import * as offline from './offline-local/offline-expectations.js'; +import * as oopifg from './oopif/oopif-expectations.js'; +import * as perf from './perf/expectations.js'; +import * as pwa from './pwa/pwa-expectations.js'; +import * as pwa2 from './pwa/pwa2-expectations.js'; +import * as pwa3 from './pwa/pwa3-expectations.js'; +import * as redirects from './redirects/expectations.js'; +import * as screenshots from './screenshot/expectations.js'; +import * as seo from './seo/expectations.js'; +import * as sourcemaps from './source-maps/expectations.js'; +import a11yConfig from './a11y/a11y-config.js'; +import byteConfig from './byte-efficiency/byte-config.js'; +import cspConfig from './csp/csp-config.js'; +import dbwConfig from './dobetterweb/dbw-config.js'; +import errorConfig from './errors/error-config.js'; +import lanternConfig from './lantern/lantern-config.js'; +import legacyJavascriptConfig from './legacy-javascript/legacy-javascript-config.js'; +import noThrottlingConfig from './tricky-metrics/no-throttling-config.js'; +import offlineConfig from './offline-local/offline-config.js'; +import oopifConfig from './oopif/oopif-config.js'; +import perfConfig from './perf/perf-config.js'; +import perfDiagnosticsConfig from './perf-diagnostics/perf-diagnostics-config.js'; +import pwaConfig from './pwa/pwa-config.js'; +import redirectsConfig from './redirects/redirects-config.js'; +import screenshotConfig from './screenshot/screenshot-config.js'; +import seoConfig from './seo/seo-config.js'; +import sourcemapsConfig from './source-maps/source-maps-config.js'; /** @type {ReadonlyArray} */ const smokeTests = [{ id: 'a11y', - expectations: require('./a11y/expectations.js'), - config: require('./a11y/a11y-config.js'), + expectations: a11y.expectations, + config: a11yConfig, }, { id: 'errors-infinite-loop', expectations: errors.infiniteLoop, - config: require('./errors/error-config.js'), + config: errorConfig, runSerially: true, }, { id: 'errors-expired-ssl', expectations: errors.expiredSsl, - config: require('./errors/error-config.js'), + config: errorConfig, runSerially: true, }, { id: 'errors-iframe-expired-ssl', expectations: errors.iframeBadSsl, - config: require('./errors/error-config.js'), + config: errorConfig, runSerially: true, }, { id: 'oopif', - expectations: require('./oopif/oopif-expectations.js'), - config: require('./oopif/oopif-config.js'), + expectations: oopifg.expectations, + config: oopifConfig, }, { id: 'pwa-airhorner', expectations: pwa.airhorner, - config: require('./pwa/pwa-config.js'), + config: pwaConfig, }, { id: 'pwa-chromestatus', expectations: pwa.chromestatus, - config: require('./pwa/pwa-config.js'), + config: pwaConfig, }, { id: 'pwa-svgomg', expectations: pwa2.svgomg, - config: require('./pwa/pwa-config.js'), + config: pwaConfig, }, { id: 'pwa-caltrain', expectations: pwa2.caltrain, - config: require('./pwa/pwa-config.js'), + config: pwaConfig, }, { id: 'pwa-rocks', - expectations: require('./pwa/pwa3-expectations.js').pwarocks, - config: require('./pwa/pwa-config.js'), + expectations: pwa3.pwarocks, + config: pwaConfig, }, { id: 'dbw', - expectations: require('./dobetterweb/dbw-expectations.js'), - config: require('./dobetterweb/dbw-config.js'), + expectations: dbw.expectations, + config: dbwConfig, runSerially: true, // Need access to network request assertions. }, { id: 'issues-mixed-content', - expectations: require('./issues/mixed-content.js'), + expectations: mixedContent.expectations, }, { id: 'redirects-single-server', expectations: redirects.singleServer, - config: require('./redirects/redirects-config.js'), + config: redirectsConfig, }, { id: 'redirects-multiple-server', expectations: redirects.multipleServer, - config: require('./redirects/redirects-config.js'), + config: redirectsConfig, }, { id: 'redirects-client-paint-server', expectations: redirects.clientPaintServer, - config: require('./redirects/redirects-config.js'), + config: redirectsConfig, }, { id: 'redirects-single-client', expectations: redirects.singleClient, - config: require('./redirects/redirects-config.js'), + config: redirectsConfig, }, { id: 'redirects-history-push-state', expectations: redirects.historyPushState, - config: require('./redirects/redirects-config.js'), + config: redirectsConfig, }, { id: 'seo-passing', expectations: seo.passing, - config: require('./seo/seo-config.js'), + config: seoConfig, }, { id: 'seo-failing', expectations: seo.failing, - config: require('./seo/seo-config.js'), + config: seoConfig, }, { id: 'seo-status-403', expectations: seo.status403, - config: require('./seo/seo-config.js'), + config: seoConfig, }, { id: 'seo-tap-targets', expectations: seo.tapTargets, - config: require('./seo/seo-config.js'), + config: seoConfig, }, { id: 'offline-online-only', expectations: offline.onlineOnly, - config: require('./offline-local/offline-config.js'), + config: offlineConfig, runSerially: true, }, { id: 'offline-ready', expectations: offline.ready, - config: require('./offline-local/offline-config.js'), + config: offlineConfig, runSerially: true, }, { id: 'offline-sw-broken', expectations: offline.swBroken, - config: require('./offline-local/offline-config.js'), + config: offlineConfig, runSerially: true, }, { id: 'offline-sw-slow', expectations: offline.swSlow, - config: require('./offline-local/offline-config.js'), + config: offlineConfig, runSerially: true, }, { id: 'byte-efficiency', expectations: byte.efficiency, - config: require('./byte-efficiency/byte-config.js'), + config: byteConfig, runSerially: true, }, { id: 'byte-gzip', expectations: byte.gzip, - config: require('./byte-efficiency/byte-config.js'), + config: byteConfig, runSerially: true, }, { id: 'perf-preload', expectations: perf.preload, - config: require('./perf/perf-config.js'), + config: perfConfig, runSerially: true, }, { id: 'perf-budgets', expectations: perf.budgets, - config: require('./perf/perf-config.js'), + config: perfConfig, runSerially: true, }, { id: 'perf-fonts', expectations: perf.fonts, - config: require('./perf/perf-config.js'), + config: perfConfig, runSerially: true, }, { id: 'perf-trace-elements', expectations: perf.traceElements, - config: require('./perf/perf-config.js'), + config: perfConfig, runSerially: true, }, { id: 'perf-frame-metrics', expectations: perf.frameMetrics, - config: require('./perf/perf-config.js'), + config: perfConfig, runSerially: true, }, { id: 'perf-debug', @@ -171,67 +196,67 @@ const smokeTests = [{ }, { id: 'perf-diagnostics-animations', expectations: diagnostics.animations, - config: require('./perf-diagnostics/perf-diagnostics-config.js'), + config: perfDiagnosticsConfig, }, { id: 'perf-diagnostics-third-party', expectations: diagnostics.thirdParty, - config: require('./perf-diagnostics/perf-diagnostics-config.js'), + config: perfDiagnosticsConfig, }, { id: 'perf-diagnostics-unsized-images', expectations: diagnostics.unsizedImages, - config: require('./perf-diagnostics/perf-diagnostics-config.js'), + config: perfDiagnosticsConfig, }, { id: 'lantern-online', expectations: lantern.online, - config: require('./lantern/lantern-config.js'), + config: lanternConfig, }, { id: 'lantern-settimeout', expectations: lantern.setTimeout, - config: require('./lantern/lantern-config.js'), + config: lanternConfig, }, { id: 'lantern-fetch', expectations: lantern.fetch, - config: require('./lantern/lantern-config.js'), + config: lanternConfig, }, { id: 'lantern-xhr', expectations: lantern.xhr, - config: require('./lantern/lantern-config.js'), + config: lanternConfig, }, { id: 'lantern-idle-callback-short', expectations: lantern.idleCallbackShort, - config: require('./lantern/lantern-config.js'), + config: lanternConfig, }, { id: 'lantern-idle-callback-long', expectations: lantern.idleCallbackLong, - config: require('./lantern/lantern-config.js'), + config: lanternConfig, }, { id: 'metrics-tricky-tti', expectations: metrics.trickyTti, - config: require('./tricky-metrics/no-throttling-config.js'), + config: noThrottlingConfig, }, { id: 'metrics-tricky-tti-late-fcp', expectations: metrics.trickyTtiLateFcp, - config: require('./tricky-metrics/no-throttling-config.js'), + config: noThrottlingConfig, }, { id: 'metrics-delayed-lcp', expectations: metrics.delayedLcp, - config: require('./tricky-metrics/no-throttling-config.js'), + config: noThrottlingConfig, }, { id: 'metrics-delayed-fcp', expectations: metrics.delayedFcp, - config: require('./tricky-metrics/no-throttling-config.js'), + config: noThrottlingConfig, }, { id: 'metrics-debugger', expectations: metrics.debuggerStatement, - config: require('./tricky-metrics/no-throttling-config.js'), + config: noThrottlingConfig, }, { id: 'legacy-javascript', - expectations: require('./legacy-javascript/expectations.js'), - config: require('./legacy-javascript/legacy-javascript-config.js'), + expectations: legacyJavascript.expectations, + config: legacyJavascriptConfig, }, { id: 'source-maps', - expectations: require('./source-maps/expectations.js'), - config: require('./source-maps/source-maps-config.js'), + expectations: sourcemaps.expectations, + config: sourcemapsConfig, }, { // TODO: restore when --enable-features=AutofillShowTypePredictions is not needed. // id: 'forms', @@ -239,20 +264,21 @@ const smokeTests = [{ // config: require('./forms/form-config.js'), // }, { id: 'screenshot', - expectations: require('./screenshot/expectations.js'), - config: require('./screenshot/screenshot-config.js'), + expectations: screenshots.expectations, + config: screenshotConfig, }, { id: 'csp-allow-all', expectations: csp.allowAll, - config: require('./csp/csp-config.js'), + config: cspConfig, }, { id: 'csp-block-all-m91', expectations: csp.blockAllM91, - config: require('./csp/csp-config.js'), + config: cspConfig, }, { id: 'csp-block-all', expectations: csp.blockAll, - config: require('./csp/csp-config.js'), + config: cspConfig, }]; -module.exports = smokeTests; +// TODO: export as named objects? export {screenshot, pwa, pwa2, ...} +export default smokeTests; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/csp/csp-config.js b/lighthouse-cli/test/smokehouse/test-definitions/csp/csp-config.js index cf27a373aed5..6310cef1e658 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/csp/csp-config.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/csp/csp-config.js @@ -6,6 +6,8 @@ 'use strict'; /** @type {LH.Config.Json} */ -module.exports = { +const config = { extends: 'lighthouse:default', }; + +export default config; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/csp/csp-expectations.js b/lighthouse-cli/test/smokehouse/test-definitions/csp/csp-expectations.js index 912f47b49541..5a402298f7bb 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/csp/csp-expectations.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/csp/csp-expectations.js @@ -111,8 +111,8 @@ const blockAll = { }, }; -module.exports = { +export { allowAll, blockAllM91, - blockAll, + blockAll }; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/dobetterweb/dbw-config.js b/lighthouse-cli/test/smokehouse/test-definitions/dobetterweb/dbw-config.js index cf65b5b2318b..f2ecf012a4f2 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/dobetterweb/dbw-config.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/dobetterweb/dbw-config.js @@ -8,10 +8,14 @@ /** * Config file for running PWA smokehouse audits. */ -module.exports = { + +/** @type {LH.Config.Json} */ +const config = { extends: 'lighthouse:default', audits: [ // Test the `ignoredPatterns` audit option. {path: 'errors-in-console', options: {ignoredPatterns: ['An ignored error']}}, ], }; + +export default config; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/dobetterweb/dbw-expectations.js b/lighthouse-cli/test/smokehouse/test-definitions/dobetterweb/dbw-expectations.js index c20a62c23a95..39e785b6d105 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/dobetterweb/dbw-expectations.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/dobetterweb/dbw-expectations.js @@ -443,4 +443,4 @@ const expectations = { }, }; -module.exports = expectations; +export {expectations}; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/errors/error-config.js b/lighthouse-cli/test/smokehouse/test-definitions/errors/error-config.js index c76a5829f282..9e4fd463d6c3 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/errors/error-config.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/errors/error-config.js @@ -8,7 +8,9 @@ /** * Config file for sites with various errors, just fail out quickly. */ -module.exports = { + +/** @type {LH.Config.Json} */ +const config = { extends: 'lighthouse:default', settings: { maxWaitForLoad: 5000, @@ -17,3 +19,5 @@ module.exports = { ], }, }; + +export default config; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/errors/error-expectations.js b/lighthouse-cli/test/smokehouse/test-definitions/errors/error-expectations.js index b6d46758bc1f..af140cd26b32 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/errors/error-expectations.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/errors/error-expectations.js @@ -102,8 +102,8 @@ const iframeBadSsl = { }, }; -module.exports = { +export { infiniteLoop, expiredSsl, - iframeBadSsl, + iframeBadSsl }; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/forms/form-config.js b/lighthouse-cli/test/smokehouse/test-definitions/forms/form-config.js index 727fe300b7db..083c6ea17202 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/forms/form-config.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/forms/form-config.js @@ -5,7 +5,7 @@ */ 'use strict'; -const experimentalConfig = require('../../../../../lighthouse-core/config/experimental-config.js'); +import * as experimentalConfig from '../../../../../lighthouse-core/config/experimental-config.js'; /** * @type {LH.Config.Json} @@ -20,4 +20,4 @@ const config = { }, }; -module.exports = config; +export default config; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/forms/form-expectations.js b/lighthouse-cli/test/smokehouse/test-definitions/forms/form-expectations.js index fab69f24cbd1..627ea771ec39 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/forms/form-expectations.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/forms/form-expectations.js @@ -580,4 +580,4 @@ const expectations = { }, }; -module.exports = expectations; +export {expectations}; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/lantern/lantern-config.js b/lighthouse-cli/test/smokehouse/test-definitions/lantern/lantern-config.js index f8ccb461a8eb..d6cc8f6cf47f 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/lantern/lantern-config.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/lantern/lantern-config.js @@ -8,7 +8,9 @@ /** * Config file for running byte efficiency smokehouse audits. */ -module.exports = { + +/** @type {LH.Config.Json} */ +const config = { extends: 'lighthouse:default', settings: { onlyCategories: ['performance'], @@ -22,3 +24,5 @@ module.exports = { }, }, }; + +export default config; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/lantern/lantern-expectations.js b/lighthouse-cli/test/smokehouse/test-definitions/lantern/lantern-expectations.js index c19b90cf8540..018726222a56 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/lantern/lantern-expectations.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/lantern/lantern-expectations.js @@ -145,11 +145,11 @@ const idleCallbackLong = { }, }; -module.exports = { +export { online, setTimeout, fetch, xhr, idleCallbackShort, - idleCallbackLong, + idleCallbackLong }; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/legacy-javascript/expectations.js b/lighthouse-cli/test/smokehouse/test-definitions/legacy-javascript/expectations.js index 199abc652c6b..b8e350049372 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/legacy-javascript/expectations.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/legacy-javascript/expectations.js @@ -93,4 +93,4 @@ const expectations = { }, }; -module.exports = expectations; +export {expectations}; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/legacy-javascript/legacy-javascript-config.js b/lighthouse-cli/test/smokehouse/test-definitions/legacy-javascript/legacy-javascript-config.js index 21cb6cfb741b..33afcdaa3c09 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/legacy-javascript/legacy-javascript-config.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/legacy-javascript/legacy-javascript-config.js @@ -8,7 +8,9 @@ /** * Config file for running PWA smokehouse audits. */ -module.exports = { + +/** @type {LH.Config.Json} */ +const config = { extends: 'lighthouse:default', settings: { onlyCategories: [ @@ -19,3 +21,5 @@ module.exports = { ], }, }; + +export default config; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/mixed-content/expectations.js b/lighthouse-cli/test/smokehouse/test-definitions/mixed-content/expectations.js new file mode 100644 index 000000000000..5a246c8945d5 --- /dev/null +++ b/lighthouse-cli/test/smokehouse/test-definitions/mixed-content/expectations.js @@ -0,0 +1,40 @@ +/** + * @license Copyright 2021 The Lighthouse Authors. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + */ +'use strict'; + +/** + * @type {Smokehouse.ExpectedRunnerResult} + * Expected Lighthouse results a site with mixed-content issues. + */ +const expectations = { + artifacts: { + InspectorIssues: { + mixedContent: [ + { + _minChromiumMilestone: 88, // We went from Warning to AutoUpgrade in https://chromium-review.googlesource.com/c/chromium/src/+/2480817 + resourceType: 'Image', + resolutionStatus: 'MixedContentAutomaticallyUpgraded', + insecureURL: 'http://www.mixedcontentexamples.com/Content/Test/steveholt.jpg', + mainResourceURL: 'https://www.mixedcontentexamples.com/Test/NonSecureImage', + request: { + url: 'http://www.mixedcontentexamples.com/Content/Test/steveholt.jpg', + }, + }, + ], + }, + }, + lhr: { + requestedUrl: 'https://www.mixedcontentexamples.com/Test/NonSecureImage', + finalUrl: 'https://www.mixedcontentexamples.com/Test/NonSecureImage', + audits: { + 'is-on-https': { + score: 0, + }, + }, + }, +}; + +export {expectations}; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/offline-local/offline-config.js b/lighthouse-cli/test/smokehouse/test-definitions/offline-local/offline-config.js index f55e828c873c..869188cd2f21 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/offline-local/offline-config.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/offline-local/offline-config.js @@ -8,7 +8,9 @@ /** * Config file for running PWA smokehouse audits. */ -module.exports = { + +/** @type {LH.Config.Json} */ +const config = { extends: 'lighthouse:default', settings: { onlyCategories: [ @@ -35,3 +37,5 @@ module.exports = { ], }, }; + +export default config; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/offline-local/offline-expectations.js b/lighthouse-cli/test/smokehouse/test-definitions/offline-local/offline-expectations.js index bb20430a4588..8fff662d3749 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/offline-local/offline-expectations.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/offline-local/offline-expectations.js @@ -232,9 +232,9 @@ const swSlow = { }, }; -module.exports = { +export { onlineOnly, ready, swBroken, - swSlow, + swSlow }; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/oopif/oopif-config.js b/lighthouse-cli/test/smokehouse/test-definitions/oopif/oopif-config.js index bc7ef0a3e367..4b6955476d63 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/oopif/oopif-config.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/oopif/oopif-config.js @@ -5,11 +5,8 @@ */ 'use strict'; -/** - * @type {LH.Config.Json} - * Config file for running the OOPIF tests - */ -module.exports = { +/** @type {LH.Config.Json} */ +const config = { extends: 'lighthouse:default', categories: { performance: { @@ -36,3 +33,5 @@ module.exports = { }, ], }; + +export default config; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/oopif/oopif-expectations.js b/lighthouse-cli/test/smokehouse/test-definitions/oopif/oopif-expectations.js index a31e1fe25d88..96df2d2ea649 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/oopif/oopif-expectations.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/oopif/oopif-expectations.js @@ -9,7 +9,7 @@ * @type {Smokehouse.ExpectedRunnerResult} * Expected Lighthouse audit values for sites with OOPIFS. */ -module.exports = { +const expectations = { lhr: { requestedUrl: 'http://localhost:10200/oopif.html', finalUrl: 'http://localhost:10200/oopif.html', @@ -50,3 +50,5 @@ module.exports = { ], }, }; + +export {expectations}; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/perf-diagnostics/expectations.js b/lighthouse-cli/test/smokehouse/test-definitions/perf-diagnostics/expectations.js index f384d9ffb9dc..43d9b3d7f000 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/perf-diagnostics/expectations.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/perf-diagnostics/expectations.js @@ -138,8 +138,8 @@ const unsizedImages = { }, }; -module.exports = { +export { animations, thirdParty, - unsizedImages, + unsizedImages }; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/perf-diagnostics/perf-diagnostics-config.js b/lighthouse-cli/test/smokehouse/test-definitions/perf-diagnostics/perf-diagnostics-config.js index f72873b8e127..469232ac170f 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/perf-diagnostics/perf-diagnostics-config.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/perf-diagnostics/perf-diagnostics-config.js @@ -6,9 +6,11 @@ 'use strict'; /** @type {LH.Config.Json} */ -module.exports = { +const config = { extends: 'lighthouse:default', settings: { onlyCategories: ['performance'], }, }; + +export default config; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/perf/expectations.js b/lighthouse-cli/test/smokehouse/test-definitions/perf/expectations.js index 7d6857db3c42..75537c6332a0 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/perf/expectations.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/perf/expectations.js @@ -383,11 +383,11 @@ const debug = { }, }; -module.exports = { +export { preload, budgets, fonts, debug, traceElements, - frameMetrics, + frameMetrics }; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/perf/perf-config.js b/lighthouse-cli/test/smokehouse/test-definitions/perf/perf-config.js index 65da9e2db242..554de31c9aa5 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/perf/perf-config.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/perf/perf-config.js @@ -6,7 +6,7 @@ 'use strict'; /** @type {LH.Config.Json} */ -const perfConfig = { +const config = { extends: 'lighthouse:default', settings: { throttlingMethod: 'devtools', @@ -49,4 +49,4 @@ const perfConfig = { }, }; -module.exports = perfConfig; +export default config; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/pwa/pwa-config.js b/lighthouse-cli/test/smokehouse/test-definitions/pwa/pwa-config.js index 92ee9cfcbb19..43f66a7f24ce 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/pwa/pwa-config.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/pwa/pwa-config.js @@ -8,9 +8,13 @@ /** * Config file for running PWA smokehouse audits. */ -module.exports = { + +/** @type {LH.Config.Json} */ +const config = { extends: 'lighthouse:default', settings: { onlyCategories: ['pwa'], }, }; + +export default config; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/pwa/pwa-expectations-details.js b/lighthouse-cli/test/smokehouse/test-definitions/pwa/pwa-expectations-details.js index e435f2aead16..3526e7112f0e 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/pwa/pwa-expectations-details.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/pwa/pwa-expectations-details.js @@ -5,7 +5,7 @@ */ 'use strict'; -module.exports = { +export default { isParseFailure: false, hasStartUrl: true, hasIconsAtLeast144px: true, diff --git a/lighthouse-cli/test/smokehouse/test-definitions/pwa/pwa-expectations.js b/lighthouse-cli/test/smokehouse/test-definitions/pwa/pwa-expectations.js index 3b67ee48a9b4..81bc18ecb823 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/pwa/pwa-expectations.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/pwa/pwa-expectations.js @@ -7,7 +7,7 @@ /** @fileoverview Expected Lighthouse audit values for various sites with stable(ish) PWA results. */ -const pwaDetailsExpectations = require('./pwa-expectations-details.js'); +import pwaDetailsExpectations from './pwa-expectations-details.js'; /** * @type {Smokehouse.ExpectedRunnerResult} @@ -115,7 +115,7 @@ const chromestatus = { }, }; -module.exports = { +export { airhorner, - chromestatus, + chromestatus }; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/pwa/pwa2-expectations.js b/lighthouse-cli/test/smokehouse/test-definitions/pwa/pwa2-expectations.js index c088b5fe3f1c..0c4f6431ee4d 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/pwa/pwa2-expectations.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/pwa/pwa2-expectations.js @@ -7,7 +7,8 @@ /** @fileoverview Expected Lighthouse audit values for various sites with stable(ish) PWA results. */ -const pwaDetailsExpectations = require('./pwa-expectations-details.js'); +import pwaDetailsExpectations from './pwa-expectations-details.js'; + const jakeExpectations = {...pwaDetailsExpectations, hasShortName: false}; /** @@ -120,7 +121,7 @@ const caltrain = { }, }; -module.exports = { +export { svgomg, - caltrain, + caltrain }; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/pwa/pwa3-expectations.js b/lighthouse-cli/test/smokehouse/test-definitions/pwa/pwa3-expectations.js index 0b3ce6481973..a48e44d5abd3 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/pwa/pwa3-expectations.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/pwa/pwa3-expectations.js @@ -7,7 +7,8 @@ /** @fileoverview Expected Lighthouse audit values for various sites with stable(ish) PWA results. */ -const pwaDetailsExpectations = require('./pwa-expectations-details.js'); +import pwaDetailsExpectations from './pwa-expectations-details.js'; + const pwaRocksExpectations = {...pwaDetailsExpectations, hasIconsAtLeast512px: false}; /** @@ -66,6 +67,6 @@ const pwarocks = { }, }; -module.exports = { - pwarocks, +export { + pwarocks }; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/redirects/expectations.js b/lighthouse-cli/test/smokehouse/test-definitions/redirects/expectations.js index 92f4b81873e6..91cd6f71830b 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/redirects/expectations.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/redirects/expectations.js @@ -146,10 +146,10 @@ const historyPushState = { }, }; -module.exports = { +export { singleServer, multipleServer, clientPaintServer, singleClient, - historyPushState, + historyPushState }; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/redirects/redirects-config.js b/lighthouse-cli/test/smokehouse/test-definitions/redirects/redirects-config.js index cb2370efd92b..ed3de923dcef 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/redirects/redirects-config.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/redirects/redirects-config.js @@ -8,7 +8,9 @@ /** * Config file for running PWA smokehouse audits. */ -module.exports = { + +/** @type {LH.Config.Json} */ +const config = { extends: 'lighthouse:default', settings: { onlyAudits: [ @@ -21,3 +23,5 @@ module.exports = { throttlingMethod: /** @type {'provided'} */ ('provided'), }, }; + +export default config; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/screenshot/expectations.js b/lighthouse-cli/test/smokehouse/test-definitions/screenshot/expectations.js index d7cace633d46..70e8b4770127 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/screenshot/expectations.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/screenshot/expectations.js @@ -59,4 +59,4 @@ const expectations = { }, }; -module.exports = expectations; +export {expectations}; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/screenshot/screenshot-config.js b/lighthouse-cli/test/smokehouse/test-definitions/screenshot/screenshot-config.js index c90cc351fcb0..8e2a9325ff8e 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/screenshot/screenshot-config.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/screenshot/screenshot-config.js @@ -6,7 +6,7 @@ 'use strict'; /** @type {LH.Config.Json} */ -module.exports = { +const config = { extends: 'lighthouse:default', settings: { formFactor: 'desktop', @@ -19,3 +19,5 @@ module.exports = { }, }, }; + +export default config; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/seo/expectations.js b/lighthouse-cli/test/smokehouse/test-definitions/seo/expectations.js index 101764914fe2..fc434b1a203f 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/seo/expectations.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/seo/expectations.js @@ -479,9 +479,9 @@ const tapTargets = { }, }; -module.exports = { +export { passing, failing, status403, - tapTargets, + tapTargets }; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/seo/seo-config.js b/lighthouse-cli/test/smokehouse/test-definitions/seo/seo-config.js index 8278d6f6ff40..7d34b319946b 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/seo/seo-config.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/seo/seo-config.js @@ -8,9 +8,13 @@ /** * Config file for running SEO smokehouse audits. */ -module.exports = { + +/** @type {LH.Config.Json} */ +const config = { extends: 'lighthouse:default', settings: { onlyCategories: ['seo'], }, }; + +export default config; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/source-maps/expectations.js b/lighthouse-cli/test/smokehouse/test-definitions/source-maps/expectations.js index 948e528ed267..48d53434d565 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/source-maps/expectations.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/source-maps/expectations.js @@ -5,10 +5,11 @@ */ 'use strict'; -const fs = require('fs'); +import fs from 'fs'; +import {LH_ROOT} from '../../../../../root.js'; const mapJson = - fs.readFileSync(`${__dirname}/../../../fixtures/source-map/script.js.map`, 'utf-8'); + fs.readFileSync(`${LH_ROOT}/lighthouse-cli/test/fixtures/source-map/script.js.map`, 'utf-8'); const map = JSON.parse(mapJson); /** @@ -40,4 +41,4 @@ const expectations = { }, }; -module.exports = expectations; +export {expectations}; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/source-maps/source-maps-config.js b/lighthouse-cli/test/smokehouse/test-definitions/source-maps/source-maps-config.js index a757ad7abffb..711d198f0870 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/source-maps/source-maps-config.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/source-maps/source-maps-config.js @@ -10,9 +10,11 @@ */ /** @type {LH.Config.Json} */ -module.exports = { +const config = { extends: 'lighthouse:default', settings: { onlyAudits: ['unused-javascript'], }, }; + +export default config; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/tricky-metrics/expectations.js b/lighthouse-cli/test/smokehouse/test-definitions/tricky-metrics/expectations.js index d0fa4ad1e329..0ce547057c8b 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/tricky-metrics/expectations.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/tricky-metrics/expectations.js @@ -92,10 +92,10 @@ const debuggerStatement = { }, }; -module.exports = { +export { trickyTti, trickyTtiLateFcp, delayedLcp, delayedFcp, - debuggerStatement, + debuggerStatement }; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/tricky-metrics/no-throttling-config.js b/lighthouse-cli/test/smokehouse/test-definitions/tricky-metrics/no-throttling-config.js index db5c291938e6..0d3b15c43906 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/tricky-metrics/no-throttling-config.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/tricky-metrics/no-throttling-config.js @@ -20,4 +20,4 @@ const noThrottlingConfig = { }, }; -module.exports = noThrottlingConfig; +export default noThrottlingConfig; diff --git a/package.json b/package.json index 7ef410008b1e..a6368c5a67c1 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "build-extension-firefox": "node ./build/build-extension.js firefox", "build-devtools": "yarn reset-link && node ./build/build-bundle.js clients/devtools-entry.js dist/lighthouse-dt-bundle.js && node ./build/build-dt-report-resources.js", "build-smokehouse-bundle": "node ./build/build-smokehouse-bundle.js", - "build-lr": "yarn reset-link && node ./build/build-lightrider-bundles.js", + "build-lr": "yarn reset-link && node ./build/build-lightrider-bundles.js && rollup lighthouse-cli/test/fixtures/static-server.js -o dist/lightrider/static-server.js -p commonjs -p node-resolve -e mime-db,glob", "build-pack": "bash build/build-pack.sh", "build-report": "node build/build-report-components.js && yarn eslint --fix report/renderer/components.js && node build/build-report.js", "build-sample-reports": "yarn build-report && node build/build-sample-reports.js", @@ -140,6 +140,7 @@ "cross-env": "^7.0.2", "csv-validator": "^0.0.3", "devtools-protocol": "0.0.901419", + "es-main": "^1.0.2", "eslint": "^7.23.0", "eslint-config-google": "^0.9.1", "eslint-plugin-import": "^2.24.2", @@ -150,7 +151,7 @@ "glob": "^7.1.3", "idb-keyval": "2.2.0", "intl-messageformat-parser": "^1.8.1", - "jest": "^27.0.3", + "jest": "27.0.3", "jsdom": "^12.2.0", "jsonld": "^5.2.0", "jsonlint-mod": "^1.7.6", @@ -165,6 +166,8 @@ "puppeteer": "^10.2.0", "rollup": "^2.50.6", "rollup-plugin-commonjs": "^10.1.0", + "rollup-plugin-node-resolve": "^5.2.0", + "rollup-plugin-shim": "^1.0.0", "rollup-plugin-terser": "^7.0.2", "tabulator-tables": "^4.9.3", "terser": "^5.3.8", diff --git a/yarn.lock b/yarn.lock index 4e5d98a3074c..df3fca317c29 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1198,6 +1198,13 @@ resolved "https://registry.yarnpkg.com/@types/resize-observer-browser/-/resize-observer-browser-0.1.1.tgz#9b7cdae9cdc8b1a7020ca7588018dac64c770866" integrity sha512-5/bJS/uGB5kmpRrrAWXQnmyKlv+4TlPn4f+A2NBa93p+mt6Ht+YcNGkQKf8HMx28a9hox49ZXShtbGqZkk41Sw== +"@types/resolve@0.0.8": + version "0.0.8" + resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-0.0.8.tgz#f26074d238e02659e323ce1a13d041eee280e194" + integrity sha512-auApPaJf3NPfe18hSoJkp8EbZzer2ISk7o8mCC3M9he/a04+gbMF97NkpD2S8riMGvm4BMRI59/SZQSaLTKpsQ== + dependencies: + "@types/node" "*" + "@types/resolve@1.17.1": version "1.17.1" resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-1.17.1.tgz#3afd6ad8967c77e4376c598a82ddd58f46ec45d6" @@ -3356,6 +3363,11 @@ es-abstract@^1.18.2: string.prototype.trimstart "^1.0.4" unbox-primitive "^1.0.1" +es-main@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/es-main/-/es-main-1.0.2.tgz#c9030d78796f609f865b66f4125a78d77fec3de3" + integrity sha512-LLgW8Cby/FiyQygrI23q2EswulHiDKoyjWlDRgTGXjQ3iRim2R26VfoehpxI5oKRXSNams3L/80KtggoUdxdDQ== + es-to-primitive@^1.2.1: version "1.2.1" resolved "https://registry.yarnpkg.com/es-to-primitive/-/es-to-primitive-1.2.1.tgz#e55cd4c9cdc188bcefb03b366c736323fc5c898a" @@ -5531,7 +5543,7 @@ jest-worker@^27.0.2: merge-stream "^2.0.0" supports-color "^8.0.0" -jest@^27.0.3: +jest@27.0.3: version "27.0.3" resolved "https://registry.yarnpkg.com/jest/-/jest-27.0.3.tgz#0b4ac738c93612f778d58250aee026220487e5a4" integrity sha512-0G9+QqXFIZWgf5rs3yllpaA+13ZawVHfyuhuCV1EnoFbX++rVMRrYWCAnk+dfhwyv9/VTQvn+XG969u8aPRsBg== @@ -7385,7 +7397,7 @@ resolve-url@^0.2.1: resolved "https://registry.yarnpkg.com/resolve-url/-/resolve-url-0.2.1.tgz#2c637fe77c893afd2a663fe21aa9080068e2052a" integrity sha1-LGN/53yJOv0qZj/iGqkIAGjiBSo= -resolve@^1.1.4, resolve@^1.1.5, resolve@^1.10.0, resolve@^1.11.0, resolve@^1.13.1, resolve@^1.17.0, resolve@^1.19.0, resolve@^1.20.0, resolve@^1.4.0: +resolve@^1.1.4, resolve@^1.1.5, resolve@^1.10.0, resolve@^1.11.0, resolve@^1.11.1, resolve@^1.13.1, resolve@^1.17.0, resolve@^1.19.0, resolve@^1.20.0, resolve@^1.4.0: version "1.20.0" resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.20.0.tgz#629a013fb3f70755d6f0b7935cc1c2c5378b1975" integrity sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A== @@ -7448,6 +7460,22 @@ rollup-plugin-commonjs@^10.1.0: resolve "^1.11.0" rollup-pluginutils "^2.8.1" +rollup-plugin-node-resolve@^5.2.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/rollup-plugin-node-resolve/-/rollup-plugin-node-resolve-5.2.0.tgz#730f93d10ed202473b1fb54a5997a7db8c6d8523" + integrity sha512-jUlyaDXts7TW2CqQ4GaO5VJ4PwwaV8VUGA7+km3n6k6xtOEacf61u0VXwN80phY/evMcaS+9eIeJ9MOyDxt5Zw== + dependencies: + "@types/resolve" "0.0.8" + builtin-modules "^3.1.0" + is-module "^1.0.0" + resolve "^1.11.1" + rollup-pluginutils "^2.8.1" + +rollup-plugin-shim@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/rollup-plugin-shim/-/rollup-plugin-shim-1.0.0.tgz#b00f5cb44cdae81358c5342fe82fa71a1602b56b" + integrity sha512-rZqFD43y4U9nSqVq3iyWBiDwmBQJY8Txi04yI9jTKD3xcl7CbFjh1qRpQshUB3sONLubDzm7vJiwB+1MEGv67w== + rollup-plugin-terser@^7.0.2: version "7.0.2" resolved "https://registry.yarnpkg.com/rollup-plugin-terser/-/rollup-plugin-terser-7.0.2.tgz#e8fbba4869981b2dc35ae7e8a502d5c6c04d324d" From 58bea1587ed7a0e5eef71a2e3df10f68c3e64567 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Fri, 10 Sep 2021 16:04:13 -0700 Subject: [PATCH 02/11] fix --- lighthouse-core/test/fraggle-rock/api-test-pptr.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lighthouse-core/test/fraggle-rock/api-test-pptr.js b/lighthouse-core/test/fraggle-rock/api-test-pptr.js index a92ca7edf26e..38d3bc0604d2 100644 --- a/lighthouse-core/test/fraggle-rock/api-test-pptr.js +++ b/lighthouse-core/test/fraggle-rock/api-test-pptr.js @@ -10,7 +10,6 @@ const path = require('path'); const lighthouse = require('../../fraggle-rock/api.js'); const puppeteer = require('puppeteer'); -const StaticServer = require('../../../lighthouse-cli/test/fixtures/static-server.js').Server; jest.setTimeout(90_000); @@ -53,7 +52,7 @@ function getAuditsBreakdown(lhr) { } describe('Fraggle Rock API', () => { - /** @type {InstanceType} */ + /** @type {InstanceType} */ let server; /** @type {import('puppeteer').Browser} */ let browser; @@ -63,7 +62,10 @@ describe('Fraggle Rock API', () => { let serverBaseUrl; beforeAll(async () => { - server = new StaticServer(); + // TODO(esmodules): use normal import when present file is esm. + const {Server} = await import('../../../lighthouse-cli/test/fixtures/static-server.js'); + + server = new Server(); await server.listen(0, '127.0.0.1'); serverBaseUrl = `http://localhost:${server.getPort()}`; browser = await puppeteer.launch({ From f4dd5bc99d00c28c5bfe459728cb6d92b5b9fc96 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Fri, 10 Sep 2021 16:08:58 -0700 Subject: [PATCH 03/11] interop for days --- tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/tsconfig.json b/tsconfig.json index dd5ac335450b..b2c926eb8be2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,6 +15,7 @@ "diagnostics": true, "composite": true, "outDir": ".tmp/tsbuildinfo/", + "esModuleInterop": true, }, "include": [ "root.js", From 84b23eb1bbc1d00d8431bf9c5f422e9d6c265440 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Fri, 10 Sep 2021 16:49:16 -0700 Subject: [PATCH 04/11] fixcrash --- .../test/fraggle-rock/api-test-pptr.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lighthouse-core/test/fraggle-rock/api-test-pptr.js b/lighthouse-core/test/fraggle-rock/api-test-pptr.js index 38d3bc0604d2..80f199e0118e 100644 --- a/lighthouse-core/test/fraggle-rock/api-test-pptr.js +++ b/lighthouse-core/test/fraggle-rock/api-test-pptr.js @@ -7,9 +7,17 @@ /* eslint-env jest */ -const path = require('path'); -const lighthouse = require('../../fraggle-rock/api.js'); -const puppeteer = require('puppeteer'); +// TODO(esmodules): Node 14, 16 crash with `--experimental-vm-modules` if require and import +// are used in the same test file. +// See https://github.com/GoogleChrome/lighthouse/pull/12702#issuecomment-876832620 +// Use normal import when present file is esm. + +/** @type {import('path')} */ +let path; +/** @type {import('../../fraggle-rock/api.js')} */ +let lighthouse; +/** @type {import('puppeteer')} */ +let puppeteer; jest.setTimeout(90_000); @@ -64,6 +72,9 @@ describe('Fraggle Rock API', () => { beforeAll(async () => { // TODO(esmodules): use normal import when present file is esm. const {Server} = await import('../../../lighthouse-cli/test/fixtures/static-server.js'); + path = await import('path'); + lighthouse = await import('../../fraggle-rock/api.js'); + puppeteer = (await import('puppeteer')).default; server = new Server(); await server.listen(0, '127.0.0.1'); From 162e46c90e57a701e3bb3e6c6291e11311b2d999 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Fri, 10 Sep 2021 17:10:50 -0700 Subject: [PATCH 05/11] fix windows --- lighthouse-cli/test/smokehouse/frontends/smokehouse-bin.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lighthouse-cli/test/smokehouse/frontends/smokehouse-bin.js b/lighthouse-cli/test/smokehouse/frontends/smokehouse-bin.js index 025c26c2b2ba..9ba77c274d85 100644 --- a/lighthouse-cli/test/smokehouse/frontends/smokehouse-bin.js +++ b/lighthouse-cli/test/smokehouse/frontends/smokehouse-bin.js @@ -15,6 +15,7 @@ import path from 'path'; import fs from 'fs'; +import url from 'url'; import cloneDeep from 'lodash.clonedeep'; import yargs from 'yargs'; @@ -184,7 +185,7 @@ async function begin() { let testDefnPath = argv.testsPath || coreTestDefnsPath; testDefnPath = path.resolve(process.cwd(), testDefnPath); const requestedTestIds = argv._; - let rawTestDefns = await import(testDefnPath); + let rawTestDefns = await import(url.pathToFileURL(testDefnPath).href); if (rawTestDefns) { // Support commonjs. rawTestDefns = rawTestDefns.default || rawTestDefns; From 6b40515f071256ba30b6e087002d60fa065e5359 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Mon, 13 Sep 2021 11:52:17 -0700 Subject: [PATCH 06/11] pr --- lighthouse-cli/test/fixtures/static-server.js | 43 ++++++++++--------- .../smokehouse/frontends/smokehouse-bin.js | 7 +-- .../test/smokehouse/report-assert.js | 10 ++--- .../smokehouse/test-definitions/core-tests.js | 9 ++-- .../test-definitions/forms/form-config.js | 2 +- .../mixed-content-expectations.js} | 0 .../test-definitions/issues/mixed-content.js | 42 ------------------ package.json | 5 +-- yarn.lock | 2 +- 9 files changed, 38 insertions(+), 82 deletions(-) rename lighthouse-cli/test/smokehouse/test-definitions/{mixed-content/expectations.js => issues/mixed-content-expectations.js} (100%) delete mode 100644 lighthouse-cli/test/smokehouse/test-definitions/issues/mixed-content.js diff --git a/lighthouse-cli/test/fixtures/static-server.js b/lighthouse-cli/test/fixtures/static-server.js index 6fe09eaa6ab0..cfef8861890c 100644 --- a/lighthouse-cli/test/fixtures/static-server.js +++ b/lighthouse-cli/test/fixtures/static-server.js @@ -8,21 +8,24 @@ /* eslint-disable no-console */ -const http = require('http'); -const zlib = require('zlib'); -const path = require('path'); -const fs = require('fs'); -const glob = require('glob'); -const mime = require('mime-types'); -const parseQueryString = require('querystring').parse; -const parseURL = require('url').parse; -const URLSearchParams = require('url').URLSearchParams; -const {LH_ROOT} = require('../../../root.js'); +import http from 'http'; +import zlib from 'zlib'; +import path from 'path'; +import fs from 'fs'; +import {parse as parseQueryString} from 'querystring'; +import {parse as parseURL} from 'url'; +import {URLSearchParams} from 'url'; + +import mime from 'mime-types'; +import glob from 'glob'; +import esMain from 'es-main'; + +import {LH_ROOT} from '../../../root.js'; const HEADER_SAFELIST = new Set(['x-robots-tag', 'link', 'content-security-policy']); class Server { - baseDir = __dirname; + baseDir = `${LH_ROOT}/lighthouse-cli/test/fixtures`; constructor() { this._server = http.createServer(this._requestHandler.bind(this)); @@ -172,7 +175,7 @@ class Server { // Create an index page that lists the available test pages. if (filePath === '/') { - const fixturePaths = glob.sync('**/*.html', {cwd: __dirname}); + const fixturePaths = glob.sync('**/*.html', {cwd: this.baseDir}); const html = `

Smoke test fixtures

@@ -187,7 +190,7 @@ class Server { if (filePath.startsWith('/dist/gh-pages')) { // Rewrite lighthouse-viewer paths to point to that location. - absoluteFilePath = path.join(__dirname, '/../../../', filePath); + absoluteFilePath = path.join(this.baseDir, '/../../../', filePath); } // Disallow file requests outside of LH folder @@ -244,7 +247,7 @@ serverForOnline._server.on('error', e => console.error(e.code, e)); serverForOffline._server.on('error', e => console.error(e.code, e)); // If called via `node static-server.js` then start listening, otherwise, just expose the servers -if (require.main === module) { +if (esMain(import.meta)) { // Start listening const onlinePort = 10200; const offlinePort = 10503; @@ -252,10 +255,10 @@ if (require.main === module) { serverForOffline.listen(offlinePort, 'localhost'); console.log(`online: listening on http://localhost:${onlinePort}`); console.log(`offline: listening on http://localhost:${offlinePort}`); -} else { - module.exports = { - Server, - server: serverForOnline, - serverForOffline, - }; } + +export { + Server, + serverForOnline as server, + serverForOffline +}; diff --git a/lighthouse-cli/test/smokehouse/frontends/smokehouse-bin.js b/lighthouse-cli/test/smokehouse/frontends/smokehouse-bin.js index 9ba77c274d85..a0f3a50e530c 100644 --- a/lighthouse-cli/test/smokehouse/frontends/smokehouse-bin.js +++ b/lighthouse-cli/test/smokehouse/frontends/smokehouse-bin.js @@ -19,7 +19,6 @@ import url from 'url'; import cloneDeep from 'lodash.clonedeep'; import yargs from 'yargs'; -// @ts-expect-error: TODO: no types until @types/yargs 16 ... should upgrade yargs first. import * as yargsHelpers from 'yargs/helpers'; import log from 'lighthouse-logger'; @@ -185,11 +184,7 @@ async function begin() { let testDefnPath = argv.testsPath || coreTestDefnsPath; testDefnPath = path.resolve(process.cwd(), testDefnPath); const requestedTestIds = argv._; - let rawTestDefns = await import(url.pathToFileURL(testDefnPath).href); - if (rawTestDefns) { - // Support commonjs. - rawTestDefns = rawTestDefns.default || rawTestDefns; - } + const {default: rawTestDefns} = await import(url.pathToFileURL(testDefnPath).href); const allTestDefns = updateTestDefnFormat(rawTestDefns); const invertMatch = argv.invertMatch; const testDefns = getDefinitionsToRun(allTestDefns, requestedTestIds, {invertMatch}); diff --git a/lighthouse-cli/test/smokehouse/report-assert.js b/lighthouse-cli/test/smokehouse/report-assert.js index cc07b5dc5047..0cb845cfe401 100644 --- a/lighthouse-cli/test/smokehouse/report-assert.js +++ b/lighthouse-cli/test/smokehouse/report-assert.js @@ -10,6 +10,11 @@ * against the results actually collected from Lighthouse. */ +import cloneDeep from 'lodash.clonedeep'; +import log from 'lighthouse-logger'; + +import {LocalConsole} from './lib/local-console.js'; + /** * @typedef Difference * @property {string} path @@ -26,11 +31,6 @@ * @property {Difference|null} [diff] */ -import cloneDeep from 'lodash.clonedeep'; -import log from 'lighthouse-logger'; - -import {LocalConsole} from './lib/local-console.js'; - const NUMBER_REGEXP = /(?:\d|\.)+/.source; const OPS_REGEXP = /<=?|>=?|\+\/-|±/.source; // An optional number, optional whitespace, an operator, optional whitespace, a number. diff --git a/lighthouse-cli/test/smokehouse/test-definitions/core-tests.js b/lighthouse-cli/test/smokehouse/test-definitions/core-tests.js index acd5e5bc0c68..2e8cb3d17088 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/core-tests.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/core-tests.js @@ -11,10 +11,11 @@ import * as csp from './csp/csp-expectations.js'; import * as dbw from './dobetterweb/dbw-expectations.js'; import * as diagnostics from './perf-diagnostics/expectations.js'; import * as errors from './errors/error-expectations.js'; +// import * as forms from './forms/form-expectations.js'; import * as lantern from './lantern/lantern-expectations.js'; import * as legacyJavascript from './legacy-javascript/expectations.js'; import * as metrics from './tricky-metrics/expectations.js'; -import * as mixedContent from './mixed-content/expectations.js'; +import * as mixedContent from './issues/mixed-content-expectations.js'; import * as offline from './offline-local/offline-expectations.js'; import * as oopifg from './oopif/oopif-expectations.js'; import * as perf from './perf/expectations.js'; @@ -30,6 +31,7 @@ import byteConfig from './byte-efficiency/byte-config.js'; import cspConfig from './csp/csp-config.js'; import dbwConfig from './dobetterweb/dbw-config.js'; import errorConfig from './errors/error-config.js'; +// import formConfig from './forms/form-config.js'; import lanternConfig from './lantern/lantern-config.js'; import legacyJavascriptConfig from './legacy-javascript/legacy-javascript-config.js'; import noThrottlingConfig from './tricky-metrics/no-throttling-config.js'; @@ -260,8 +262,8 @@ const smokeTests = [{ }, { // TODO: restore when --enable-features=AutofillShowTypePredictions is not needed. // id: 'forms', -// expectations: require('./forms/form-expectations.js'), -// config: require('./forms/form-config.js'), +// expectations: forms.expectations, +// config: formConfig, // }, { id: 'screenshot', expectations: screenshots.expectations, @@ -280,5 +282,4 @@ const smokeTests = [{ config: cspConfig, }]; -// TODO: export as named objects? export {screenshot, pwa, pwa2, ...} export default smokeTests; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/forms/form-config.js b/lighthouse-cli/test/smokehouse/test-definitions/forms/form-config.js index 083c6ea17202..f1017e17f0a6 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/forms/form-config.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/forms/form-config.js @@ -5,7 +5,7 @@ */ 'use strict'; -import * as experimentalConfig from '../../../../../lighthouse-core/config/experimental-config.js'; +import experimentalConfig from '../../../../../lighthouse-core/config/experimental-config.js'; /** * @type {LH.Config.Json} diff --git a/lighthouse-cli/test/smokehouse/test-definitions/mixed-content/expectations.js b/lighthouse-cli/test/smokehouse/test-definitions/issues/mixed-content-expectations.js similarity index 100% rename from lighthouse-cli/test/smokehouse/test-definitions/mixed-content/expectations.js rename to lighthouse-cli/test/smokehouse/test-definitions/issues/mixed-content-expectations.js diff --git a/lighthouse-cli/test/smokehouse/test-definitions/issues/mixed-content.js b/lighthouse-cli/test/smokehouse/test-definitions/issues/mixed-content.js deleted file mode 100644 index 4e2e55510ace..000000000000 --- a/lighthouse-cli/test/smokehouse/test-definitions/issues/mixed-content.js +++ /dev/null @@ -1,42 +0,0 @@ -/** - * @license Copyright 2021 The Lighthouse Authors. All Rights Reserved. - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - */ -'use strict'; - -/** @fileoverview Expected Lighthouse audit values for various sites with stable(ish) PWA results. */ - -/** - * @type {Smokehouse.ExpectedRunnerResult} - * Expected Lighthouse results a site with mixed-content issues. - */ -const mixedContent = { - artifacts: { - InspectorIssues: { - mixedContent: [ - { - _minChromiumMilestone: 88, // We went from Warning to AutoUpgrade in https://chromium-review.googlesource.com/c/chromium/src/+/2480817 - resourceType: 'Image', - resolutionStatus: 'MixedContentAutomaticallyUpgraded', - insecureURL: 'http://www.mixedcontentexamples.com/Content/Test/steveholt.jpg', - mainResourceURL: 'https://www.mixedcontentexamples.com/Test/NonSecureImage', - request: { - url: 'http://www.mixedcontentexamples.com/Content/Test/steveholt.jpg', - }, - }, - ], - }, - }, - lhr: { - requestedUrl: 'https://www.mixedcontentexamples.com/Test/NonSecureImage', - finalUrl: 'https://www.mixedcontentexamples.com/Test/NonSecureImage', - audits: { - 'is-on-https': { - score: 0, - }, - }, - }, -}; - -module.exports = mixedContent; diff --git a/package.json b/package.json index a6368c5a67c1..1f7793fae387 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "build-extension-firefox": "node ./build/build-extension.js firefox", "build-devtools": "yarn reset-link && node ./build/build-bundle.js clients/devtools-entry.js dist/lighthouse-dt-bundle.js && node ./build/build-dt-report-resources.js", "build-smokehouse-bundle": "node ./build/build-smokehouse-bundle.js", - "build-lr": "yarn reset-link && node ./build/build-lightrider-bundles.js && rollup lighthouse-cli/test/fixtures/static-server.js -o dist/lightrider/static-server.js -p commonjs -p node-resolve -e mime-db,glob", + "build-lr": "yarn reset-link && node ./build/build-lightrider-bundles.js && rollup lighthouse-cli/test/fixtures/static-server.js -o dist/lightrider/static-server.js -p commonjs -p node-resolve -e mime-types,glob", "build-pack": "bash build/build-pack.sh", "build-report": "node build/build-report-components.js && yarn eslint --fix report/renderer/components.js && node build/build-report.js", "build-sample-reports": "yarn build-report && node build/build-sample-reports.js", @@ -123,7 +123,7 @@ "@types/tabulator-tables": "^4.9.1", "@types/update-notifier": "^4.1.0", "@types/ws": "^7.0.0", - "@types/yargs": "^15.0.11", + "@types/yargs": "^16.0.0", "@types/yargs-parser": "^15.0.0", "@typescript-eslint/eslint-plugin": "^4.30.0", "@typescript-eslint/parser": "^4.30.0", @@ -167,7 +167,6 @@ "rollup": "^2.50.6", "rollup-plugin-commonjs": "^10.1.0", "rollup-plugin-node-resolve": "^5.2.0", - "rollup-plugin-shim": "^1.0.0", "rollup-plugin-terser": "^7.0.2", "tabulator-tables": "^4.9.3", "terser": "^5.3.8", diff --git a/yarn.lock b/yarn.lock index df3fca317c29..6c4db75c76a5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1265,7 +1265,7 @@ dependencies: "@types/yargs-parser" "*" -"@types/yargs@^15.0.0", "@types/yargs@^15.0.11": +"@types/yargs@^15.0.0": version "15.0.11" resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-15.0.11.tgz#361d7579ecdac1527687bcebf9946621c12ab78c" integrity sha512-jfcNBxHFYJ4nPIacsi3woz1+kvUO6s1CyeEhtnDHBjHUMNj5UlW2GynmnSgiJJEdNg9yW5C8lfoNRZrHGv5EqA== From c7eb1502e903e74c6d716ae3a07aa3ae9e98c240 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Mon, 13 Sep 2021 11:52:35 -0700 Subject: [PATCH 07/11] lock --- yarn.lock | 5 ----- 1 file changed, 5 deletions(-) diff --git a/yarn.lock b/yarn.lock index 6c4db75c76a5..020f6fc97088 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7471,11 +7471,6 @@ rollup-plugin-node-resolve@^5.2.0: resolve "^1.11.1" rollup-pluginutils "^2.8.1" -rollup-plugin-shim@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/rollup-plugin-shim/-/rollup-plugin-shim-1.0.0.tgz#b00f5cb44cdae81358c5342fe82fa71a1602b56b" - integrity sha512-rZqFD43y4U9nSqVq3iyWBiDwmBQJY8Txi04yI9jTKD3xcl7CbFjh1qRpQshUB3sONLubDzm7vJiwB+1MEGv67w== - rollup-plugin-terser@^7.0.2: version "7.0.2" resolved "https://registry.yarnpkg.com/rollup-plugin-terser/-/rollup-plugin-terser-7.0.2.tgz#e8fbba4869981b2dc35ae7e8a502d5c6c04d324d" From d0267b41a71a6cdf3c25c8de4dbe667d1c09d2f4 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Mon, 13 Sep 2021 12:03:34 -0700 Subject: [PATCH 08/11] fix --- lighthouse-cli/test/fixtures/package.json | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 lighthouse-cli/test/fixtures/package.json diff --git a/lighthouse-cli/test/fixtures/package.json b/lighthouse-cli/test/fixtures/package.json new file mode 100644 index 000000000000..bd346284783c --- /dev/null +++ b/lighthouse-cli/test/fixtures/package.json @@ -0,0 +1,4 @@ +{ + "type": "module", + "//": "Any directory that uses `import ... from` or `export ...` must be type module. Temporary file until root package.json is type: module" +} \ No newline at end of file From 39cc2f8a7377cb2f8c0244fb60218eed3602b957 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Mon, 13 Sep 2021 12:07:30 -0700 Subject: [PATCH 09/11] fixmerge --- .../test/smokehouse/test-definitions/core-tests.js | 6 ++++-- .../test/smokehouse/test-definitions/pubads/expectations.js | 2 +- .../smokehouse/test-definitions/pubads/pubads-config.js | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lighthouse-cli/test/smokehouse/test-definitions/core-tests.js b/lighthouse-cli/test/smokehouse/test-definitions/core-tests.js index caae51a9ff5e..b4f1081db990 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/core-tests.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/core-tests.js @@ -19,6 +19,7 @@ import * as mixedContent from './issues/mixed-content-expectations.js'; import * as offline from './offline-local/offline-expectations.js'; import * as oopifg from './oopif/oopif-expectations.js'; import * as perf from './perf/expectations.js'; +import * as pubads from './pubads/expectations.js'; import * as pwa from './pwa/pwa-expectations.js'; import * as pwa2 from './pwa/pwa2-expectations.js'; import * as pwa3 from './pwa/pwa3-expectations.js'; @@ -39,6 +40,7 @@ import offlineConfig from './offline-local/offline-config.js'; import oopifConfig from './oopif/oopif-config.js'; import perfConfig from './perf/perf-config.js'; import perfDiagnosticsConfig from './perf-diagnostics/perf-diagnostics-config.js'; +import pubadsConfig from './pubads/pubads-config.js'; import pwaConfig from './pwa/pwa-config.js'; import redirectsConfig from './redirects/redirects-config.js'; import screenshotConfig from './screenshot/screenshot-config.js'; @@ -270,8 +272,8 @@ const smokeTests = [{ config: screenshotConfig, }, { id: 'pubads', - expectations: require('./pubads/expectations.js'), - config: require('./pubads/pubads-config.js'), + expectations: pubads.expectations, + config: pubadsConfig, }, { id: 'csp-allow-all', expectations: csp.allowAll, diff --git a/lighthouse-cli/test/smokehouse/test-definitions/pubads/expectations.js b/lighthouse-cli/test/smokehouse/test-definitions/pubads/expectations.js index 95b6a39fd9f6..e9bc4e7797c7 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/pubads/expectations.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/pubads/expectations.js @@ -21,4 +21,4 @@ const expectations = { }, }; -module.exports = expectations; +export {expectations}; diff --git a/lighthouse-cli/test/smokehouse/test-definitions/pubads/pubads-config.js b/lighthouse-cli/test/smokehouse/test-definitions/pubads/pubads-config.js index 742c2cdeecc8..a4483e678745 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/pubads/pubads-config.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/pubads/pubads-config.js @@ -6,7 +6,9 @@ 'use strict'; /** @type {LH.Config.Json} */ -module.exports = { +const config = { extends: 'lighthouse:default', plugins: ['lighthouse-plugin-publisher-ads'], }; + +export default config; From 6e3544ebaf1ddc245a3ef89fc3ce34b55438d074 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Mon, 13 Sep 2021 12:39:49 -0700 Subject: [PATCH 10/11] fix static server test --- .../test/{ => fixtures}/static-server-test.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) rename lighthouse-cli/test/{ => fixtures}/static-server-test.js (86%) diff --git a/lighthouse-cli/test/static-server-test.js b/lighthouse-cli/test/fixtures/static-server-test.js similarity index 86% rename from lighthouse-cli/test/static-server-test.js rename to lighthouse-cli/test/fixtures/static-server-test.js index 93f0d1234005..451c94f794b4 100644 --- a/lighthouse-cli/test/static-server-test.js +++ b/lighthouse-cli/test/fixtures/static-server-test.js @@ -5,9 +5,11 @@ */ 'use strict'; -const fs = require('fs'); -const fetch = require('node-fetch'); -const {server} = require('./fixtures/static-server.js'); +import fs from 'fs'; + +import fetch from 'node-fetch'; + +import {server} from './static-server.js'; /* eslint-env jest */ @@ -27,7 +29,7 @@ describe('Server', () => { it('fetches fixture', async () => { const res = await fetch(`http://localhost:${server.getPort()}/dobetterweb/dbw_tester.html`); const data = await res.text(); - const expected = fs.readFileSync(`${__dirname}/fixtures/dobetterweb/dbw_tester.html`, 'utf-8'); + const expected = fs.readFileSync(`${server.baseDir}/dobetterweb/dbw_tester.html`, 'utf-8'); expect(data).toEqual(expected); }); From 359a0db3d1563ee3a646a136e162ddd046047851 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Mon, 13 Sep 2021 12:51:36 -0700 Subject: [PATCH 11/11] fix windows --- lighthouse-cli/test/smokehouse/frontends/smokehouse-bin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lighthouse-cli/test/smokehouse/frontends/smokehouse-bin.js b/lighthouse-cli/test/smokehouse/frontends/smokehouse-bin.js index a0f3a50e530c..2c50a18f3760 100644 --- a/lighthouse-cli/test/smokehouse/frontends/smokehouse-bin.js +++ b/lighthouse-cli/test/smokehouse/frontends/smokehouse-bin.js @@ -27,7 +27,7 @@ import {updateTestDefnFormat} from './back-compat-util.js'; import {LH_ROOT} from '../../../../root.js'; const coreTestDefnsPath = - `${LH_ROOT}/lighthouse-cli/test/smokehouse/test-definitions/core-tests.js`; + path.join(LH_ROOT, 'lighthouse-cli/test/smokehouse/test-definitions/core-tests.js'); /** * Possible Lighthouse runners. Loaded dynamically so e.g. a CLI run isn't