Skip to content

Commit

Permalink
tests: use readJson instead of imports for json (#14020)
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark authored May 24, 2022
1 parent 48d069d commit 94b4f38
Show file tree
Hide file tree
Showing 95 changed files with 406 additions and 222 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module.exports = {
}],
'no-floating-decimal': 2,
'max-len': [2, 100, {
ignorePattern: 'readJson\\(',
ignoreComments: true,
ignoreUrls: true,
tabWidth: 2,
Expand Down
4 changes: 3 additions & 1 deletion lighthouse-cli/test/cli/printer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import {strict as assert} from 'assert';
import fs from 'fs';

import {readJson} from '../../../root.js';
import * as Printer from '../../printer.js';
import sampleResults from '../../../lighthouse-core/test/results/sample_v2.json';

const sampleResults = readJson('../../../lighthouse-core/test/results/sample_v2.json', import.meta);

describe('Printer', () => {
it('accepts valid output paths', () => {
Expand Down
8 changes: 5 additions & 3 deletions lighthouse-core/test/audits/bootup-time-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

import {strict as assert} from 'assert';

import {readJson} from '../../../root.js';
import BootupTime from '../../audits/bootup-time.js';
import acceptableTrace from '../fixtures/traces/progressive-app-m60.json';
import acceptableDevtoolsLogs from '../fixtures/traces/progressive-app-m60.devtools.log.json';
import errorTrace from '../fixtures/traces/no_fmp_event.json';

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

describe('Performance: bootup-time audit', () => {
const auditOptions = Object.assign({}, BootupTime.defaultOptions, {thresholdInMs: 10});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ 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 trace from '../../fixtures/traces/progressive-app-m60.json';
import devtoolsLog from '../../fixtures/traces/progressive-app-m60.devtools.log.json';
import traceM78 from '../../fixtures/traces/lcp-m78.json';
import devtoolsLogM78 from '../../fixtures/traces/lcp-m78.devtools.log.json';
import {getURLArtifactFromDevtoolsLog} from '../../test-utils.js';
import {readJson} from '../../../../root.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);
const traceM78 = readJson('../../fixtures/traces/lcp-m78.json', import.meta);
const devtoolsLogM78 = readJson('../../fixtures/traces/lcp-m78.devtools.log.json', import.meta);

describe('Byte efficiency base audit', () => {
let graph;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
* 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 trace from '../../fixtures/traces/lcp-m78.json';
import devtoolsLog from '../../fixtures/traces/lcp-m78.devtools.log.json';
import {
loadSourceMapFixture,
createScript,
getURLArtifactFromDevtoolsLog,
} from '../../test-utils.js';

const trace = readJson('../../fixtures/traces/lcp-m78.json', import.meta);
const devtoolsLog = readJson('../../fixtures/traces/lcp-m78.devtools.log.json', import.meta);

describe('DuplicatedJavascript computed artifact', () => {
it('works (simple)', async () => {
const context = {computedCache: new Map(), options: {ignoreThresholdInBytes: 200}};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ 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 trace from '../../fixtures/traces/progressive-app-m60.json';
import devtoolsLog from '../../fixtures/traces/progressive-app-m60.devtools.log.json';
import ampTrace from '../../fixtures/traces/amp-m86.trace.json';
import ampDevtoolsLog from '../../fixtures/traces/amp-m86.devtoolslog.json';
import {getURLArtifactFromDevtoolsLog} from '../../test-utils.js';
import {readJson} from '../../../../root.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);
const ampTrace = readJson('../../fixtures/traces/amp-m86.trace.json', import.meta);
const ampDevtoolsLog = readJson('../../fixtures/traces/amp-m86.devtoolslog.json', import.meta);

const mobileSlow4G = constants.throttling.mobileSlow4G;

Expand Down
4 changes: 3 additions & 1 deletion lighthouse-core/test/audits/critical-request-chains-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

import {strict as assert} from 'assert';

import {readJson} from '../../../root.js';
import CriticalRequestChains from '../../audits/critical-request-chains.js';
import redditDevtoolsLog from '../fixtures/artifacts/perflog/defaultPass.devtoolslog.json';
import createTestTrace from '../create-test-trace.js';
import networkRecordsToDevtoolsLog from '../network-records-to-devtools-log.js';

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

const FAILING_CHAIN_RECORDS = [
{
endTime: 5,
Expand Down
6 changes: 4 additions & 2 deletions lighthouse-core/test/audits/diagnostics-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
* 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 acceptableTrace from '../fixtures/traces/progressive-app-m60.json';
import acceptableDevToolsLog from '../fixtures/traces/progressive-app-m60.devtools.log.json';

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

describe('Diagnostics audit', () => {
it('should work', async () => {
Expand Down
6 changes: 4 additions & 2 deletions lighthouse-core/test/audits/dobetterweb/uses-http2-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
* 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 trace from '../../fixtures/traces/progressive-app-m60.json';
import devtoolsLog from '../../fixtures/traces/progressive-app-m60.devtools.log.json';
import NetworkRecords from '../../../computed/network-records.js';
import networkRecordsToDevtoolsLog from '../../network-records-to-devtools-log.js';
import {getURLArtifactFromDevtoolsLog} 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);

describe('Resources are fetched over http/2', () => {
let artifacts = {};
let context = {};
Expand Down
4 changes: 3 additions & 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,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 FinalScreenshotAudit from '../../audits/final-screenshot.js';
import pwaTrace from '../fixtures/traces/progressive-app-m60.json';

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

const noScreenshotsTrace = {traceEvents: pwaTrace.traceEvents.filter(e => e.name !== 'Screenshot')};

Expand Down
6 changes: 4 additions & 2 deletions lighthouse-core/test/audits/installable-manifest-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

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 manifest from '../fixtures/manifest.json';
import manifestDirtyJpg from '../fixtures/manifest-dirty-jpg.json';

const manifest = readJson('../fixtures/manifest.json', import.meta);
const manifestDirtyJpg = readJson('../fixtures/manifest-dirty-jpg.json', import.meta);

const manifestSrc = JSON.stringify(manifest);
const manifestDirtyJpgSrc = JSON.stringify(manifestDirtyJpg);
Expand Down
4 changes: 3 additions & 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,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 MainThreadTasks from '../../audits/main-thread-tasks.js';
import acceptableTrace from '../fixtures/traces/progressive-app-m60.json';

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

describe('Main thread tasks audit', () => {
it('should work', async () => {
Expand Down
10 changes: 6 additions & 4 deletions lighthouse-core/test/audits/mainthread-work-breakdown-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

import {strict as assert} from 'assert';

import {readJson} from '../../../root.js';
import PageExecutionTimings from '../../audits/mainthread-work-breakdown.js';
import acceptableTrace from '../fixtures/traces/progressive-app-m60.json';
import siteWithRedirectTrace from '../fixtures/traces/site-with-redirect.json';
import loadTrace from '../fixtures/traces/load.json';
import errorTrace from '../fixtures/traces/no_fmp_event.json';

const acceptableTrace = readJson('../fixtures/traces/progressive-app-m60.json', import.meta);
const siteWithRedirectTrace = readJson('../fixtures/traces/site-with-redirect.json', import.meta);
const loadTrace = readJson('../fixtures/traces/load.json', import.meta);
const errorTrace = readJson('../fixtures/traces/no_fmp_event.json', import.meta);

const options = PageExecutionTimings.defaultOptions;

Expand Down
6 changes: 4 additions & 2 deletions lighthouse-core/test/audits/maskable-icon-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +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 MaskableIconAudit from '../../audits/maskable-icon.js';
import manifestParser from '../../lib/manifest-parser.js';
import manifest from '../fixtures/manifest.json';
import manifestWithoutMaskable from '../fixtures/manifest-no-maskable-icon.json';

const manifest = readJson('../fixtures/manifest.json', import.meta);
const manifestWithoutMaskable = readJson('../fixtures/manifest-no-maskable-icon.json', import.meta);

const manifestSrc = JSON.stringify(manifest);
const manifestWithoutMaskableSrc = JSON.stringify(manifestWithoutMaskable);
Expand Down
22 changes: 12 additions & 10 deletions lighthouse-core/test/audits/metrics-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@

import {jest} from '@jest/globals';

import {readJson} from '../../../root.js';
import MetricsAudit from '../../audits/metrics.js';
import TTIComputed from '../../computed/metrics/interactive.js';
import pwaTrace from '../fixtures/traces/progressive-app-m60.json';
import pwaDevtoolsLog from '../fixtures/traces/progressive-app-m60.devtools.log.json';
import lcpTrace from '../fixtures/traces/lcp-m78.json';
import lcpDevtoolsLog from '../fixtures/traces/lcp-m78.devtools.log.json';
import lcpAllFramesTrace from '../fixtures/traces/frame-metrics-m89.json';
import lcpAllFramesDevtoolsLog from '../fixtures/traces/frame-metrics-m89.devtools.log.json'; // eslint-disable-line max-len
import clsAllFramesTrace from '../fixtures/traces/frame-metrics-m90.json';
import clsAllFramesDevtoolsLog from '../fixtures/traces/frame-metrics-m90.devtools.log.json'; // eslint-disable-line max-len
import jumpyClsTrace from '../fixtures/traces/jumpy-cls-m90.json';
import jumpyClsDevtoolsLog from '../fixtures/traces/jumpy-cls-m90.devtoolslog.json';
import {getURLArtifactFromDevtoolsLog} 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);
const lcpTrace = readJson('../fixtures/traces/lcp-m78.json', import.meta);
const lcpDevtoolsLog = readJson('../fixtures/traces/lcp-m78.devtools.log.json', import.meta);
const lcpAllFramesTrace = readJson('../fixtures/traces/frame-metrics-m89.json', import.meta);
const lcpAllFramesDevtoolsLog = readJson('../fixtures/traces/frame-metrics-m89.devtools.log.json', import.meta);
const clsAllFramesTrace = readJson('../fixtures/traces/frame-metrics-m90.json', import.meta);
const clsAllFramesDevtoolsLog = readJson('../fixtures/traces/frame-metrics-m90.devtools.log.json', import.meta);
const jumpyClsTrace = readJson('../fixtures/traces/jumpy-cls-m90.json', import.meta);
const jumpyClsDevtoolsLog = readJson('../fixtures/traces/jumpy-cls-m90.devtoolslog.json', import.meta);

describe('Performance: metrics', () => {
it('evaluates valid input correctly', async () => {
const URL = getURLArtifactFromDevtoolsLog(pwaDevtoolsLog);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +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 CumulativeLayoutShift from '../../../audits/metrics/cumulative-layout-shift.js';
import jumpyClsTrace from '../../fixtures/traces/jumpy-cls-m90.json';

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

describe('Cumulative Layout Shift', () => {
it('evaluates CLS correctly', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +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 ExperimentalInteractionToNextPaint from
'../../../audits/metrics/experimental-interaction-to-next-paint.js';
import interactionTrace from '../../fixtures/traces/timespan-responsiveness-m103.trace.json';
import noInteractionTrace from '../../fixtures/traces/jumpy-cls-m90.json';

const interactionTrace = readJson('../../fixtures/traces/timespan-responsiveness-m103.trace.json', import.meta);
const noInteractionTrace = readJson('../../fixtures/traces/jumpy-cls-m90.json', import.meta);

describe('Interaction to Next Paint', () => {
function getTestData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
* 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 pwaTrace from '../../fixtures/traces/progressive-app-m60.json';
import pwaDevtoolsLog from '../../fixtures/traces/progressive-app-m60.devtools.log.json';
import {getURLArtifactFromDevtoolsLog} 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);

const options = FCP3G.defaultOptions;

describe('Performance: first-contentful-paint-3g audit', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@

import {strict as assert} from 'assert';

import {readJson} from '../../../../root.js';
import FcpAudit from '../../../audits/metrics/first-contentful-paint.js';
import constants from '../../../config/constants.js';
import pwaTrace from '../../fixtures/traces/progressive-app-m60.json';
import pwaDevtoolsLog from '../../fixtures/traces/progressive-app-m60.devtools.log.json';
import frameTrace from '../../fixtures/traces/frame-metrics-m90.json';
import frameDevtoolsLog from '../../fixtures/traces/frame-metrics-m90.devtools.log.json';

const pwaTrace = readJson('../../fixtures/traces/progressive-app-m60.json', import.meta);
const pwaDevtoolsLog = readJson('../../fixtures/traces/progressive-app-m60.devtools.log.json', import.meta);
const frameTrace = readJson('../../fixtures/traces/frame-metrics-m90.json', import.meta);
const frameDevtoolsLog = readJson('../../fixtures/traces/frame-metrics-m90.devtools.log.json', import.meta);

const options = FcpAudit.defaultOptions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import {strict as assert} from 'assert';
import FMPAudit from '../../../audits/metrics/first-meaningful-paint.js';
import Audit from '../../../audits/audit.js';
import constants from '../../../config/constants.js';
import trace from '../../fixtures/traces/progressive-app-m60.json';
import devtoolsLogs from '../../fixtures/traces/progressive-app-m60.devtools.log.json';
import {getURLArtifactFromDevtoolsLog} from '../../test-utils.js';
import {readJson} from '../../../../root.js';

const trace = readJson('../../fixtures/traces/progressive-app-m60.json', import.meta);
const devtoolsLogs = readJson('../../fixtures/traces/progressive-app-m60.devtools.log.json', import.meta);

/**
* @param {{
Expand Down
10 changes: 6 additions & 4 deletions lighthouse-core/test/audits/metrics/interactive-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@

import {strict as assert} from 'assert';

import {readJson} from '../../../../root.js';
import Interactive from '../../../audits/metrics/interactive.js';
import constants from '../../../config/constants.js';
import acceptableTrace from '../../fixtures/traces/progressive-app-m60.json';
import acceptableDevToolsLog from '../../fixtures/traces/progressive-app-m60.devtools.log.json';
import redirectTrace from '../../fixtures/traces/site-with-redirect.json';
import redirectDevToolsLog from '../../fixtures/traces/site-with-redirect.devtools.log.json';

const acceptableTrace = readJson('../../fixtures/traces/progressive-app-m60.json', import.meta);
const acceptableDevToolsLog = readJson('../../fixtures/traces/progressive-app-m60.devtools.log.json', import.meta);
const redirectTrace = readJson('../../fixtures/traces/site-with-redirect.json', import.meta);
const redirectDevToolsLog = readJson('../../fixtures/traces/site-with-redirect.devtools.log.json', import.meta);

const options = Interactive.defaultOptions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
* 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 LCPAudit from '../../../audits/metrics/largest-contentful-paint.js';
import constants from '../../../config/constants.js';
import trace from '../../fixtures/traces/lcp-m78.json';
import devtoolsLog from '../../fixtures/traces/lcp-m78.devtools.log.json';
import preLcpTrace from '../../fixtures/traces/progressive-app-m60.json';
import preLcpDevtoolsLog from '../../fixtures/traces/progressive-app-m60.devtools.log.json';

const trace = readJson('../../fixtures/traces/lcp-m78.json', import.meta);
const devtoolsLog = readJson('../../fixtures/traces/lcp-m78.devtools.log.json', import.meta);
const preLcpTrace = readJson('../../fixtures/traces/progressive-app-m60.json', import.meta);
const preLcpDevtoolsLog = readJson('../../fixtures/traces/progressive-app-m60.devtools.log.json', import.meta);

const defaultOptions = LCPAudit.defaultOptions;

Expand Down
Loading

0 comments on commit 94b4f38

Please sign in to comment.