Skip to content

Commit

Permalink
tests: update to typescript 3.9.7 (#11158)
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankenny authored Jul 27, 2020
1 parent 43042e1 commit 7d68521
Show file tree
Hide file tree
Showing 72 changed files with 205 additions and 194 deletions.
6 changes: 3 additions & 3 deletions build/build-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const locales = fs.readdirSync(__dirname + '/../lighthouse-core/lib/i18n/locales

// HACK: manually include the lighthouse-plugin-publisher-ads audits.
/** @type {Array<string>} */
// @ts-ignore
// @ts-expect-error
const pubAdsAudits = require('lighthouse-plugin-publisher-ads/plugin.js').audits.map(a => a.path);

/** @param {string} file */
Expand Down Expand Up @@ -84,7 +84,7 @@ async function browserifyFile(entryPath, distPath) {

// Don't include locales in DevTools.
if (isDevtools(entryPath)) {
// @ts-ignore bundle.ignore does accept an array of strings.
// @ts-expect-error bundle.ignore does accept an array of strings.
bundle.ignore(locales);
}

Expand Down Expand Up @@ -171,7 +171,7 @@ async function cli(argv) {
build(entryPath, distPath);
}

// @ts-ignore Test if called from the CLI or as a module.
// @ts-expect-error Test if called from the CLI or as a module.
if (require.main === module) {
cli(process.argv);
} else {
Expand Down
15 changes: 7 additions & 8 deletions clients/devtools-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,25 @@ if (typeof module !== 'undefined' && module.exports) {
// work for LH because of https://github.com/browserify/browserify/issues/968
// Instead, since this file is only ever run in node for testing, expose a
// bundle entry point as global.
// @ts-ignore
// @ts-expect-error
global.runBundledLighthouse = lighthouse;
}

// Expose only in DevTools' worker
// @ts-ignore
if (typeof self !== 'undefined') {
// TODO: refactor and delete `global.isDevtools`.
global.isDevtools = true;

// @ts-ignore
// @ts-expect-error
self.setUpWorkerConnection = setUpWorkerConnection;
// @ts-ignore
// @ts-expect-error
self.runLighthouse = lighthouse;
// @ts-ignore
// @ts-expect-error
self.createConfig = createConfig;
// @ts-ignore
// @ts-expect-error
self.listenForStatus = listenForStatus;
// @ts-ignore
// @ts-expect-error
self.registerLocaleData = registerLocaleData;
// @ts-ignore
// @ts-expect-error
self.lookupLocale = lookupLocale;
}
2 changes: 1 addition & 1 deletion clients/devtools-report-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

/* global Runtime */

// @ts-ignore: Runtime.cachedResources exists in Devtools. https://source.chromium.org/chromium/chromium/src/+/master:third_party/devtools-frontend/src/front_end/root/Runtime.js;l=1169
// @ts-expect-error: Runtime.cachedResources exists in Devtools. https://source.chromium.org/chromium/chromium/src/+/master:third_party/devtools-frontend/src/front_end/root/Runtime.js;l=1169
const cachedResources = Runtime.cachedResources;

// Getters are necessary because the DevTools bundling processes
Expand Down
2 changes: 1 addition & 1 deletion clients/lightrider/lightrider-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,6 @@ if (typeof module !== 'undefined' && module.exports) {

// Expose on window for browser-residing consumers of file.
if (typeof window !== 'undefined') {
// @ts-ignore
// @ts-expect-error - not worth typing a property on `window`.
window.runLighthouseInLR = runLighthouseInLR;
}
6 changes: 3 additions & 3 deletions lighthouse-cli/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ async function begin() {
cliFlags.outputPath = 'stdout';
}

// @ts-ignore - deprecation message for removed disableDeviceEmulation; can remove warning in v6.
// @ts-expect-error - deprecation message for removed disableDeviceEmulation; can remove warning in v6.
if (cliFlags.disableDeviceEmulation) {
log.warn('config', 'The "--disable-device-emulation" has been removed in v5.' +
' Please use "--emulated-form-factor=none" instead.');
Expand All @@ -107,8 +107,8 @@ async function begin() {
// copied over to LH.Settings.extraHeaders, which is LH.Crdp.Network.Headers. Force
// the conversion here, but long term either the CLI flag or the setting should have
// a different name.
// @ts-ignore
let extraHeadersStr = /** @type {string} */ (cliFlags.extraHeaders);
/** @type {string} */
let extraHeadersStr = cliFlags.extraHeaders;
// If not a JSON object, assume it's a path to a JSON file.
if (extraHeadersStr.substr(0, 1) !== '{') {
extraHeadersStr = fs.readFileSync(extraHeadersStr, 'utf-8');
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-cli/cli-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function flatten(arr) {
* @return {LH.CliFlags}
*/
function getFlags(manualArgv) {
// @ts-ignore yargs() is incorrectly typed as not accepting a single string.
// @ts-expect-error yargs() is incorrectly typed as not accepting a single string.
const y = manualArgv ? yargs(manualArgv) : yargs;
// Intentionally left as type `any` because @types/yargs doesn't chain correctly.
const argv = y.help('help')
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-cli/sentry-prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function prompt() {

const timeoutPromise = new Promise((resolve) => {
timeout = setTimeout(() => {
// @ts-ignore Promise returned by prompt is decorated with `ui`
// @ts-expect-error Promise returned by prompt is decorated with `ui`
prompt.ui.close();
process.stdout.write('\n');
log.warn('CLI', 'No response to error logging preference, errors will not be reported.');
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-cli/test/cli/bin-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ describe('CLI bin', function() {

describe('extraHeaders', () => {
it('should convert extra headers to object', async () => {
// @ts-ignore - see TODO: in bin.js
// @ts-expect-error - see TODO: in bin.js
cliFlags = {...cliFlags, extraHeaders: '{"foo": "bar"}'};
await bin.begin();

Expand All @@ -156,7 +156,7 @@ describe('CLI bin', function() {

it('should read extra headers from file', async () => {
const headersFile = require.resolve('../fixtures/extra-headers/valid.json');
// @ts-ignore - see TODO: in bin.js
// @ts-expect-error - see TODO: in bin.js
cliFlags = {...cliFlags, extraHeaders: headersFile};
await bin.begin();

Expand Down
4 changes: 2 additions & 2 deletions lighthouse-cli/test/cli/cli-flags-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ describe('CLI bin', function() {
getFlags('chrome://version');
const yargs = require('yargs');

// @ts-ignore - getGroups is private
// @ts-expect-error - getGroups is private
const optionGroups = yargs.getGroups();
/** @type {string[]} */
const allOptions = [];
Object.keys(optionGroups).forEach(key => {
allOptions.push(...optionGroups[key]);
});
// @ts-ignore - getUsageInstance is private
// @ts-expect-error - getUsageInstance is private
const optionsWithDescriptions = Object.keys(yargs.getUsageInstance().getDescriptions());

allOptions.forEach(opt => {
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-cli/test/smokehouse/lighthouse-runners/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ const ChromeLauncher = require('chrome-launcher');
const ChromeProtocol = require('../../../../lighthouse-core/gather/connections/cri.js');

// Load bundle, which creates a `global.runBundledLighthouse`.
// @ts-ignore - file won't exist until `yarn build-all`, but not used for types anyways.
// @ts-ignore - file exists if `yarn build-all` is run, but not used for types anyways.
require('../../../../dist/lighthouse-dt-bundle.js'); // eslint-disable-line

/** @type {import('../../../../lighthouse-core/index.js')} */
// @ts-ignore - not worth giving test global an actual type.
// @ts-expect-error - not worth giving test global an actual type.
const lighthouse = global.runBundledLighthouse;

/**
Expand Down
6 changes: 3 additions & 3 deletions lighthouse-cli/test/smokehouse/report-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,9 @@ function isPlainObject(obj) {
* @param {Comparison} assertion
*/
function reportAssertion(localConsole, assertion) {
// @ts-ignore - this doesn't exist now but could one day, so try not to break the future
// @ts-expect-error - this doesn't exist now but could one day, so try not to break the future
const _toJSON = RegExp.prototype.toJSON;
// @ts-ignore
// @ts-expect-error
// eslint-disable-next-line no-extend-native
RegExp.prototype.toJSON = RegExp.prototype.toString;

Expand Down Expand Up @@ -312,7 +312,7 @@ function reportAssertion(localConsole, assertion) {
}
}

// @ts-ignore
// @ts-expect-error
// eslint-disable-next-line no-extend-native
RegExp.prototype.toJSON = _toJSON;
}
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/byte-efficiency/offscreen-images.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class OffscreenImages extends ByteEfficiencyAudit {
// Filter out images that were loaded after all CPU activity
items = context.settings.throttlingMethod === 'simulate' ?
OffscreenImages.filterLanternResults(unfilteredResults, lanternInteractive) :
// @ts-ignore - .timestamp will exist if throttlingMethod isn't lantern
// @ts-expect-error - .timestamp will exist if throttlingMethod isn't lantern
OffscreenImages.filterObservedResults(unfilteredResults, interactive.timestamp);
} catch (err) {
// if the error is during a Lantern run, end of trace may also be inaccurate, so rethrow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,14 @@ class RenderBlockingResources extends Audit {
const wastedCssBytes = await RenderBlockingResources.computeWastedCSSBytes(artifacts, context);

const metricSettings = {throttlingMethod: 'simulate'};

/** @type {LH.Artifacts.MetricComputationData} */
// @ts-expect-error - TODO(bckenny): allow optional `throttling` settings
const metricComputationData = {trace, devtoolsLog, simulator, settings: metricSettings};
// @ts-ignore - TODO(bckenny): allow optional `throttling` settings
const fcpSimulation = await FirstContentfulPaint.request(metricComputationData, context);

// Cast to just `LanternMetric` since we explicitly set `throttlingMethod: 'simulate'`.
const fcpSimulation = /** @type {LH.Artifacts.LanternMetric} */
(await FirstContentfulPaint.request(metricComputationData, context));
const fcpTsInMs = traceOfTab.timestamps.firstContentfulPaint / 1000;

const nodesByUrl = getNodesAndTimingByUrl(fcpSimulation.optimisticEstimate.nodeTimings);
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/font-display.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class FontDisplay extends Audit {

// Finally convert the raw font URLs to the absolute URLs and add them to the set.
const relativeURLs = rawFontURLs
// @ts-ignore - guaranteed to match from previous regex, pull URL group out
// @ts-expect-error - guaranteed to match from previous regex, pull URL group out
.map(s => s.match(CSS_URL_REGEX)[1].trim())
.map(s => {
// remove any quotes surrounding the URL
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/predictive-perf.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class PredictivePerf extends Audit {
const trace = artifacts.traces[Audit.DEFAULT_PASS];
const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
/** @type {LH.Config.Settings} */
// @ts-ignore - TODO(bckenny): allow optional `throttling` settings
// @ts-expect-error - TODO(bckenny): allow optional `throttling` settings
const settings = {}; // Use default settings.
const fcp = await LanternFcp.request({trace, devtoolsLog, settings}, context);
const fmp = await LanternFmp.request({trace, devtoolsLog, settings}, context);
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/screenshot-thumbnails.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class ScreenshotThumbnails extends Audit {
const targetTimestamp = speedline.beginning + timelineEnd * i / NUMBER_OF_THUMBNAILS;

/** @type {SpeedlineFrame} */
// @ts-ignore - there will always be at least one frame by this point. TODO: use nonnullable assertion in TS2.9
// @ts-expect-error - there will always be at least one frame by this point. TODO: use nonnullable assertion in TS2.9
let frameForTimestamp = null;
if (i === NUMBER_OF_THUMBNAILS) {
frameForTimestamp = analyzedFrames[analyzedFrames.length - 1];
Expand Down
10 changes: 5 additions & 5 deletions lighthouse-core/audits/seo/hreflang.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ const str_ = i18n.createMessageInstanceIdFn(__filename, UIStrings);
* @return {Array<string>}
*/
function importValidLangs() {
// @ts-ignore - global switcheroo to load axe valid-langs
// @ts-expect-error - global switcheroo to load axe valid-langs
const axeCache = global.axe;
// @ts-ignore
// @ts-expect-error
global.axe = {utils: {}};
// @ts-ignore
// @ts-expect-error
require('axe-core/lib/core/utils/valid-langs.js');
// @ts-ignore
// @ts-expect-error
const validLangs = global.axe.utils.validLangs();
// @ts-ignore
// @ts-expect-error
global.axe = axeCache;

return validLangs;
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/uses-rel-preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class UsesRelPreloadAudit extends Audit {
// Once we've modified the dependencies, simulate the new graph with flexible ordering.
const simulationAfterChanges = simulator.simulate(modifiedGraph, {flexibleOrdering: true});
const originalNodesByRecord = Array.from(simulationBeforeChanges.nodeTimings.keys())
// @ts-ignore we don't care if all nodes without a record collect on `undefined`
// @ts-expect-error we don't care if all nodes without a record collect on `undefined`
.reduce((map, node) => map.set(node.record, node), new Map());

const results = [];
Expand Down
6 changes: 3 additions & 3 deletions lighthouse-core/computed/js-bundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ function computeGeneratedFileSizes(map, content) {
// denotes nothing is mapped.
const failureResult = {files: {}, unmappedBytes, totalBytes};

// @ts-ignore: This function is added in SDK.js. This will eventually be added to CDT.
// @ts-expect-error: This function is added in SDK.js. This will eventually be added to CDT.
map.computeLastGeneratedColumns();

for (const mapping of map.mappings()) {
const source = mapping.sourceURL;
const lineNum = mapping.lineNumber;
const colNum = mapping.columnNumber;
// @ts-ignore: `lastColumnNumber` is not on types yet. This will eventually be added to CDT.
// @ts-expect-error: `lastColumnNumber` is not on types yet. This will eventually be added to CDT.
const lastColNum = /** @type {number=} */ (mapping.lastColumnNumber);

// Webpack sometimes emits null mappings.
Expand Down Expand Up @@ -99,7 +99,7 @@ class JSBundles {

const compiledUrl = SourceMap.scriptUrl || 'compiled.js';
const mapUrl = SourceMap.sourceMapUrl || 'compiled.js.map';
// @ts-ignore: CDT expects undefined properties to be explicit.
// Hack: CDT expects undefined properties to be explicit.
const rawMapForCdt = /** @type {any} */ (rawMap);
const map = new SDK.TextSourceMap(compiledUrl, mapUrl, rawMapForCdt);

Expand Down
18 changes: 9 additions & 9 deletions lighthouse-core/computed/page-dependency-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,12 @@ class PageDependencyGraph {

switch (evt.name) {
case 'TimerInstall':
// @ts-ignore - 'TimerInstall' event means timerId exists.
// @ts-expect-error - 'TimerInstall' event means timerId exists.
timers.set(evt.args.data.timerId, node);
stackTraceUrls.forEach(url => addDependencyOnUrl(node, url));
break;
case 'TimerFire': {
// @ts-ignore - 'TimerFire' event means timerId exists.
// @ts-expect-error - 'TimerFire' event means timerId exists.
const installer = timers.get(evt.args.data.timerId);
if (!installer || installer.endTime > node.startTime) break;
installer.addDependent(node);
Expand All @@ -273,37 +273,37 @@ class PageDependencyGraph {

case 'EvaluateScript':
addDependencyOnFrame(node, evt.args.data.frame);
// @ts-ignore - 'EvaluateScript' event means argsUrl is defined.
// @ts-expect-error - 'EvaluateScript' event means argsUrl is defined.
addDependencyOnUrl(node, argsUrl);
stackTraceUrls.forEach(url => addDependencyOnUrl(node, url));
break;

case 'XHRReadyStateChange':
// Only create the dependency if the request was completed
// @ts-ignore - 'XHRReadyStateChange' event means readyState is defined.
// 'XHRReadyStateChange' event means readyState is defined.
if (evt.args.data.readyState !== 4) break;

// @ts-ignore - 'XHRReadyStateChange' event means argsUrl is defined.
// @ts-expect-error - 'XHRReadyStateChange' event means argsUrl is defined.
addDependencyOnUrl(node, argsUrl);
stackTraceUrls.forEach(url => addDependencyOnUrl(node, url));
break;

case 'FunctionCall':
case 'v8.compile':
addDependencyOnFrame(node, evt.args.data.frame);
// @ts-ignore - events mean argsUrl is defined.
// @ts-expect-error - events mean argsUrl is defined.
addDependencyOnUrl(node, argsUrl);
break;

case 'ParseAuthorStyleSheet':
addDependencyOnFrame(node, evt.args.data.frame);
// @ts-ignore - 'ParseAuthorStyleSheet' event means styleSheetUrl is defined.
// @ts-expect-error - 'ParseAuthorStyleSheet' event means styleSheetUrl is defined.
addDependencyOnUrl(node, evt.args.data.styleSheetUrl);
break;

case 'ResourceSendRequest':
addDependencyOnFrame(node, evt.args.data.frame);
// @ts-ignore - 'ResourceSendRequest' event means requestId is defined.
// @ts-expect-error - 'ResourceSendRequest' event means requestId is defined.
addDependentNetworkRequest(node, evt.args.data.requestId);
stackTraceUrls.forEach(url => addDependencyOnUrl(node, url));
break;
Expand Down Expand Up @@ -432,7 +432,7 @@ class PageDependencyGraph {
const length = Math.ceil((node.endTime - node.startTime) / timePerCharacter);
const bar = padRight('', offset) + padRight('', length, '=');

// @ts-ignore -- disambiguate displayName from across possible Node types.
// @ts-expect-error -- disambiguate displayName from across possible Node types.
const displayName = node.record ? node.record.url : node.type;
// eslint-disable-next-line
console.log(padRight(bar, widthInCharacters), `| ${displayName.slice(0, 30)}`);
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/computed/unused-javascript-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ class UnusedJavascriptSummary {
return retVal;
});

// @ts-ignore: We will upstream computeLastGeneratedColumns to CDT eventually.
// @ts-expect-error: We will upstream computeLastGeneratedColumns to CDT eventually.
bundle.map.computeLastGeneratedColumns();
for (const mapping of bundle.map.mappings()) {
let offset = lineOffsets[mapping.lineNumber];

offset += mapping.columnNumber;
const lastColumnOfMapping =
// @ts-ignore: We will upstream lastColumnNumber to CDT eventually.
// @ts-expect-error: We will upstream lastColumnNumber to CDT eventually.
(mapping.lastColumnNumber - 1) || lineLengths[mapping.lineNumber];
for (let i = mapping.columnNumber; i <= lastColumnOfMapping; i++) {
if (wasteData.every(data => data.unusedByIndex[offset] === 1)) {
Expand Down
Loading

0 comments on commit 7d68521

Please sign in to comment.