Skip to content

Commit

Permalink
finish
Browse files Browse the repository at this point in the history
  • Loading branch information
adamraine committed Nov 9, 2022
1 parent 2bf1f3c commit de496fc
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 103 deletions.
13 changes: 2 additions & 11 deletions core/test/gather/driver/navigation-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,12 @@ import {
flushAllTimersAndMicrotasks,
timers,
} from '../../test-utils.js';
// import {gotoURL, getNavigationWarnings} from '../../../gather/driver/navigation.js';

const {createMockOnceFn} = mockCommands;

// 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
/** @type {import('../../../gather/driver/navigation.js')['gotoURL']} */
let gotoURL;
/** @type {import('../../../gather/driver/navigation.js')['getNavigationWarnings']} */
let getNavigationWarnings;

before(async () => {
({gotoURL, getNavigationWarnings} = (await import('../../../gather/driver/navigation.js')));
});
// https://github.com/GoogleChrome/lighthouse/blob/main/docs/hacking-tips.md#mocking-modules-with-testdouble
const {gotoURL, getNavigationWarnings} = await import('../../../gather/driver/navigation.js');

timers.useFakeTimers();

Expand Down
17 changes: 5 additions & 12 deletions core/test/gather/driver/prepare-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,6 @@ import * as td from 'testdouble';

import {createMockSession, createMockDriver} from '../mock-driver.js';
import {flushAllTimersAndMicrotasks, fnAny, timers} from '../../test-utils.js';
// import prepare from '../../../gather/driver/prepare.js';
import * as constants from '../../../config/constants.js';

// 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
/** @type {import('../../../gather/driver/prepare.js')} */
let prepare;

before(async () => {
prepare = (await import('../../../gather/driver/prepare.js'));
});

