From 6859c5f6a183c65b15021ed6e342f6f83af21a87 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Wed, 12 Jun 2024 15:38:07 -0700 Subject: [PATCH] tests(lantern): refactor to DevTools test convention (#16072) --- .eslintignore | 2 ++ .../lantern/BaseNode.test.js} | 2 +- .../lantern/PageDependencyGraph.test.js} | 2 +- .../lantern/TBTUtils.test.js} | 2 +- .../metrics/FirstContentfulPaint.test.js} | 4 ++-- .../lantern/metrics/Interactive.test.js} | 4 ++-- .../metrics/LargestContentfulPaint.test.js} | 4 ++-- .../lib/lantern/metrics/MetricTestUtils.js | 4 ++-- .../lantern/metrics/SpeedIndex.test.js} | 4 ++-- .../first-contentful-paint-test.js.snap | 0 .../__snapshots__/interactive-test.js.snap | 0 .../lantern/simulation/ConnectionPool.test.js} | 2 +- .../lantern/simulation/DNSCache.test.js} | 2 +- .../simulation/NetworkAnalyzer.test.js} | 4 ++-- .../lantern/simulation/Simulator.test.js} | 6 +++--- .../lantern/simulation/TCPConnection.test.js} | 2 +- core/scripts/i18n/collect-strings.js | 1 + core/test/scripts/run-mocha-tests.js | 1 + tsconfig.json | 18 ++++++++++-------- 19 files changed, 35 insertions(+), 29 deletions(-) rename core/{test/lib/lantern/base-node-test.js => lib/lantern/BaseNode.test.js} (99%) rename core/{test/lib/lantern/page-dependency-graph-test.js => lib/lantern/PageDependencyGraph.test.js} (99%) rename core/{test/lib/lantern/tbt-utils-test.js => lib/lantern/TBTUtils.test.js} (98%) rename core/{test/lib/lantern/metrics/first-contentful-paint-test.js => lib/lantern/metrics/FirstContentfulPaint.test.js} (94%) rename core/{test/lib/lantern/metrics/interactive-test.js => lib/lantern/metrics/Interactive.test.js} (94%) rename core/{test/lib/lantern/metrics/lantern-largest-contentful-paint-test.js => lib/lantern/metrics/LargestContentfulPaint.test.js} (92%) rename core/{test => }/lib/lantern/metrics/MetricTestUtils.js (92%) rename core/{test/lib/lantern/metrics/speed-index-test.js => lib/lantern/metrics/SpeedIndex.test.js} (95%) rename core/{test => }/lib/lantern/metrics/__snapshots__/first-contentful-paint-test.js.snap (100%) rename core/{test => }/lib/lantern/metrics/__snapshots__/interactive-test.js.snap (100%) rename core/{test/lib/lantern/simulation/connection-pool-test.js => lib/lantern/simulation/ConnectionPool.test.js} (99%) rename core/{test/lib/lantern/simulation/dns-cache-test.js => lib/lantern/simulation/DNSCache.test.js} (97%) rename core/{test/lib/lantern/simulation/network-analyzer-test.js => lib/lantern/simulation/NetworkAnalyzer.test.js} (99%) rename core/{test/lib/lantern/simulation/simulator-test.js => lib/lantern/simulation/Simulator.test.js} (98%) rename core/{test/lib/lantern/simulation/tcp-connection-test.js => lib/lantern/simulation/TCPConnection.test.js} (99%) diff --git a/.eslintignore b/.eslintignore index b99210eb6e5b..22ee61dbab63 100644 --- a/.eslintignore +++ b/.eslintignore @@ -19,3 +19,5 @@ third-party/** **/*.d.cts page-functions-test-case*out*.js +# TODO(15841): remove when importing Lantern from npm +core/lib/lantern/**/*.test.js diff --git a/core/test/lib/lantern/base-node-test.js b/core/lib/lantern/BaseNode.test.js similarity index 99% rename from core/test/lib/lantern/base-node-test.js rename to core/lib/lantern/BaseNode.test.js index f8457e693e87..9f3bf1950b65 100644 --- a/core/test/lib/lantern/base-node-test.js +++ b/core/lib/lantern/BaseNode.test.js @@ -6,7 +6,7 @@ import assert from 'assert/strict'; -import * as Lantern from '../../../lib/lantern/lantern.js'; +import * as Lantern from './lantern.js'; const {BaseNode, NetworkNode} = Lantern; diff --git a/core/test/lib/lantern/page-dependency-graph-test.js b/core/lib/lantern/PageDependencyGraph.test.js similarity index 99% rename from core/test/lib/lantern/page-dependency-graph-test.js rename to core/lib/lantern/PageDependencyGraph.test.js index 03214e9661ed..efcf22883318 100644 --- a/core/test/lib/lantern/page-dependency-graph-test.js +++ b/core/lib/lantern/PageDependencyGraph.test.js @@ -6,7 +6,7 @@ import assert from 'assert/strict'; -import * as Lantern from '../../../lib/lantern/lantern.js'; +import * as Lantern from './lantern.js'; const {PageDependencyGraph, NetworkRequestTypes} = Lantern; diff --git a/core/test/lib/lantern/tbt-utils-test.js b/core/lib/lantern/TBTUtils.test.js similarity index 98% rename from core/test/lib/lantern/tbt-utils-test.js rename to core/lib/lantern/TBTUtils.test.js index a1bceecff2d7..cc7702e91aac 100644 --- a/core/test/lib/lantern/tbt-utils-test.js +++ b/core/lib/lantern/TBTUtils.test.js @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import * as Lantern from '../../../lib/lantern/lantern.js'; +import * as Lantern from './lantern.js'; const {calculateSumOfBlockingTime} = Lantern.TBTUtils; diff --git a/core/test/lib/lantern/metrics/first-contentful-paint-test.js b/core/lib/lantern/metrics/FirstContentfulPaint.test.js similarity index 94% rename from core/test/lib/lantern/metrics/first-contentful-paint-test.js rename to core/lib/lantern/metrics/FirstContentfulPaint.test.js index 5e91642edf12..b50be2de2087 100644 --- a/core/test/lib/lantern/metrics/first-contentful-paint-test.js +++ b/core/lib/lantern/metrics/FirstContentfulPaint.test.js @@ -6,8 +6,8 @@ import assert from 'assert/strict'; -import * as Lantern from '../../../../lib/lantern/lantern.js'; -import {readJson} from '../../../test-utils.js'; +import * as Lantern from '../lantern.js'; +import {readJson} from '../../../test/test-utils.js'; import {getComputationDataFromFixture} from './MetricTestUtils.js'; const {FirstContentfulPaint} = Lantern.Metrics; diff --git a/core/test/lib/lantern/metrics/interactive-test.js b/core/lib/lantern/metrics/Interactive.test.js similarity index 94% rename from core/test/lib/lantern/metrics/interactive-test.js rename to core/lib/lantern/metrics/Interactive.test.js index 742c6f9f3d15..1272c7cce151 100644 --- a/core/test/lib/lantern/metrics/interactive-test.js +++ b/core/lib/lantern/metrics/Interactive.test.js @@ -6,9 +6,9 @@ import assert from 'assert/strict'; -import * as Lantern from '../../../../lib/lantern/lantern.js'; +import * as Lantern from '../lantern.js'; import {getComputationDataFromFixture} from './MetricTestUtils.js'; -import {readJson} from '../../../test-utils.js'; +import {readJson} from '../../../test/test-utils.js'; const {Interactive, FirstContentfulPaint, LargestContentfulPaint} = Lantern.Metrics; diff --git a/core/test/lib/lantern/metrics/lantern-largest-contentful-paint-test.js b/core/lib/lantern/metrics/LargestContentfulPaint.test.js similarity index 92% rename from core/test/lib/lantern/metrics/lantern-largest-contentful-paint-test.js rename to core/lib/lantern/metrics/LargestContentfulPaint.test.js index 0a066de059d0..55d8136a8459 100644 --- a/core/test/lib/lantern/metrics/lantern-largest-contentful-paint-test.js +++ b/core/lib/lantern/metrics/LargestContentfulPaint.test.js @@ -6,9 +6,9 @@ import assert from 'assert/strict'; -import * as Lantern from '../../../../lib/lantern/lantern.js'; +import * as Lantern from '../lantern.js'; import {getComputationDataFromFixture} from './MetricTestUtils.js'; -import {readJson} from '../../../test-utils.js'; +import {readJson} from '../../../test/test-utils.js'; const {FirstContentfulPaint, LargestContentfulPaint} = Lantern.Metrics; diff --git a/core/test/lib/lantern/metrics/MetricTestUtils.js b/core/lib/lantern/metrics/MetricTestUtils.js similarity index 92% rename from core/test/lib/lantern/metrics/MetricTestUtils.js rename to core/lib/lantern/metrics/MetricTestUtils.js index c6a03ab5a520..5ac981e265f7 100644 --- a/core/test/lib/lantern/metrics/MetricTestUtils.js +++ b/core/lib/lantern/metrics/MetricTestUtils.js @@ -6,8 +6,8 @@ import * as TraceEngine from '@paulirish/trace_engine'; -import * as Lantern from '../../../../lib/lantern/lantern.js'; -import {polyfillDOMRect} from '../../../../lib/polyfill-dom-rect.js'; +import * as Lantern from '../lantern.js'; +import {polyfillDOMRect} from '../../polyfill-dom-rect.js'; polyfillDOMRect(); diff --git a/core/test/lib/lantern/metrics/speed-index-test.js b/core/lib/lantern/metrics/SpeedIndex.test.js similarity index 95% rename from core/test/lib/lantern/metrics/speed-index-test.js rename to core/lib/lantern/metrics/SpeedIndex.test.js index a7a53c336a68..bd48e0111604 100644 --- a/core/test/lib/lantern/metrics/speed-index-test.js +++ b/core/lib/lantern/metrics/SpeedIndex.test.js @@ -4,8 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -import * as Lantern from '../../../../lib/lantern/lantern.js'; -import {readJson} from '../../../test-utils.js'; +import * as Lantern from '../lantern.js'; +import {readJson} from '../../../test/test-utils.js'; import {getComputationDataFromFixture} from './MetricTestUtils.js'; const {SpeedIndex, FirstContentfulPaint} = Lantern.Metrics; diff --git a/core/test/lib/lantern/metrics/__snapshots__/first-contentful-paint-test.js.snap b/core/lib/lantern/metrics/__snapshots__/first-contentful-paint-test.js.snap similarity index 100% rename from core/test/lib/lantern/metrics/__snapshots__/first-contentful-paint-test.js.snap rename to core/lib/lantern/metrics/__snapshots__/first-contentful-paint-test.js.snap diff --git a/core/test/lib/lantern/metrics/__snapshots__/interactive-test.js.snap b/core/lib/lantern/metrics/__snapshots__/interactive-test.js.snap similarity index 100% rename from core/test/lib/lantern/metrics/__snapshots__/interactive-test.js.snap rename to core/lib/lantern/metrics/__snapshots__/interactive-test.js.snap diff --git a/core/test/lib/lantern/simulation/connection-pool-test.js b/core/lib/lantern/simulation/ConnectionPool.test.js similarity index 99% rename from core/test/lib/lantern/simulation/connection-pool-test.js rename to core/lib/lantern/simulation/ConnectionPool.test.js index e3a724371268..a0fd3b094dc5 100644 --- a/core/test/lib/lantern/simulation/connection-pool-test.js +++ b/core/lib/lantern/simulation/ConnectionPool.test.js @@ -7,7 +7,7 @@ import assert from 'assert/strict'; import {URL} from 'url'; -import * as Lantern from '../../../../lib/lantern/lantern.js'; +import * as Lantern from '../lantern.js'; const {ConnectionPool} = Lantern.Simulation; diff --git a/core/test/lib/lantern/simulation/dns-cache-test.js b/core/lib/lantern/simulation/DNSCache.test.js similarity index 97% rename from core/test/lib/lantern/simulation/dns-cache-test.js rename to core/lib/lantern/simulation/DNSCache.test.js index bbe372f0c852..b795193ed4be 100644 --- a/core/test/lib/lantern/simulation/dns-cache-test.js +++ b/core/lib/lantern/simulation/DNSCache.test.js @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import * as Lantern from '../../../../lib/lantern/lantern.js'; +import * as Lantern from '../lantern.js'; const {DNSCache} = Lantern.Simulation; diff --git a/core/test/lib/lantern/simulation/network-analyzer-test.js b/core/lib/lantern/simulation/NetworkAnalyzer.test.js similarity index 99% rename from core/test/lib/lantern/simulation/network-analyzer-test.js rename to core/lib/lantern/simulation/NetworkAnalyzer.test.js index 53e296ed9f67..e3f960d08779 100644 --- a/core/test/lib/lantern/simulation/network-analyzer-test.js +++ b/core/lib/lantern/simulation/NetworkAnalyzer.test.js @@ -6,8 +6,8 @@ import assert from 'assert/strict'; -import * as Lantern from '../../../../lib/lantern/lantern.js'; -import {readJson} from '../../../test-utils.js'; +import * as Lantern from '../lantern.js'; +import {readJson} from '../../../test/test-utils.js'; import {runTraceEngine} from '../metrics/MetricTestUtils.js'; const {NetworkAnalyzer} = Lantern.Simulation; diff --git a/core/test/lib/lantern/simulation/simulator-test.js b/core/lib/lantern/simulation/Simulator.test.js similarity index 98% rename from core/test/lib/lantern/simulation/simulator-test.js rename to core/lib/lantern/simulation/Simulator.test.js index 9f08ea28cea9..8b2975005324 100644 --- a/core/test/lib/lantern/simulation/simulator-test.js +++ b/core/lib/lantern/simulation/Simulator.test.js @@ -6,9 +6,9 @@ import assert from 'assert/strict'; -import * as Lantern from '../../../../lib/lantern/lantern.js'; -import {readJson} from '../../../test-utils.js'; -import {runTraceEngine} from '../metrics/MetricTestUtils.js'; +import * as Lantern from '../lantern.js'; +import {readJson} from '../../../test/test-utils.js'; +import {runTraceEngine} from '../../../test/lib/lantern/metrics/MetricTestUtils.js'; const {NetworkNode, CPUNode} = Lantern; const {Simulator, DNSCache} = Lantern.Simulation; diff --git a/core/test/lib/lantern/simulation/tcp-connection-test.js b/core/lib/lantern/simulation/TCPConnection.test.js similarity index 99% rename from core/test/lib/lantern/simulation/tcp-connection-test.js rename to core/lib/lantern/simulation/TCPConnection.test.js index 515b2cd2d76a..dcf2902822de 100644 --- a/core/test/lib/lantern/simulation/tcp-connection-test.js +++ b/core/lib/lantern/simulation/TCPConnection.test.js @@ -6,7 +6,7 @@ import assert from 'assert/strict'; -import * as Lantern from '../../../../lib/lantern/lantern.js'; +import * as Lantern from '../lantern.js'; const {TcpConnection} = Lantern.Simulation; diff --git a/core/scripts/i18n/collect-strings.js b/core/scripts/i18n/collect-strings.js index 6c6641f63552..a6ca66163757 100644 --- a/core/scripts/i18n/collect-strings.js +++ b/core/scripts/i18n/collect-strings.js @@ -50,6 +50,7 @@ const ignoredPathComponents = [ '**/core/lib/stack-packs.js', '**/test/**', '**/*-test.js', + '**/*.test.js', '**/*-renderer.js', '**/util-commonjs.js', 'treemap/app/src/main.js', diff --git a/core/test/scripts/run-mocha-tests.js b/core/test/scripts/run-mocha-tests.js index 7f0a88e2f20a..aef7edda22ee 100644 --- a/core/test/scripts/run-mocha-tests.js +++ b/core/test/scripts/run-mocha-tests.js @@ -171,6 +171,7 @@ const defaultTestMatches = [ 'cli/**/*-test.js', 'core/**/*-test.js', 'core/test/**/*-test-pptr.js', + 'core/lib/lantern/*.test.js', 'report/**/*-test.js', 'shared/**/*-test.js', 'third-party/**/*-test.js', diff --git a/tsconfig.json b/tsconfig.json index bda352ffb478..313808d4448c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -66,13 +66,15 @@ "core/test/lib/emulation-test.js", "core/test/lib/i18n/i18n-test.js", "core/test/lib/icons-test.js", - "core/test/lib/lantern/base-node-test.js", - "core/test/lib/lantern/metrics/*", - "core/test/lib/lantern/page-dependency-graph-test.js", - "core/test/lib/lantern/simulation/connection-pool-test.js", - "core/test/lib/lantern/simulation/dns-cache-test.js", - "core/test/lib/lantern/simulation/network-analyzer-test.js", - "core/test/lib/lantern/simulation/simulator-test.js", + // TODO(15841): remove when importing Lantern from npm + "core/lib/lantern/BaseNode.test.js", + "core/lib/lantern/metrics/*.test.js", + "core/lib/lantern/PageDependencyGraph.test.js", + "core/lib/lantern/simulation/ConnectionPool.test.js", + "core/lib/lantern/simulation/DNSCache.test.js", + "core/lib/lantern/simulation/NetworkAnalyzer.test.js", + "core/lib/lantern/simulation/Simulator.test.js", + // ------ done TODO "core/test/lib/lh-element-test.js", "core/test/lib/lighthouse-compatibility-test.js", "core/test/lib/manifest-parser-test.js", @@ -109,6 +111,6 @@ "core/test/computed/metrics/interactive-test.js", "core/test/computed/tbt-impact-tasks-test.js", "core/test/fixtures/config-plugins/lighthouse-plugin-simple/plugin-simple.js", - "core/test/lib/lantern/metrics/MetricTestUtils.js", + "core/lib/lantern/metrics/MetricTestUtils.js", ], }