Skip to content

Commit

Permalink
tests: move readJson from root.js to test-utils.js (#14175)
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark committed Jun 30, 2022
1 parent 24bc84a commit 6680d23
Show file tree
Hide file tree
Showing 118 changed files with 152 additions and 165 deletions.
3 changes: 2 additions & 1 deletion build/build-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import PubAdsPlugin from 'lighthouse-plugin-publisher-ads/plugin.js';

import * as rollupPlugins from './rollup-plugins.js';
import Runner from '../lighthouse-core/runner.js';
import {LH_ROOT, readJson} from '../root.js';
import {LH_ROOT} from '../root.js';
import {readJson} from '../lighthouse-core/test/test-utils.js';

const require = createRequire(import.meta.url);

Expand Down
3 changes: 2 additions & 1 deletion build/build-extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import cpy from 'cpy';
import {rollup} from 'rollup';

import * as rollupPlugins from './rollup-plugins.js';
import {LH_ROOT, readJson} from '../root.js';
import {LH_ROOT} from '../root.js';
import {readJson} from '../lighthouse-core/test/test-utils.js';

const argv = process.argv.slice(2);
const browserBrand = argv[0];
Expand Down
3 changes: 2 additions & 1 deletion build/build-sample-reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import swapFlowLocale from '../shared/localization/swap-flow-locale.js';
import ReportGenerator from '../report/generator/report-generator.js';
import {defaultSettings} from '../lighthouse-core/config/constants.js';
import lighthouse from '../lighthouse-core/index.js';
import {LH_ROOT, readJson} from '../root.js';
import {LH_ROOT} from '../root.js';
import {readJson} from '../lighthouse-core/test/test-utils.js';

/** @type {LH.Result} */
const lhr = readJson(`${LH_ROOT}/lighthouse-core/test/results/sample_v2.json`);
Expand Down
3 changes: 2 additions & 1 deletion build/gh-pages-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import glob from 'glob';
import * as terser from 'terser';

import * as rollupPlugins from './rollup-plugins.js';
import {LH_ROOT, readJson} from '../root.js';
import {LH_ROOT} from '../root.js';
import {readJson} from '../lighthouse-core/test/test-utils.js';

const ghPagesDistDir = `${LH_ROOT}/dist/gh-pages`;
const lighthousePackage = readJson(`${LH_ROOT}/package.json`);
Expand Down
3 changes: 2 additions & 1 deletion lighthouse-cli/test/cli/bin-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import fs from 'fs';
import * as td from 'testdouble';
import jestMock from 'jest-mock';

import {LH_ROOT, readJson} from '../../../root.js';
import {LH_ROOT} from '../../../root.js';
import {readJson} from '../../../lighthouse-core/test/test-utils.js';

const mockRunLighthouse = jestMock.fn();
const mockGetFlags = jestMock.fn();
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-cli/test/cli/printer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import {strict as assert} from 'assert';
import fs from 'fs';

import {readJson} from '../../../root.js';
import {readJson} from '../../../lighthouse-core/test/test-utils.js';
import * as Printer from '../../printer.js';

const sampleResults = readJson('../../../lighthouse-core/test/results/sample_v2.json', import.meta);
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-cli/test/smokehouse/report-assert-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

/* eslint-disable no-control-regex */

import {readJson} from '../../../lighthouse-core/test/test-utils.js';
import {findDifferences, getAssertionReport} from './report-assert.js';
import {readJson} from '../../../root.js';

describe('findDiffersences', () => {
const testCases = {
Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/scripts/build-test-flow-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import fs from 'fs';
import open from 'open';

import reportGenerator from '../../report/generator/report-generator.js';
import {LH_ROOT, readJson} from '../../root.js';
import {LH_ROOT} from '../../root.js';
import {readJson} from '../test/test-utils.js';

const flow = readJson('lighthouse-core/test/fixtures/fraggle-rock/reports/sample-flow-result.json');
const htmlReport = reportGenerator.generateFlowReportHtml(flow);
Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/scripts/i18n/bake-ctc-to-lhl.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import fs from 'fs';
import path from 'path';

import {LH_ROOT, readJson} from '../../../root.js';
import {LH_ROOT} from '../../../root.js';
import {readJson} from '../../test/test-utils.js';

/**
* @typedef CtcMessage
Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/scripts/i18n/count-translated.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

import glob from 'glob';

import {LH_ROOT, readJson} from '../../../root.js';
import {LH_ROOT} from '../../../root.js';
import {readJson} from '../../test/test-utils.js';

/** @type {LhlMessages} */
const enUsLhl = readJson('shared/localization/locales/en-US.json');
Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/scripts/i18n/prune-obsolete-lhl-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import glob from 'glob';
import MessageParser from 'intl-messageformat-parser';

import {collectAllCustomElementsFromICU} from '../../../shared/localization/format.js';
import {LH_ROOT, readJson} from '../../../root.js';
import {LH_ROOT} from '../../../root.js';
import {readJson} from '../../test/test-utils.js';

/** @typedef {Record<string, {message: string}>} LhlMessages */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import log from 'lighthouse-logger';

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

/** @typedef {import('./download-issues.js').AugmentedGitHubIssue} AugmentedGitHubIssue */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import path from 'path';
import chalk from 'chalk';

import constants from './constants.js';
import {readJson} from '../../../root.js';
import {readJson} from '../../test/test-utils.js';

const INPUT_PATH = process.argv[2] || constants.SITE_INDEX_WITH_GOLDEN_WITH_COMPUTED_PATH;
const HEAD_PATH = path.resolve(process.cwd(), INPUT_PATH);
Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/scripts/lantern/debug-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import path from 'path';
import {execFileSync} from 'child_process';

import constants from './constants.js';
import {LH_ROOT, readJson} from '../../../root.js';
import {LH_ROOT} from '../../../root.js';
import {readJson} from '../../test/test-utils.js';

const INPUT_URL = process.argv[2];
if (!INPUT_URL) throw new Error('Usage $0: <url>');
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/scripts/lantern/print-correlations.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import path from 'path';
import chalk from 'chalk';

import constants from './constants.js';
import {readJson} from '../../../root.js';
import {readJson} from '../../test/test-utils.js';

const GOOD_DIFF_AS_PERCENT_THRESHOLD = 0.2;
const OK_DIFF_AS_PERCENT_THRESHOLD = 0.5;
Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/scripts/lantern/run-on-all-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import path from 'path';
import {execFileSync} from 'child_process';

import constants from './constants.js';
import {LH_ROOT, readJson} from '../../../root.js';
import {LH_ROOT} from '../../../root.js';
import {readJson} from '../../test/test-utils.js';

const INPUT_PATH = process.argv[2] || constants.SITE_INDEX_WITH_GOLDEN_PATH;
const SITE_INDEX_PATH = path.resolve(process.cwd(), INPUT_PATH);
Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/scripts/lantern/run-once.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import path from 'path';
import PredictivePerf from '../../audits/predictive-perf.js';
import Simulator from '../../lib/dependency-graph/simulator/simulator.js';
import traceSaver from '../../lib/lantern-trace-saver.js';
import {LH_ROOT, readJson} from '../../../root.js';
import {LH_ROOT} from '../../../root.js';
import {readJson} from '../../test/test-utils.js';

if (process.argv.length !== 4) throw new Error('Usage $0 <trace file> <devtools file>');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {execFileSync} from 'child_process';
import prettyJSONStringify from 'pretty-json-stringify';

import constants from './constants.js';
import {LH_ROOT, readJson} from '../../../root.js';
import {LH_ROOT} from '../../../root.js';
import {readJson} from '../../test/test-utils.js';

const INPUT_PATH = process.argv[2] || constants.SITE_INDEX_WITH_GOLDEN_PATH;
const SITE_INDEX_PATH = path.resolve(process.cwd(), INPUT_PATH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import colors from 'colors';

import LegacyJavascript from '../../audits/byte-efficiency/legacy-javascript.js';
import format from '../../../shared/localization/format.js';
import {LH_ROOT, readJson} from '../../../root.js';
import {LH_ROOT} from '../../../root.js';
import {readJson} from '../../test/test-utils.js';

const LATEST_RUN_DIR = path.join(LH_ROOT, 'latest-run');

Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/scripts/legacy-javascript/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import glob from 'glob';
import {makeHash} from './hash.js';
import LegacyJavascript from '../../audits/byte-efficiency/legacy-javascript.js';
import networkRecordsToDevtoolsLog from '../../test/network-records-to-devtools-log.js';
import {LH_ROOT, readJson} from '../../../root.js';
import {LH_ROOT} from '../../../root.js';
import {readJson} from '../../test/test-utils.js';

const scriptDir = `${LH_ROOT}/lighthouse-core/scripts/legacy-javascript`;

Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/scripts/release/bump-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import fs from 'fs';

import glob from 'glob';

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

const NEW_VERSION = process.argv[2];
if (!/^\d+\.\d+\.\d+(-dev\.\d{8})?$/.test(NEW_VERSION)) {
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/test/audits/bootup-time-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import {strict as assert} from 'assert';

import {readJson} from '../../../root.js';
import BootupTime from '../../audits/bootup-time.js';
import {readJson} from '../test-utils.js';

const acceptableTrace = readJson('../fixtures/traces/progressive-app-m60.json', import.meta);
const acceptableDevtoolsLogs = readJson('../fixtures/traces/progressive-app-m60.devtools.log.json', import.meta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import CPUNode from '../../../lib/dependency-graph/cpu-node.js';
import Simulator from '../../../lib/dependency-graph/simulator/simulator.js';
import PageDependencyGraph from '../../../computed/page-dependency-graph.js';
import LoadSimulator from '../../../computed/load-simulator.js';
import {getURLArtifactFromDevtoolsLog} from '../../test-utils.js';
import {readJson} from '../../../../root.js';
import {getURLArtifactFromDevtoolsLog, readJson} from '../../test-utils.js';

const trace = readJson('../../fixtures/traces/progressive-app-m60.json', import.meta);
const devtoolsLog = readJson('../../fixtures/traces/progressive-app-m60.devtools.log.json', import.meta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
* 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 {readJson} from '../../../../root.js';
import DuplicatedJavascript from '../../../audits/byte-efficiency/duplicated-javascript.js';
import {
loadSourceMapFixture,
createScript,
getURLArtifactFromDevtoolsLog,
readJson,
} from '../../test-utils.js';

const trace = readJson('../../fixtures/traces/lcp-m78.json', import.meta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* 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 {readJson} from '../../../../root.js';
import LegacyJavascript from '../../../audits/byte-efficiency/legacy-javascript.js';
import networkRecordsToDevtoolsLog from '../../network-records-to-devtools-log.js';
import {readJson} from '../../test-utils.js';

/**
* @param {Array<{url: string, code: string, map?: LH.Artifacts.RawSourceMap}>} scripts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import NetworkNode from '../../../lib/dependency-graph/network-node.js';
import CPUNode from '../../../lib/dependency-graph/cpu-node.js';
import Simulator from '../../../lib/dependency-graph/simulator/simulator.js';
import NetworkRequest from '../../../lib/network-request.js';
import {getURLArtifactFromDevtoolsLog} from '../../test-utils.js';
import {readJson} from '../../../../root.js';
import {getURLArtifactFromDevtoolsLog, readJson} from '../../test-utils.js';

const trace = readJson('../../fixtures/traces/progressive-app-m60.json', import.meta);
const devtoolsLog = readJson('../../fixtures/traces/progressive-app-m60.devtools.log.json', import.meta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

import {strict as assert} from 'assert';

import {readJson} from '../../../root.js';
import CriticalRequestChains from '../../audits/critical-request-chains.js';
import createTestTrace from '../create-test-trace.js';
import networkRecordsToDevtoolsLog from '../network-records-to-devtools-log.js';
import {readJson} from '../test-utils.js';

const redditDevtoolsLog = readJson('../fixtures/artifacts/perflog/defaultPass.devtoolslog.json', import.meta);

Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/test/audits/diagnostics-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {readJson} from '../../../root.js';
import Diagnostics from '../../audits/diagnostics.js';
import {readJson} from '../test-utils.js';

const acceptableTrace = readJson('../fixtures/traces/progressive-app-m60.json', import.meta);
const acceptableDevToolsLog = readJson('../fixtures/traces/progressive-app-m60.devtools.log.json', import.meta);
Expand Down
3 changes: 1 addition & 2 deletions lighthouse-core/test/audits/dobetterweb/uses-http2-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
* 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 {readJson} from '../../../../root.js';
import UsesHTTP2Audit from '../../../audits/dobetterweb/uses-http2.js';
import NetworkRecords from '../../../computed/network-records.js';
import networkRecordsToDevtoolsLog from '../../network-records-to-devtools-log.js';
import {getURLArtifactFromDevtoolsLog} from '../../test-utils.js';
import {getURLArtifactFromDevtoolsLog, readJson} from '../../test-utils.js';

const trace = readJson('../../fixtures/traces/progressive-app-m60.json', import.meta);
const devtoolsLog = readJson('../../fixtures/traces/progressive-app-m60.devtools.log.json', import.meta);
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/test/audits/final-screenshot-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {readJson} from '../../../root.js';
import FinalScreenshotAudit from '../../audits/final-screenshot.js';
import {readJson} from '../test-utils.js';

const pwaTrace = readJson('../fixtures/traces/progressive-app-m60.json', import.meta);

Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/test/audits/installable-manifest-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

import {strict as assert} from 'assert';

import {readJson} from '../../../root.js';
import InstallableManifestAudit from '../../audits/installable-manifest.js';
import manifestParser from '../../lib/manifest-parser.js';
import {readJson} from '../test-utils.js';

const manifest = readJson('../fixtures/manifest.json', import.meta);
const manifestDirtyJpg = readJson('../fixtures/manifest-dirty-jpg.json', import.meta);
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/test/audits/main-thread-tasks-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {readJson} from '../../../root.js';
import MainThreadTasks from '../../audits/main-thread-tasks.js';
import {readJson} from '../test-utils.js';

const acceptableTrace = readJson('../fixtures/traces/progressive-app-m60.json', import.meta);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import {strict as assert} from 'assert';

import {readJson} from '../../../root.js';
import PageExecutionTimings from '../../audits/mainthread-work-breakdown.js';
import {readJson} from '../test-utils.js';

const acceptableTrace = readJson('../fixtures/traces/progressive-app-m60.json', import.meta);
const siteWithRedirectTrace = readJson('../fixtures/traces/site-with-redirect.json', import.meta);
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/test/audits/maskable-icon-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* 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 {readJson} from '../../../root.js';
import MaskableIconAudit from '../../audits/maskable-icon.js';
import manifestParser from '../../lib/manifest-parser.js';
import {readJson} from '../test-utils.js';

const manifest = readJson('../fixtures/manifest.json', import.meta);
const manifestWithoutMaskable = readJson('../fixtures/manifest-no-maskable-icon.json', import.meta);
Expand Down
3 changes: 1 addition & 2 deletions lighthouse-core/test/audits/metrics-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@

import jestMock from 'jest-mock';

import {readJson} from '../../../root.js';
import MetricsAudit from '../../audits/metrics.js';
import TTIComputed from '../../computed/metrics/interactive.js';
import {getURLArtifactFromDevtoolsLog} from '../test-utils.js';
import {getURLArtifactFromDevtoolsLog, readJson} from '../test-utils.js';

const pwaTrace = readJson('../fixtures/traces/progressive-app-m60.json', import.meta);
const pwaDevtoolsLog = readJson('../fixtures/traces/progressive-app-m60.devtools.log.json', import.meta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {readJson} from '../../../../root.js';
import CumulativeLayoutShift from '../../../audits/metrics/cumulative-layout-shift.js';
import {readJson} from '../../test-utils.js';

const jumpyClsTrace = readJson('../../fixtures/traces/jumpy-cls-m90.json', import.meta);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* 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 {readJson} from '../../../../root.js';
import ExperimentalInteractionToNextPaint from
'../../../audits/metrics/experimental-interaction-to-next-paint.js';
import {readJson} from '../../test-utils.js';

const interactionTrace = readJson('../../fixtures/traces/timespan-responsiveness-m103.trace.json', import.meta);
const noInteractionTrace = readJson('../../fixtures/traces/jumpy-cls-m90.json', import.meta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +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 {readJson} from '../../../../root.js';
import FCP3G from '../../../audits/metrics/first-contentful-paint-3g.js';
import {getURLArtifactFromDevtoolsLog} from '../../test-utils.js';
import {getURLArtifactFromDevtoolsLog, readJson} from '../../test-utils.js';

const pwaTrace = readJson('../../fixtures/traces/progressive-app-m60.json', import.meta);
const pwaDevtoolsLog = readJson('../../fixtures/traces/progressive-app-m60.devtools.log.json', import.meta);
Expand Down
Loading

0 comments on commit 6680d23

Please sign in to comment.