const storageMock = {
clearDataForOrigin: fnAny(),
Expand All @@ -28,6 +16,11 @@ const storageMock = {
};
await td.replaceEsm('../../../gather/driver/storage.js', storageMock);

// Some imports needs to be done dynamically, so that their dependencies will be mocked.
// https://github.com/GoogleChrome/lighthouse/blob/main/docs/hacking-tips.md#mocking-modules-with-testdouble
const prepare = await import('../../../gather/driver/prepare.js');
const constants = await import('../../../config/constants.js');

const url = 'https://example.com';
let sessionMock = createMockSession();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,14 @@
*/

import {createMockContext, mockDriverSubmodules} from '../../../gather/mock-driver.js';
// import ResponseCompression from '../../../../gather/gatherers/dobetterweb/response-compression.js';

const mocks = await mockDriverSubmodules();

// 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
// https://github.com/GoogleChrome/lighthouse/blob/main/docs/hacking-tips.md#mocking-modules-with-testdouble
/** @typedef {import('../../../../gather/gatherers/dobetterweb/response-compression.js')} ResponseCompression */
/** @type {typeof import('../../../../gather/gatherers/dobetterweb/response-compression.js')} */
let ResponseCompression;

before(async () => {
ResponseCompression =
(await import('../../../../gather/gatherers/dobetterweb/response-compression.js')).default;
});

const mocks = await mockDriverSubmodules();
const ResponseCompression =
(await import('../../../../gather/gatherers/dobetterweb/response-compression.js')).default;

const networkRecords = [
{
Expand Down
16 changes: 5 additions & 11 deletions core/test/gather/gatherers/link-elements-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,16 @@
import jestMock from 'jest-mock';
import * as td from 'testdouble';

// 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/gatherers/link-elements.js').default} LinkElements */
/** @type {typeof import('../../../gather/gatherers/link-elements.js').default} */
let LinkElements;

before(async () => {
LinkElements = (await import('../../../gather/gatherers/link-elements.js')).default;
});

const mockMainResource = jestMock.fn();
await td.replaceEsm('../../../computed/main-resource.js', {
MainResource: {request: mockMainResource},
});

// Some imports needs to be done dynamically, so that their dependencies will be mocked.
// https://github.com/GoogleChrome/lighthouse/blob/main/docs/hacking-tips.md#mocking-modules-with-testdouble
/** @typedef {import('../../../gather/gatherers/link-elements.js').default} LinkElements */
const LinkElements = (await import('../../../gather/gatherers/link-elements.js')).default;

beforeEach(() => {
mockMainResource.mockReset();
});
Expand Down
17 changes: 5 additions & 12 deletions core/test/gather/gatherers/script-elements-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,14 @@
*/

import {createMockContext, mockDriverSubmodules} from '../mock-driver.js';
// import ScriptElements from '../../../gather/gatherers/script-elements.js';
import {NetworkRequest} from '../../../lib/network-request.js';

const mocks = await mockDriverSubmodules();

// 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
// https://github.com/GoogleChrome/lighthouse/blob/main/docs/hacking-tips.md#mocking-modules-with-testdouble
/** @typedef {import('../../../gather/gatherers/script-elements.js').default} ScriptElements */
/** @type {typeof import('../../../gather/gatherers/script-elements.js').default} */
let ScriptElements;

before(async () => {
ScriptElements = (await import('../../../gather/gatherers/script-elements.js')).default;
});

const mocks = await mockDriverSubmodules();
const ScriptElements = (await import('../../../gather/gatherers/script-elements.js')).default;
const {NetworkRequest} = await import('../../../lib/network-request.js');

/**
* @param {Partial<LH.Artifacts.NetworkRequest>=} partial
Expand Down
16 changes: 4 additions & 12 deletions core/test/gather/gatherers/service-worker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,6 @@ import * as td from 'testdouble';

import {fnAny} from '../../test-utils.js';

// import ServiceWorkerGather from '../../../gather/gatherers/service-worker.js';

// 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
/** @type {typeof import('../../../gather/gatherers/service-worker.js').default} */
let ServiceWorkerGather;

before(async () => {
ServiceWorkerGather = (await import('../../../gather/gatherers/service-worker.js')).default;
});

const getServiceWorkerVersions = fnAny();
const getServiceWorkerRegistrations = fnAny();

Expand All @@ -30,6 +18,10 @@ await td.replaceEsm('../../../gather/driver/service-workers.js', {
getServiceWorkerRegistrations,
});

// Some imports needs to be done dynamically, so that their dependencies will be mocked.
// https://github.com/GoogleChrome/lighthouse/blob/main/docs/hacking-tips.md#mocking-modules-with-testdouble
const ServiceWorkerGather = (await import('../../../gather/gatherers/service-worker.js')).default;

describe('service worker gatherer', () => {
it('obtains the active service worker registration', async () => {
const url = 'https://example.com/';
Expand Down
5 changes: 2 additions & 3 deletions core/test/gather/navigation-runner-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
mockDriverSubmodules,
mockRunnerModule,
} from './mock-driver.js';
import {defaultNavigationConfig} from '../../config/constants.js';
import {fnAny} from '../test-utils.js';
import {networkRecordsToDevtoolsLog} from '../network-records-to-devtools-log.js';
import {Runner as runnerActual} from '../../runner.js';
Expand All @@ -26,13 +25,13 @@ beforeEach(async () => {
});

// 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
// https://github.com/GoogleChrome/lighthouse/blob/main/docs/hacking-tips.md#mocking-modules-with-testdouble
const runner = await import('../../gather/navigation-runner.js');
const {LighthouseError} = await import('../../lib/lh-error.js');
const DevtoolsLogGatherer = (await import('../../gather/gatherers/devtools-log.js')).default;
const TraceGatherer = (await import('../../gather/gatherers/trace.js')).default;
const {initializeConfig} = await import('../../config/config.js');
const {defaultNavigationConfig} = await import('../../config/constants.js');

/** @typedef {{meta: LH.Gatherer.GathererMeta<'Accessibility'>, getArtifact: Mock<any, any>, startInstrumentation: Mock<any, any>, stopInstrumentation: Mock<any, any>, startSensitiveInstrumentation: Mock<any, any>, stopSensitiveInstrumentation: Mock<any, any>}} MockGatherer */

Expand Down
5 changes: 2 additions & 3 deletions core/test/gather/snapshot-runner-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ await td.replaceEsm('../../gather/driver.js',
mockDriverModule(() => mockDriver.asDriver()));

// 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
const snapshotGather = (await import('../../gather/snapshot-runner.js')).snapshotGather;
// https://github.com/GoogleChrome/lighthouse/blob/main/docs/hacking-tips.md#mocking-modules-with-testdouble
const {snapshotGather} = await import('../../gather/snapshot-runner.js');

describe('Snapshot Runner', () => {
/** @type {ReturnType<typeof createMockPage>} */
Expand Down
5 changes: 2 additions & 3 deletions core/test/gather/timespan-runner-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ await td.replaceEsm('../../gather/driver.js',
mockDriverModule(() => mockDriver.asDriver()));

// 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
const startTimespanGather = (await import('../../gather/timespan-runner.js')).startTimespanGather;
// https://github.com/GoogleChrome/lighthouse/blob/main/docs/hacking-tips.md#mocking-modules-with-testdouble
const {startTimespanGather} = await import('../../gather/timespan-runner.js');

describe('Timespan Runner', () => {
/** @type {ReturnType<typeof createMockPage>} */
Expand Down
25 changes: 8 additions & 17 deletions core/test/legacy/gather/gather-runner-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ import assert from 'assert/strict';

import jestMock from 'jest-mock';

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,
Expand Down Expand Up @@ -50,23 +44,20 @@ 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
// https://github.com/GoogleChrome/lighthouse/blob/main/docs/hacking-tips.md#mocking-modules-with-testdouble
/** @typedef {import('../../../legacy/gather/driver.js').Driver} Driver */
/** @type {typeof import('../../../legacy/gather/driver.js').Driver} */
let Driver;
/** @type {typeof import('../../../legacy/gather/gather-runner.js').GatherRunner} */
let GatherRunner_;
/** @typedef {import('../../../legacy/config/config.js').Config} Config */
/** @type {typeof import('../../../legacy/config/config.js').Config} */
let Config;
/** @typedef {import('../../../legacy/gather/connections/connection.js').Connection} Connection */
const {Driver} = await import('../../../legacy/gather/driver.js');
const {GatherRunner: GatherRunner_} = await import('../../../legacy/gather/gather-runner.js');
const {Config} = await import('../../../legacy/config/config.js');
const {Gatherer} = await import('../../../gather/gatherers/gatherer.js');
const {LighthouseError} = await import('../../../lib/lh-error.js');
const {Connection} = await import('../../../legacy/gather/connections/connection.js');

/** @type {ReturnType<createTypeHackedGatherRunner>} */
let GatherRunner;
before(async () => {
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();
Expand Down
9 changes: 4 additions & 5 deletions core/test/runner-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ await td.replaceEsm('../gather/driver/service-workers.js', {
});

// 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
const Runner = (await import('../runner.js')).Runner;
const GatherRunner = (await import('../legacy/gather/gather-runner.js')).GatherRunner;
const Config = (await import('../legacy/config/config.js')).Config;
// https://github.com/GoogleChrome/lighthouse/blob/main/docs/hacking-tips.md#mocking-modules-with-testdouble
const {Runner} = await import('../runner.js');
const {GatherRunner} = await import('../legacy/gather/gather-runner.js');
const {Config} = await import('../legacy/config/config.js');
const {Audit} = await import('../audits/audit.js');
const {Gatherer} = await import('../gather/gatherers/gatherer.js');
const i18n = await import('../lib/i18n/i18n.js');
Expand Down
3 changes: 1 addition & 2 deletions core/test/user-flow-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ await td.replaceEsm('../gather/timespan-runner.js', timespanModule);
const mockRunner = await mockRunnerModule();

// 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
// https://github.com/GoogleChrome/lighthouse/blob/main/docs/hacking-tips.md#mocking-modules-with-testdouble
const {getStepName, getFlowName, UserFlow, auditGatherSteps} = await import('../user-flow.js');

describe('UserFlow', () => {
Expand Down

0 comments on commit de496fc

Please sign in to comment.