diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml index 6408dbf9f9d0..7d637aa2e780 100644 --- a/.github/workflows/unit.yml +++ b/.github/workflows/unit.yml @@ -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). diff --git a/build/test/plugins/inline-fs-test.js b/build/test/plugins/inline-fs-test.js index 8657d82d1b62..24daec3fcadc 100644 --- a/build/test/plugins/inline-fs-test.js +++ b/build/test/plugins/inline-fs-test.js @@ -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); diff --git a/cli/test/cli/bin-test.js b/cli/test/cli/bin-test.js index 872cd3260ef3..0cfb98597ca3 100644 --- a/cli/test/cli/bin-test.js +++ b/cli/test/cli/bin-test.js @@ -5,6 +5,7 @@ */ import fs from 'fs'; +import {pathToFileURL} from 'url'; import * as td from 'testdouble'; import jestMock from 'jest-mock'; @@ -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); @@ -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); diff --git a/core/config/config-helpers.js b/core/config/config-helpers.js index 8cf9142ba2c9..94b222e7ad07 100644 --- a/core/config/config-helpers.js +++ b/core/config/config-helpers.js @@ -6,6 +6,7 @@ import path from 'path'; import {createRequire} from 'module'; +import url from 'url'; import isDeepEqual from 'lodash/isEqual.js'; @@ -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)) { @@ -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; + } } } diff --git a/core/test/gather/mock-driver.js b/core/test/gather/mock-driver.js index e8cf900a30a1..b6aa95de54b1 100644 --- a/core/test/gather/mock-driver.js +++ b/core/test/gather/mock-driver.js @@ -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 */ @@ -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; } diff --git a/core/test/test-utils.js b/core/test/test-utils.js index 7b786e710f09..9416a3db0365 100644 --- a/core/test/test-utils.js +++ b/core/test/test-utils.js @@ -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: [], @@ -286,9 +286,7 @@ function getURLArtifactFromDevtoolsLog(devtoolsLog) { * @return {Promise>>} */ 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!`); } diff --git a/package.json b/package.json index 50349b2a6335..6610984f1b9d 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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": [ diff --git a/yarn.lock b/yarn.lock index c5ceb7712dc1..1e4c795d8391 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"