Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ jobs:
- run: yarn install --frozen-lockfile --network-timeout 1000000
- run: yarn build-report

# TODO: fix run-mocha-tests.js on windows.
# - run: yarn unit-cli
- run: yarn unit-cli
- run: yarn diff:sample-json

# Fail if any changes were written to any source files or generated untracked files (ex, from -GA).
Expand Down
7 changes: 6 additions & 1 deletion build/test/plugins/inline-fs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ const require = createRequire(import.meta.url);

const filepath = `${LH_ROOT}/core/index.js`;

describe('inline-fs', () => {
// Lots of path separator issues on Windows, because LH_ROOT has \\ slashes but
// most tests here don't JSON.stringify the strings they interpolate into code.
// Deferring for now.
const describeSkipOnWindows = process.platform === 'win32' ? describe.skip : describe;

describeSkipOnWindows('inline-fs', () => {
const tmpPath = `${LH_ROOT}/.tmp/inline-fs/test.txt`;
const tmpDir = path.dirname(tmpPath);

Expand Down
5 changes: 3 additions & 2 deletions cli/test/cli/bin-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import fs from 'fs';
import {pathToFileURL} from 'url';

import * as td from 'testdouble';
import jestMock from 'jest-mock';
Expand Down Expand Up @@ -89,7 +90,7 @@ describe('CLI bin', function() {
// TODO(esmodules): change this test when config file is esm.
const configPath = `${LH_ROOT}/core/config/lr-desktop-config.js`;
cliFlags = {...cliFlags, configPath: configPath};
const actualConfig = (await import(configPath)).default;
const actualConfig = (await import(pathToFileURL(configPath).href)).default;
await bin.begin();

expect(getRunLighthouseArgs()[2]).toEqual(actualConfig);
Expand All @@ -99,7 +100,7 @@ describe('CLI bin', function() {
const configPath =
`${LH_ROOT}/cli/test/fixtures/esm-config.js`;
cliFlags = {...cliFlags, configPath: configPath};
const actualConfig = (await import(configPath)).default;
const actualConfig = (await import(pathToFileURL(configPath).href)).default;
await bin.begin();

expect(getRunLighthouseArgs()[2]).toEqual(actualConfig);
Expand Down
14 changes: 12 additions & 2 deletions core/config/config-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import path from 'path';
import {createRequire} from 'module';
import url from 'url';

import isDeepEqual from 'lodash/isEqual.js';

Expand Down Expand Up @@ -217,6 +218,11 @@ const bundledModules = new Map(/* BUILD_REPLACE_BUNDLED_MODULES */);
* @param {string} requirePath
*/
async function requireWrapper(requirePath) {
// For windows.
if (path.isAbsolute(requirePath)) {
requirePath = url.pathToFileURL(requirePath).href;
}

/** @type {any} */
let module;
if (bundledModules.has(requirePath)) {
Expand Down Expand Up @@ -287,8 +293,12 @@ function requireAudit(auditPath, coreAuditList, configDir) {
} else {
// Otherwise, attempt to find it elsewhere. This throws if not found.
const absolutePath = resolveModulePath(auditPath, configDir, 'audit');
// Use a relative path so bundler can easily expose it.
requirePath = path.relative(getModuleDirectory(import.meta), absolutePath);
if (isBundledEnvironment()) {
// Use a relative path so bundler can easily expose it.
requirePath = path.relative(getModuleDirectory(import.meta), absolutePath);
} else {
requirePath = absolutePath;
}
}
}

Expand Down
3 changes: 1 addition & 2 deletions core/test/gather/mock-driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
} from './mock-commands.js';
import * as constants from '../../config/constants.js';
import {fnAny} from '../test-utils.js';
import {LH_ROOT} from '../../../root.js';

/** @typedef {import('../../gather/driver.js').Driver} Driver */
/** @typedef {import('../../gather/driver/execution-context.js')} ExecutionContext */
Expand Down Expand Up @@ -187,7 +186,7 @@ const runnerMock = {
},
};
async function mockRunnerModule() {
await td.replaceEsm(`${LH_ROOT}/core/runner.js`, {Runner: runnerMock});
await td.replaceEsm('../../runner.js', {Runner: runnerMock});
return runnerMock;
}

Expand Down
20 changes: 9 additions & 11 deletions core/test/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,35 +182,35 @@ async function flushAllTimersAndMicrotasks(ms = 1000) {
* shouldn't concern themselves about.
*/
async function makeMocksForGatherRunner() {
await td.replaceEsm(require.resolve('../gather/driver/environment.js'), {
await td.replaceEsm('../gather/driver/environment.js', {
getBenchmarkIndex: () => Promise.resolve(150),
getBrowserVersion: async () => ({userAgent: 'Chrome', milestone: 80}),
getEnvironmentWarnings: () => [],
});
await td.replaceEsm(require.resolve('../gather/gatherers/stacks.js'), undefined, {
await td.replaceEsm('../gather/gatherers/stacks.js', undefined, {
collectStacks: () => Promise.resolve([]),
});
await td.replaceEsm(require.resolve('../gather/gatherers/installability-errors.js'), undefined, {
await td.replaceEsm('../gather/gatherers/installability-errors.js', undefined, {
getInstallabilityErrors: async () => ({errors: []}),
});
await td.replaceEsm(require.resolve('../gather/gatherers/web-app-manifest.js'), undefined, {
await td.replaceEsm('../gather/gatherers/web-app-manifest.js', undefined, {
getWebAppManifest: async () => null,
});
await td.replaceEsm(require.resolve('../lib/emulation.js'), {
await td.replaceEsm('../lib/emulation.js', {
emulate: jestMock.fn(),
throttle: jestMock.fn(),
clearThrottling: jestMock.fn(),
});
await td.replaceEsm(require.resolve('../gather/driver/prepare.js'), {
await td.replaceEsm('../gather/driver/prepare.js', {
prepareTargetForNavigationMode: jestMock.fn(),
prepareTargetForIndividualNavigation: jestMock.fn().mockResolvedValue({warnings: []}),
});
await td.replaceEsm(require.resolve('../gather/driver/storage.js'), {
await td.replaceEsm('../gather/driver/storage.js', {
clearDataForOrigin: jestMock.fn(),
cleanBrowserCaches: jestMock.fn(),
getImportantStorageWarning: jestMock.fn(),
});
await td.replaceEsm(require.resolve('../gather/driver/navigation.js'), {
await td.replaceEsm('../gather/driver/navigation.js', {
gotoURL: jestMock.fn().mockResolvedValue({
mainDocumentUrl: 'http://example.com',
warnings: [],
Expand Down Expand Up @@ -286,9 +286,7 @@ function getURLArtifactFromDevtoolsLog(devtoolsLog) {
* @return {Promise<Record<string, Mock<any, any>>>}
*/
async function importMock(modulePath, importMeta) {
const dir = path.dirname(url.fileURLToPath(importMeta.url));
modulePath = path.resolve(dir, modulePath);
const mock = await import(modulePath);
const mock = await import(new URL(modulePath, importMeta.url).href);
if (!Object.keys(mock).some(key => mock[key]?.mock)) {
throw new Error(`${modulePath} was not mocked!`);
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
"parse-cache-control": "1.0.1",
"ps-list": "^8.0.0",
"puppeteer-core": "^18.0.5",
"quibble": "connorjclark/quibble#fork",
"robots-parser": "^3.0.0",
"semver": "^5.3.0",
"speedline-core": "^1.4.3",
Expand All @@ -213,7 +214,7 @@
"resolutions": {
"puppeteer/**/devtools-protocol": "0.0.1034970",
"puppeteer-core/**/devtools-protocol": "0.0.1034970",
"testdouble/**/quibble": "connorjclark/quibble#mod-cache"
"testdouble/**/quibble": "connorjclark/quibble#fork"
},
"repository": "GoogleChrome/lighthouse",
"keywords": [
Expand Down
7 changes: 4 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6031,9 +6031,10 @@ query-string@^4.1.0:
object-assign "^4.1.0"
strict-uri-encode "^1.0.0"

quibble@^0.6.7, quibble@connorjclark/quibble#mod-cache:
version "0.6.14"
resolved "https://codeload.github.com/connorjclark/quibble/tar.gz/68d53b087d4c9117cc86c7e5f19e7953a219582b"
quibble@^0.6.7, quibble@connorjclark/quibble#fork:
version "0.6.12"
uid f49c6c6122f08a4872a1fafc1d2aca68a7fdc2df
resolved "https://codeload.github.com/connorjclark/quibble/tar.gz/f49c6c6122f08a4872a1fafc1d2aca68a7fdc2df"
dependencies:
lodash "^4.17.21"
resolve "^1.20.0"
Expand Down