diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 91796856373d..755c3ec91e2f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -128,7 +128,7 @@ accept your pull requests. ## Tracking Errors -We track our errors in the wild with Sentry. In general, do not worry about wrapping your audits or gatherers in try/catch blocks and reporting every error that could possibly occur; `core/runner.js` and `core/gather/gather-runner.js` already catch and report any errors that occur while running a gatherer or audit, including errors fatal to the entire run. However, there are some situations when you might want to explicitly handle an error and report it to Sentry or wrap it to avoid reporting. Generally, you can interact with Sentry simply by requiring the `core/lib/sentry.js` file and call its methods. The module exports a delegate that will correctly handle the error reporting based on the user's opt-in preference and will simply no-op if they haven't so you don't need to check. +We track our errors in the wild with Sentry. In general, do not worry about wrapping your audits or gatherers in try/catch blocks and reporting every error that could possibly occur; `core/runner.js` and `core/fraggle-rock/gather/*-runner.js` already catch and report any errors that occur while running a gatherer or audit, including errors fatal to the entire run. However, there are some situations when you might want to explicitly handle an error and report it to Sentry or wrap it to avoid reporting. Generally, you can interact with Sentry simply by requiring the `core/lib/sentry.js` file and call its methods. The module exports a delegate that will correctly handle the error reporting based on the user's opt-in preference and will simply no-op if they haven't so you don't need to check. #### If you have an expected error that is recoverable but want to track how frequently it happens, *use Sentry.captureException*. diff --git a/build/build-bundle.js b/build/build-bundle.js index 9fab54dacdad..43510cf79923 100644 --- a/build/build-bundle.js +++ b/build/build-bundle.js @@ -102,7 +102,7 @@ async function buildBundle(entryPath, distPath, opts = {minify: true}) { /** @type {Record} */ const shimsObj = { - [require.resolve('../core/gather/connections/cri.js')]: + [require.resolve('../core/legacy/gather/connections/cri.js')]: 'export const CriConnection = {}', [require.resolve('../package.json')]: `export const version = '${pkg.version}';`, }; diff --git a/cli/test/smokehouse/lighthouse-runners/bundle.js b/cli/test/smokehouse/lighthouse-runners/bundle.js index 81204ee7d55f..86cb9f7d1a2f 100644 --- a/cli/test/smokehouse/lighthouse-runners/bundle.js +++ b/cli/test/smokehouse/lighthouse-runners/bundle.js @@ -19,7 +19,7 @@ import {once} from 'events'; import puppeteer from 'puppeteer-core'; import ChromeLauncher from 'chrome-launcher'; -import {CriConnection} from '../../../../core/gather/connections/cri.js'; +import {CriConnection} from '../../../../core/legacy/gather/connections/cri.js'; import {LH_ROOT} from '../../../../root.js'; import {loadArtifacts, saveArtifacts} from '../../../../core/lib/asset-saver.js'; diff --git a/clients/devtools/devtools-entry.js b/clients/devtools/devtools-entry.js index ca3abb1294f9..a83222239783 100644 --- a/clients/devtools/devtools-entry.js +++ b/clients/devtools/devtools-entry.js @@ -12,12 +12,12 @@ import log from 'lighthouse-logger'; import lighthouse, {legacyNavigation} from '../../core/index.js'; import {navigation, startTimespan, snapshot} from '../../core/fraggle-rock/api.js'; -import {RawConnection} from '../../core/gather/connections/raw.js'; +import {RawConnection} from '../../core/legacy/gather/connections/raw.js'; import {lookupLocale} from '../../core/lib/i18n/i18n.js'; import {registerLocaleData, getCanonicalLocales} from '../../shared/localization/format.js'; import * as constants from '../../core/config/constants.js'; -/** @typedef {import('../../core/gather/connections/connection.js')} Connection */ +/** @typedef {import('../../core/legacy/gather/connections/connection.js')} Connection */ // Rollup seems to overlook some references to `Buffer`, so it must be made explicit. // (`parseSourceMapFromDataUrl` breaks without this) @@ -58,7 +58,7 @@ function createConfig(categoryIDs, device) { } /** - * @param {import('../../core/gather/connections/raw.js').Port} port + * @param {import('../../core/legacy/gather/connections/raw.js').Port} port * @return {RawConnection} */ function setUpWorkerConnection(port) { diff --git a/clients/lightrider/lightrider-entry.js b/clients/lightrider/lightrider-entry.js index 0cedc2c5959f..676fb522ff73 100644 --- a/clients/lightrider/lightrider-entry.js +++ b/clients/lightrider/lightrider-entry.js @@ -25,7 +25,7 @@ const LR_PRESETS = { desktop: desktopConfig, }; -/** @typedef {import('../../core/gather/connections/connection.js').Connection} Connection */ +/** @typedef {import('../../core/legacy/gather/connections/connection.js').Connection} Connection */ // Rollup seems to overlook some references to `Buffer`, so it must be made explicit. // (`parseSourceMapFromDataUrl` breaks without this) diff --git a/core/gather/gatherers/seo/font-size.js b/core/gather/gatherers/seo/font-size.js index 025631e725e4..33d56e416973 100644 --- a/core/gather/gatherers/seo/font-size.js +++ b/core/gather/gatherers/seo/font-size.js @@ -22,7 +22,7 @@ const MINIMAL_LEGIBLE_FONT_SIZE_PX = 12; // limit number of protocol calls to make sure that gatherer doesn't take more than 1-2s const MAX_NODES_SOURCE_RULE_FETCHED = 50; // number of nodes to fetch the source font-size rule -/** @typedef {import('../../driver.js')} Driver */ +/** @typedef {import('../../../legacy/gather/driver.js')} Driver */ /** @typedef {LH.Artifacts.FontSize['analyzedFailingNodesData'][0]} NodeFontData */ /** @typedef {Map} BackendIdsToFontData */ diff --git a/core/index.js b/core/index.js index 0aa2b6bb60de..fe8b33564b77 100644 --- a/core/index.js +++ b/core/index.js @@ -7,14 +7,14 @@ import log from 'lighthouse-logger'; import {Runner} from './runner.js'; -import {CriConnection} from './gather/connections/cri.js'; -import {Config} from './config/config.js'; +import {CriConnection} from './legacy/gather/connections/cri.js'; +import {Config} from './legacy/config/config.js'; import UrlUtils from './lib/url-utils.js'; import * as fraggleRock from './fraggle-rock/api.js'; -import {Driver} from './gather/driver.js'; +import {Driver} from './legacy/gather/driver.js'; import {initializeConfig} from './fraggle-rock/config/config.js'; -/** @typedef {import('./gather/connections/connection.js').Connection} Connection */ +/** @typedef {import('./legacy/gather/connections/connection.js').Connection} Connection */ /* * The relationship between these root modules: diff --git a/core/config/config.js b/core/legacy/config/config.js similarity index 97% rename from core/config/config.js rename to core/legacy/config/config.js index 48fabd302b9a..1180b17a66ff 100644 --- a/core/config/config.js +++ b/core/legacy/config/config.js @@ -9,10 +9,10 @@ import path from 'path'; import log from 'lighthouse-logger'; import legacyDefaultConfig from './legacy-default-config.js'; -import * as constants from './constants.js'; -import * as format from '../../shared/localization/format.js'; -import * as validation from './../fraggle-rock/config/validation.js'; -import {Runner} from '../runner.js'; +import * as constants from '../../config/constants.js'; +import * as format from '../../../shared/localization/format.js'; +import * as validation from '../../fraggle-rock/config/validation.js'; +import {Runner} from '../../runner.js'; import { mergePlugins, mergeConfigFragment, @@ -21,12 +21,12 @@ import { resolveGathererToDefn, deepClone, deepCloneConfigJson, -} from './config-helpers.js'; -import {getModuleDirectory} from '../../esm-utils.js'; +} from '../../config/config-helpers.js'; +import {getModuleDirectory} from '../../../esm-utils.js'; const defaultConfigPath = './legacy-default-config.js'; -/** @typedef {typeof import('../gather/gatherers/gatherer.js').Gatherer} GathererConstructor */ +/** @typedef {typeof import('../../gather/gatherers/gatherer.js').Gatherer} GathererConstructor */ /** @typedef {InstanceType} Gatherer */ /** diff --git a/core/config/legacy-default-config.js b/core/legacy/config/legacy-default-config.js similarity index 97% rename from core/config/legacy-default-config.js rename to core/legacy/config/legacy-default-config.js index dd3d193b7740..7cc286f29308 100644 --- a/core/config/legacy-default-config.js +++ b/core/legacy/config/legacy-default-config.js @@ -8,7 +8,7 @@ * @fileoverview Construct the legacy default config from the standard default config. */ -import defaultConfig from './default-config.js'; +import defaultConfig from '../../config/default-config.js'; /** @type {LH.Config.Json} */ const legacyDefaultConfig = JSON.parse(JSON.stringify(defaultConfig)); diff --git a/core/gather/connections/connection.js b/core/legacy/gather/connections/connection.js similarity index 98% rename from core/gather/connections/connection.js rename to core/legacy/gather/connections/connection.js index 677313e62a2b..350cb613fac3 100644 --- a/core/gather/connections/connection.js +++ b/core/legacy/gather/connections/connection.js @@ -8,7 +8,7 @@ import {EventEmitter} from 'events'; import log from 'lighthouse-logger'; -import {LighthouseError} from '../../lib/lh-error.js'; +import {LighthouseError} from '../../../lib/lh-error.js'; // TODO(bckenny): CommandCallback properties should be tied by command type after // https://github.com/Microsoft/TypeScript/pull/22348. See driver.js TODO. diff --git a/core/gather/connections/cri.js b/core/legacy/gather/connections/cri.js similarity index 98% rename from core/gather/connections/cri.js rename to core/legacy/gather/connections/cri.js index 7f64960e8d29..6ae03a126bc9 100644 --- a/core/gather/connections/cri.js +++ b/core/legacy/gather/connections/cri.js @@ -10,7 +10,7 @@ import WebSocket from 'ws'; import log from 'lighthouse-logger'; import {Connection} from './connection.js'; -import {LighthouseError} from '../../lib/lh-error.js'; +import {LighthouseError} from '../../../lib/lh-error.js'; const DEFAULT_HOSTNAME = '127.0.0.1'; const CONNECT_TIMEOUT = 10000; diff --git a/core/gather/connections/raw.js b/core/legacy/gather/connections/raw.js similarity index 100% rename from core/gather/connections/raw.js rename to core/legacy/gather/connections/raw.js diff --git a/core/gather/driver.js b/core/legacy/gather/driver.js similarity index 97% rename from core/gather/driver.js rename to core/legacy/gather/driver.js index 7b30d567c50b..24b634825c5e 100644 --- a/core/gather/driver.js +++ b/core/legacy/gather/driver.js @@ -8,13 +8,13 @@ import {EventEmitter} from 'events'; import log from 'lighthouse-logger'; -import {Fetcher} from './fetcher.js'; -import {ExecutionContext} from './driver/execution-context.js'; -import {LighthouseError} from '../lib/lh-error.js'; -import {fetchResponseBodyFromCache} from '../gather/driver/network.js'; -import {DevtoolsMessageLog} from './gatherers/devtools-log.js'; -import TraceGatherer from './gatherers/trace.js'; -import {getBrowserVersion} from './driver/environment.js'; +import {Fetcher} from '../../gather/fetcher.js'; +import {ExecutionContext} from '../../gather/driver/execution-context.js'; +import {LighthouseError} from '../../lib/lh-error.js'; +import {fetchResponseBodyFromCache} from '../../gather/driver/network.js'; +import {DevtoolsMessageLog} from '../../gather/gatherers/devtools-log.js'; +import TraceGatherer from '../../gather/gatherers/trace.js'; +import {getBrowserVersion} from '../../gather/driver/environment.js'; // Controls how long to wait for a response after sending a DevTools protocol command. const DEFAULT_PROTOCOL_TIMEOUT = 30000; diff --git a/core/gather/gather-runner.js b/core/legacy/gather/gather-runner.js similarity index 94% rename from core/gather/gather-runner.js rename to core/legacy/gather/gather-runner.js index d802bfd251cc..b0372f2c6cc8 100644 --- a/core/gather/gather-runner.js +++ b/core/legacy/gather/gather-runner.js @@ -6,25 +6,25 @@ import log from 'lighthouse-logger'; -import {NetworkRecords} from '../computed/network-records.js'; -import {getPageLoadError} from '../lib/navigation-error.js'; -import * as emulation from '../lib/emulation.js'; -import * as constants from '../config/constants.js'; -import * as format from '../../shared/localization/format.js'; -import {getBenchmarkIndex, getEnvironmentWarnings} from './driver/environment.js'; -import * as prepare from './driver/prepare.js'; -import * as storage from './driver/storage.js'; -import * as navigation from './driver/navigation.js'; -import * as serviceWorkers from './driver/service-workers.js'; -import WebAppManifest from './gatherers/web-app-manifest.js'; -import InstallabilityErrors from './gatherers/installability-errors.js'; -import NetworkUserAgent from './gatherers/network-user-agent.js'; -import Stacks from './gatherers/stacks.js'; -import {finalizeArtifacts} from '../fraggle-rock/gather/base-artifacts.js'; -import UrlUtils from '../lib/url-utils.js'; - -/** @typedef {import('../gather/driver.js').Driver} Driver */ -/** @typedef {import('../lib/arbitrary-equality-map.js').ArbitraryEqualityMap} ArbitraryEqualityMap */ +import {NetworkRecords} from '../../computed/network-records.js'; +import {getPageLoadError} from '../../lib/navigation-error.js'; +import * as emulation from '../../lib/emulation.js'; +import * as constants from '../../config/constants.js'; +import * as format from '../../../shared/localization/format.js'; +import {getBenchmarkIndex, getEnvironmentWarnings} from '../../gather/driver/environment.js'; +import * as prepare from '../../gather/driver/prepare.js'; +import * as storage from '../../gather/driver/storage.js'; +import * as navigation from '../../gather/driver/navigation.js'; +import * as serviceWorkers from '../../gather/driver/service-workers.js'; +import WebAppManifest from '../../gather/gatherers/web-app-manifest.js'; +import InstallabilityErrors from '../../gather/gatherers/installability-errors.js'; +import NetworkUserAgent from '../../gather/gatherers/network-user-agent.js'; +import Stacks from '../../gather/gatherers/stacks.js'; +import {finalizeArtifacts} from '../../fraggle-rock/gather/base-artifacts.js'; +import UrlUtils from '../../lib/url-utils.js'; + +/** @typedef {import('./driver.js').Driver} Driver */ +/** @typedef {import('../../lib/arbitrary-equality-map.js').ArbitraryEqualityMap} ArbitraryEqualityMap */ /** * Each entry in each gatherer result array is the output of a gatherer phase: diff --git a/core/runner.js b/core/runner.js index 6ebf64a8a570..53adb821a482 100644 --- a/core/runner.js +++ b/core/runner.js @@ -7,11 +7,12 @@ import fs from 'fs'; import path from 'path'; -import isDeepEqual from 'lodash/isEqual.js'; + import log from 'lighthouse-logger'; +import isDeepEqual from 'lodash/isEqual.js'; -import {Driver} from './gather/driver.js'; -import {GatherRunner} from './gather/gather-runner.js'; +import {Driver} from './legacy/gather/driver.js'; +import {GatherRunner} from './legacy/gather/gather-runner.js'; import {ReportScoring} from './scoring.js'; import {Audit} from './audits/audit.js'; import * as format from '../shared/localization/format.js'; @@ -25,7 +26,7 @@ import {getModuleDirectory} from '../esm-utils.js'; const moduleDir = getModuleDirectory(import.meta); -/** @typedef {import('./gather/connections/connection.js').Connection} Connection */ +/** @typedef {import('./legacy/gather/connections/connection.js').Connection} Connection */ /** @typedef {import('./lib/arbitrary-equality-map.js').ArbitraryEqualityMap} ArbitraryEqualityMap */ /** @typedef {LH.Config.Config} Config */ diff --git a/core/test/gather/fetcher-test.js b/core/test/gather/fetcher-test.js index e69618e62424..7c73409f792e 100644 --- a/core/test/gather/fetcher-test.js +++ b/core/test/gather/fetcher-test.js @@ -5,8 +5,8 @@ */ import {Fetcher} from '../../gather/fetcher.js'; -import {Driver} from '../../gather/driver.js'; -import {Connection} from '../../gather/connections/connection.js'; +import {Driver} from '../../legacy/gather/driver.js'; +import {Connection} from '../../legacy/gather/connections/connection.js'; import {fnAny, mockCommands} from '../test-utils.js'; const {createMockSendCommandFn} = mockCommands; diff --git a/core/test/gather/gatherers/global-listeners-test.js b/core/test/gather/gatherers/global-listeners-test.js index b4e72ea156c8..d3a361dd6c3b 100644 --- a/core/test/gather/gatherers/global-listeners-test.js +++ b/core/test/gather/gatherers/global-listeners-test.js @@ -6,8 +6,8 @@ import GlobalListenerGatherer from '../../../gather/gatherers/global-listeners.js'; import {createMockSendCommandFn} from '../mock-commands.js'; -import {Connection} from '../../../gather/connections/connection.js'; -import {Driver} from '../../../gather/driver.js'; +import {Connection} from '../../../legacy/gather/connections/connection.js'; +import {Driver} from '../../../legacy/gather/driver.js'; describe('Global Listener Gatherer', () => { it('remove duplicate listeners from artifacts', async () => { diff --git a/core/test/gather/gatherers/js-usage-test.js b/core/test/gather/gatherers/js-usage-test.js index 2c061654db3f..29b3393bcc06 100644 --- a/core/test/gather/gatherers/js-usage-test.js +++ b/core/test/gather/gatherers/js-usage-test.js @@ -4,8 +4,8 @@ * 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. */ -import {Driver} from '../../../gather/driver.js'; -import {Connection} from '../../../gather/connections/connection.js'; +import {Driver} from '../../../legacy/gather/driver.js'; +import {Connection} from '../../../legacy/gather/connections/connection.js'; import JsUsage from '../../../gather/gatherers/js-usage.js'; import {createMockSendCommandFn, createMockOnFn} from '../mock-commands.js'; import {createMockContext} from '../../fraggle-rock/gather/mock-driver.js'; diff --git a/core/test/gather/gatherers/source-maps-test.js b/core/test/gather/gatherers/source-maps-test.js index fa9fab1b2630..d096aacb04ba 100644 --- a/core/test/gather/gatherers/source-maps-test.js +++ b/core/test/gather/gatherers/source-maps-test.js @@ -4,8 +4,8 @@ * 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. */ -import {Driver} from '../../../gather/driver.js'; -import {Connection} from '../../../gather/connections/connection.js'; +import {Driver} from '../../../legacy/gather/driver.js'; +import {Connection} from '../../../legacy/gather/connections/connection.js'; import SourceMaps from '../../../gather/gatherers/source-maps.js'; import {createMockSendCommandFn, createMockOnFn} from '../mock-commands.js'; import {flushAllTimersAndMicrotasks, fnAny, timers} from '../../test-utils.js'; diff --git a/core/test/gather/gatherers/trace-elements-test.js b/core/test/gather/gatherers/trace-elements-test.js index 844eb91c19c9..08bb68c933ae 100644 --- a/core/test/gather/gatherers/trace-elements-test.js +++ b/core/test/gather/gatherers/trace-elements-test.js @@ -5,8 +5,8 @@ */ import TraceElementsGatherer from '../../../gather/gatherers/trace-elements.js'; -import {Driver} from '../../../gather/driver.js'; -import {Connection} from '../../../gather/connections/connection.js'; +import {Driver} from '../../../legacy/gather/driver.js'; +import {Connection} from '../../../legacy/gather/connections/connection.js'; import {createTestTrace} from '../../create-test-trace.js'; import {createMockSendCommandFn, createMockOnFn} from '../mock-commands.js'; import {flushAllTimersAndMicrotasks, fnAny, readJson, timers} from '../../test-utils.js'; diff --git a/core/test/config/config-test.js b/core/test/legacy/config/config-test.js similarity index 97% rename from core/test/config/config-test.js rename to core/test/legacy/config/config-test.js index a35554b62769..2b2d582af0de 100644 --- a/core/test/config/config-test.js +++ b/core/test/legacy/config/config-test.js @@ -10,14 +10,14 @@ import {createRequire} from 'module'; import log from 'lighthouse-logger'; -import {Config} from '../../config/config.js'; -import legacyDefaultConfig from '../../config/legacy-default-config.js'; -import * as constants from '../../config/constants.js'; -import {Gatherer} from '../../gather/gatherers/gatherer.js'; -import {Audit} from '../../audits/audit.js'; -import * as i18n from '../../lib/i18n/i18n.js'; -import * as format from '../../../shared/localization/format.js'; -import {getModuleDirectory, getModulePath} from '../../../esm-utils.js'; +import {Config} from '../../../legacy/config/config.js'; +import legacyDefaultConfig from '../../../legacy/config/legacy-default-config.js'; +import * as constants from '../../../config/constants.js'; +import {Gatherer} from '../../../gather/gatherers/gatherer.js'; +import {Audit} from '../../../audits/audit.js'; +import * as i18n from '../../../lib/i18n/i18n.js'; +import * as format from '../../../../shared/localization/format.js'; +import {getModuleDirectory, getModulePath} from '../../../../esm-utils.js'; const require = createRequire(import.meta.url); const moduleDir = getModuleDirectory(import.meta); @@ -361,7 +361,7 @@ describe('Config', () => { }); it('throws on a non-absolute config path', async () => { - const configPath = '../../config/legacy-default-config.js'; + const configPath = '../../legacy/config/legacy-default-config.js'; await assert.rejects(Config.fromJson({ audits: [], @@ -374,7 +374,7 @@ describe('Config', () => { const configPath = modulePath; return assert.doesNotReject(Config.fromJson({ - audits: ['../fixtures/valid-custom-audit' + variant], + audits: ['../../fixtures/valid-custom-audit' + variant], }, {configPath})); }); @@ -382,7 +382,7 @@ describe('Config', () => { // Construct an audit URL relative to current working directory, regardless // of where test was started from. const absoluteAuditPath = - path.resolve(moduleDir, '../fixtures/valid-custom-audit' + variant); + path.resolve(moduleDir, '../../fixtures/valid-custom-audit' + variant); assert.doesNotThrow(() => require.resolve(absoluteAuditPath)); const relativePath = path.relative(process.cwd(), absoluteAuditPath); @@ -405,7 +405,7 @@ describe('Config', () => { it('throws but not for missing audit when audit has a dependency error', async () => { await assert.rejects(Config.fromJson({ - audits: [path.resolve(moduleDir, '../fixtures/invalid-audits/require-error.js')], + audits: [path.resolve(moduleDir, '../../fixtures/invalid-audits/require-error.js')], }), function(err) { // We're expecting not to find parent class Audit, so only reject on our // own custom locate audit error, not the usual MODULE_NOT_FOUND. @@ -417,7 +417,7 @@ describe('Config', () => { }); it('throws when it finds invalid audits', async () => { - const basePath = path.resolve(moduleDir, '../fixtures/invalid-audits'); + const basePath = path.resolve(moduleDir, '../../fixtures/invalid-audits'); await assert.rejects(Config.fromJson({ audits: [basePath + '/missing-audit'], }), /audit\(\) method/); @@ -978,7 +978,7 @@ describe('Config', () => { describe('mergePlugins', () => { // Include a configPath flag so that config.js looks for the plugins in the fixtures dir. - const configFixturePath = moduleDir + '/../fixtures/config-plugins/'; + const configFixturePath = moduleDir + '/../../fixtures/config-plugins/'; it('should append audits', async () => { const configJson = { @@ -1357,7 +1357,8 @@ describe('Config', () => { ['', '.js', '.cjs'].forEach(variant => { describe(`loads custom gatherer (variant: "${variant}")`, () => { it('loads gatherers from custom paths', async () => { - const customPath = path.resolve(moduleDir, '../fixtures/valid-custom-gatherer' + variant); + const customPath = + path.resolve(moduleDir, '../../fixtures/valid-custom-gatherer' + variant); const gatherer = await loadGatherer(customPath); assert.equal(gatherer.instance.name, 'CustomGatherer'); assert.equal(typeof gatherer.instance.beforePass, 'function'); @@ -1365,7 +1366,7 @@ describe('Config', () => { it('loads a gatherer relative to a config path', async () => { const config = await Config.fromJson({ - passes: [{gatherers: ['../fixtures/valid-custom-gatherer' + variant]}], + passes: [{gatherers: ['../../fixtures/valid-custom-gatherer' + variant]}], }, {configPath: modulePath}); const gatherer = config.passes[0].gatherers[0]; @@ -1412,7 +1413,7 @@ describe('Config', () => { it('loads a gatherer relative to the working directory', async () => { // Construct a gatherer URL relative to current working directory, // regardless of where test was started from. - const absoluteGathererPath = path.resolve(moduleDir, '../fixtures/valid-custom-gatherer'); + const absoluteGathererPath = path.resolve(moduleDir, '../../fixtures/valid-custom-gatherer'); assert.doesNotThrow(_ => require.resolve(absoluteGathererPath)); const relativeGathererPath = path.relative(process.cwd(), absoluteGathererPath); @@ -1422,7 +1423,8 @@ describe('Config', () => { }); it('throws but not for missing gatherer when it has a dependency error', async () => { - const gathererPath = path.resolve(moduleDir, '../fixtures/invalid-gatherers/require-error'); + const gathererPath = + path.resolve(moduleDir, '../../fixtures/invalid-gatherers/require-error'); await assert.rejects(loadGatherer(gathererPath), function(err) { // We're expecting not to find parent class Gatherer, so only reject on @@ -1437,7 +1439,7 @@ describe('Config', () => { }); it('throws for invalid gatherers', async () => { - const root = path.resolve(moduleDir, '../fixtures/invalid-gatherers'); + const root = path.resolve(moduleDir, '../../fixtures/invalid-gatherers'); await assert.rejects(loadGatherer(`${root}/missing-before-pass`), /beforePass\(\) method/); diff --git a/core/test/gather/driver-test.js b/core/test/legacy/gather/driver-test.js similarity index 98% rename from core/test/gather/driver-test.js rename to core/test/legacy/gather/driver-test.js index 334652d392ea..b397c108cc8c 100644 --- a/core/test/gather/driver-test.js +++ b/core/test/legacy/gather/driver-test.js @@ -4,8 +4,8 @@ * 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. */ -import {Driver} from '../../gather/driver.js'; -import {Connection} from '../../gather/connections/connection.js'; +import {Driver} from '../../../legacy/gather/driver.js'; +import {Connection} from '../../../legacy/gather/connections/connection.js'; import {fakeDriver} from './fake-driver.js'; import { mockCommands, @@ -13,7 +13,7 @@ import { flushAllTimersAndMicrotasks, fnAny, timers, -} from '../test-utils.js'; +} from '../../test-utils.js'; const {createMockSendCommandFn} = mockCommands; diff --git a/core/test/gather/fake-driver.js b/core/test/legacy/gather/fake-driver.js similarity index 98% rename from core/test/gather/fake-driver.js rename to core/test/legacy/gather/fake-driver.js index 06465d9974c0..c32699c5fc9c 100644 --- a/core/test/gather/fake-driver.js +++ b/core/test/legacy/gather/fake-driver.js @@ -4,7 +4,7 @@ * 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. */ -import {fnAny, readJson} from '../test-utils.js'; +import {fnAny, readJson} from '../../test-utils.js'; /** * @param {{protocolGetVersionResponse: LH.CrdpCommands['Browser.getVersion']['returnType']}} param0 diff --git a/core/test/gather/gather-runner-test.js b/core/test/legacy/gather/gather-runner-test.js similarity index 94% rename from core/test/gather/gather-runner-test.js rename to core/test/legacy/gather/gather-runner-test.js index 0b66db432be7..14f2f75298fd 100644 --- a/core/test/gather/gather-runner-test.js +++ b/core/test/legacy/gather/gather-runner-test.js @@ -8,14 +8,14 @@ import {strict as assert} from 'assert'; import jestMock from 'jest-mock'; -import {Gatherer} from '../../gather/gatherers/gatherer.js'; -// import GathererRunner_ from '../../gather/gather-runner.js'; -// import {Config} from '../../config/config.js'; -import {LighthouseError} from '../../lib/lh-error.js'; -import {networkRecordsToDevtoolsLog} from '../network-records-to-devtools-log.js'; -// import {Driver} from '../../gather/driver.js'; -import {Connection} from '../../gather/connections/connection.js'; -import {createMockSendCommandFn, createMockOnceFn} from './mock-commands.js'; +import {Gatherer} from '../../../gather/gatherers/gatherer.js'; +// import GathererRunner_ from '../../legacy/gather/gather-runner.js'; +// import {Config} from '../../legacy/config/config.js'; +import {LighthouseError} from '../../../lib/lh-error.js'; +import {networkRecordsToDevtoolsLog} from '../../network-records-to-devtools-log.js'; +// import {Driver} from '../../legacy/gather/driver.js'; +import {Connection} from '../../../legacy/gather/connections/connection.js'; +import {createMockSendCommandFn, createMockOnceFn} from '../../gather/mock-commands.js'; import { makeMocksForGatherRunner, makeParamsOptional, @@ -25,10 +25,10 @@ import { timers, importMock, readJson, -} from '../test-utils.js'; +} from '../../test-utils.js'; import {fakeDriver} from './fake-driver.js'; -const unresolvedPerfLog = readJson('./../fixtures/unresolved-perflog.json', import.meta); +const unresolvedPerfLog = readJson('../../fixtures/unresolved-perflog.json', import.meta); await makeMocksForGatherRunner(); @@ -52,21 +52,21 @@ function createTypeHackedGatherRunner() { // Some imports needs to be done dynamically, so that their dependencies will be mocked. // See: https://jestjs.io/docs/ecmascript-modules#differences-between-esm-and-commonjs // https://github.com/facebook/jest/issues/10025 -/** @typedef {import('../../gather/driver.js').Driver} Driver */ -/** @type {typeof import('../../gather/driver.js').Driver} */ +/** @typedef {import('../../../legacy/gather/driver.js').Driver} Driver */ +/** @type {typeof import('../../../legacy/gather/driver.js').Driver} */ let Driver; -/** @type {typeof import('../../gather/gather-runner.js').GatherRunner} */ +/** @type {typeof import('../../../legacy/gather/gather-runner.js').GatherRunner} */ let GatherRunner_; -/** @typedef {import('../../config/config.js').Config} Config */ -/** @type {typeof import('../../config/config.js').Config} */ +/** @typedef {import('../../../legacy/config/config.js').Config} Config */ +/** @type {typeof import('../../../legacy/config/config.js').Config} */ let Config; /** @type {ReturnType} */ let GatherRunner; before(async () => { - Driver = (await import('../../gather/driver.js')).Driver; - GatherRunner_ = (await import('../../gather/gather-runner.js')).GatherRunner; - Config = (await import('../../config/config.js')).Config; + Driver = (await import('../../../legacy/gather/driver.js')).Driver; + GatherRunner_ = (await import('../../../legacy/gather/gather-runner.js')).GatherRunner; + Config = (await import('../../../legacy/config/config.js')).Config; assertNoSameOriginServiceWorkerClientsMock = jestMock.spyOn(GatherRunner_, 'assertNoSameOriginServiceWorkerClients'); GatherRunner = createTypeHackedGatherRunner(); @@ -103,7 +103,7 @@ class TestGathererNoArtifact extends Gatherer { afterPass() {} } -/** @type {import('../../gather/driver.js').Driver} */ +/** @type {import('../../../legacy/gather/driver.js').Driver} */ let driver; /** @type {Connection & {sendCommand: ReturnType}} */ let connectionStub; @@ -154,7 +154,7 @@ beforeEach(async () => { driver = new EmulationDriver(connectionStub); resetDefaultMockResponses(); - const {gotoURL} = await importMock('../../gather/driver/navigation.js', import.meta); + const {gotoURL} = await importMock('../../../gather/driver/navigation.js', import.meta); gotoURL.mockReset().mockResolvedValue({ mainDocumentUrl: 'https://example.com', timedOut: false, @@ -172,7 +172,7 @@ describe('GatherRunner', function() { const url1 = 'https://example.com'; const url2 = 'https://example.com/interstitial'; const driver = {}; - const {gotoURL} = await importMock('../../gather/driver/navigation.js', import.meta); + const {gotoURL} = await importMock('../../../gather/driver/navigation.js', import.meta); gotoURL.mockResolvedValue({mainDocumentUrl: url2, warnings: []}); const passContext = { @@ -199,7 +199,7 @@ describe('GatherRunner', function() { const url = 'https://example.com'; const error = new LighthouseError(LighthouseError.errors.NO_FCP); const driver = {}; - const {gotoURL} = await importMock('../../gather/driver/navigation.js', import.meta); + const {gotoURL} = await importMock('../../../gather/driver/navigation.js', import.meta); gotoURL.mockRejectedValue(error); const passContext = { @@ -247,7 +247,7 @@ describe('GatherRunner', function() { it('collects requested and final URLs as an artifact', async () => { const requestedUrl = 'https://example.com'; const mainDocumentUrl = 'https://example.com/interstitial'; - const {gotoURL} = await importMock('../../gather/driver/navigation.js', import.meta); + const {gotoURL} = await importMock('../../../gather/driver/navigation.js', import.meta); gotoURL.mockResolvedValue({mainDocumentUrl, timedOut: false, warnings: []}); const config = await makeConfig({passes: [{passName: 'defaultPass'}]}); const options = { @@ -461,7 +461,7 @@ describe('GatherRunner', function() { LighthouseRunWarnings: [], }; - const prepare = await importMock('../../gather/driver/prepare.js', import.meta); + const prepare = await importMock('../../../gather/driver/prepare.js', import.meta); await GatherRunner.runPass(passContext); expect(prepare.prepareTargetForIndividualNavigation).toHaveBeenCalled(); }); @@ -513,7 +513,7 @@ describe('GatherRunner', function() { }, }); - const {gotoURL} = await importMock('../../gather/driver/navigation.js', import.meta); + const {gotoURL} = await importMock('../../../gather/driver/navigation.js', import.meta); gotoURL.mockImplementation( /** @param {any} _ @param {string} url */ (_, url) => url.includes('blank') ? null : Promise.reject(navigationError) @@ -557,7 +557,7 @@ describe('GatherRunner', function() { }, }); - const {gotoURL} = await importMock('../../gather/driver/navigation.js', import.meta); + const {gotoURL} = await importMock('../../../gather/driver/navigation.js', import.meta); gotoURL.mockImplementation( /** @param {any} _ @param {string} url */ (_, url) => url.includes('blank') ? gotoUrlForAboutBlank() : gotoUrlForRealUrl() @@ -830,7 +830,7 @@ describe('GatherRunner', function() { let firstLoad = true; const driver = Object.assign({}, fakeDriver, {online: true}); - const {gotoURL} = await importMock('../../gather/driver/navigation.js', import.meta); + const {gotoURL} = await importMock('../../../gather/driver/navigation.js', import.meta); gotoURL.mockImplementation( /** @@ -1243,7 +1243,7 @@ describe('GatherRunner', function() { online: true, }); - const {gotoURL} = await importMock('../../gather/driver/navigation.js', import.meta); + const {gotoURL} = await importMock('../../../gather/driver/navigation.js', import.meta); gotoURL.mockResolvedValue({mainDocumentUrl: requestedUrl, warnings: ['It is too slow']}); return GatherRunner.run(config.passes, { @@ -1275,7 +1275,7 @@ describe('GatherRunner', function() { online: true, }); - const {gotoURL} = await importMock('../../gather/driver/navigation.js', import.meta); + const {gotoURL} = await importMock('../../../gather/driver/navigation.js', import.meta); gotoURL .mockResolvedValueOnce({finalUrl: requestedUrl, warnings: []}) .mockResolvedValueOnce({finalUrl: requestedUrl, warnings: ['It is too slow']}); diff --git a/core/test/lib/emulation-test.js b/core/test/lib/emulation-test.js index dd7c04d8d7dc..81a5925dcd46 100644 --- a/core/test/lib/emulation-test.js +++ b/core/test/lib/emulation-test.js @@ -5,9 +5,9 @@ */ import * as emulation from '../../lib/emulation.js'; -import {Driver} from '../../gather/driver.js'; +import {Driver} from '../../legacy/gather/driver.js'; import * as constants from '../../config/constants.js'; -import {Connection} from '../../gather/connections/connection.js'; +import {Connection} from '../../legacy/gather/connections/connection.js'; import {createMockSendCommandFn} from '../gather/mock-commands.js'; describe('emulation', () => { diff --git a/core/test/runner-test.js b/core/test/runner-test.js index dab7d436660c..63fe224bcb08 100644 --- a/core/test/runner-test.js +++ b/core/test/runner-test.js @@ -12,9 +12,9 @@ import jestMock from 'jest-mock'; import * as td from 'testdouble'; // import Runner from '../runner.js'; -// import {GatherRunner} from '../gather/gather-runner.js'; -import {fakeDriver as driverMock} from './gather/fake-driver.js'; -// import {Config} from '../config/config.js'; +// import {GatherRunner} from '../legacy/gather/gather-runner.js'; +import {fakeDriver as driverMock} from './legacy/gather/fake-driver.js'; +// import {Config} from '../legacy/config/config.js'; import {Audit} from '../audits/audit.js'; import {Gatherer} from '../gather/gatherers/gatherer.js'; import * as assetSaver from '../lib/asset-saver.js'; @@ -32,9 +32,9 @@ await makeMocksForGatherRunner(); // https://github.com/facebook/jest/issues/10025 /** @type {typeof import('../runner.js').Runner} */ let Runner; -/** @type {typeof import('../gather/gather-runner.js').GatherRunner} */ +/** @type {typeof import('../legacy/gather/gather-runner.js').GatherRunner} */ let GatherRunner; -/** @type {typeof import('../config/config.js').Config} */ +/** @type {typeof import('../legacy/config/config.js').Config} */ let Config; /** @type {jestMock.Mock} */ @@ -61,8 +61,8 @@ await td.replaceEsm('../gather/driver/service-workers.js', { before(async () => { Runner = (await import('../runner.js')).Runner; - GatherRunner = (await import('../gather/gather-runner.js')).GatherRunner; - Config = (await import('../config/config.js')).Config; + GatherRunner = (await import('../legacy/gather/gather-runner.js')).GatherRunner; + Config = (await import('../legacy/config/config.js')).Config; }); beforeEach(() => { diff --git a/core/test/scripts/run-mocha-tests.js b/core/test/scripts/run-mocha-tests.js index 70d4da3f0c3b..845558706708 100644 --- a/core/test/scripts/run-mocha-tests.js +++ b/core/test/scripts/run-mocha-tests.js @@ -66,7 +66,7 @@ const testsToIsolate = new Set([ // grep -lRE '^timers\.useFakeTimers' --include='*-test.*' --exclude-dir=node_modules 'flow-report/test/common-test.tsx', 'core/test/fraggle-rock/gather/session-test.js', - 'core/test/gather/driver-test.js', + 'core/test/legacy/gather/driver-test.js', 'core/test/gather/driver/execution-context-test.js', 'core/test/gather/driver/navigation-test.js', 'core/test/gather/driver/wait-for-condition-test.js', @@ -92,7 +92,7 @@ const testsToIsolate = new Set([ 'core/test/fraggle-rock/gather/snapshot-runner-test.js', 'core/test/fraggle-rock/gather/timespan-runner-test.js', 'core/test/fraggle-rock/user-flow-test.js', - 'core/test/gather/gather-runner-test.js', + 'core/test/legacy/gather/gather-runner-test.js', 'core/test/gather/gatherers/dobetterweb/response-compression-test.js', 'core/test/gather/gatherers/script-elements-test.js', 'core/test/runner-test.js', @@ -107,7 +107,7 @@ const testsToIsolate = new Set([ 'flow-report/test/flow-report-pptr-test.ts', 'cli/test/cli/bin-test.js', 'cli/test/cli/run-test.js', - 'core/test/config/config-test.js', + 'core/test/legacy/config/config-test.js', 'core/test/fraggle-rock/config/config-test.js', 'core/test/lib/emulation-test.js', 'core/test/lib/sentry-test.js', diff --git a/tsconfig.json b/tsconfig.json index f2579c0ad3b6..e7e2a76946ad 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -41,7 +41,7 @@ "core/test/config/budget-test.js", "core/test/config/config-helpers-test.js", "core/test/config/config-plugin-test.js", - "core/test/config/config-test.js", + "core/test/legacy/config/config-test.js", "core/test/config/default-config-test.js", "core/test/create-test-trace.js", "core/test/gather/driver/wait-for-condition-test.js", diff --git a/types/gatherer.d.ts b/types/gatherer.d.ts index 94c433e2b998..c4955b134aaa 100644 --- a/types/gatherer.d.ts +++ b/types/gatherer.d.ts @@ -7,7 +7,7 @@ import {NetworkNode as _NetworkNode} from '../core/lib/dependency-graph/network-node'; import {CPUNode as _CPUNode} from '../core/lib/dependency-graph/cpu-node'; import {Simulator as _Simulator} from '../core/lib/dependency-graph/simulator/simulator'; -import {Driver} from '../core/gather/driver'; +import {Driver} from '../core/legacy/gather/driver'; import {ExecutionContext} from '../core/gather/driver/execution-context'; import {Fetcher} from '../core/gather/fetcher'; import {ArbitraryEqualityMap} from '../core/lib/arbitrary-equality-map';