From 9fd788eca42bfdca12807fc7c1128d174e4b4182 Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Tue, 2 Apr 2024 19:02:10 -0700 Subject: [PATCH] types in mockdriver --- core/gather/navigation-runner.js | 4 +++- core/runner.js | 1 - core/test/gather/mock-driver.js | 9 +++++---- core/test/gather/session-test.js | 1 + 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/core/gather/navigation-runner.js b/core/gather/navigation-runner.js index 33fef1f139c8..dcd79e97b208 100644 --- a/core/gather/navigation-runner.js +++ b/core/gather/navigation-runner.js @@ -92,7 +92,9 @@ async function _navigate(navigationContext) { return {requestedUrl, mainDocumentUrl, navigationError: undefined}; } catch (err) { if (!(err instanceof LighthouseError)) throw err; - if (err.code !== 'NO_FCP' && err.code !== 'PAGE_HUNG' && err.code !== 'TARGET_CRASHED') throw err; + if (err.code !== 'NO_FCP' && err.code !== 'PAGE_HUNG' && err.code !== 'TARGET_CRASHED') { + throw err; + } if (typeof requestor !== 'string') throw err; // TODO: Make the urls optional here so we don't need to throw an error with a callback requestor. diff --git a/core/runner.js b/core/runner.js index 41a6e10bc8d0..819030b71236 100644 --- a/core/runner.js +++ b/core/runner.js @@ -199,7 +199,6 @@ class Runner { data: sentryContext, }); - // /** @type {LH.Artifacts} */ if (settings.auditMode && !settings.gatherMode) { // No browser required, just load the artifacts from disk. const path = this._getDataSavePath(settings); diff --git a/core/test/gather/mock-driver.js b/core/test/gather/mock-driver.js index d3f88dbfaf8a..840461bcd232 100644 --- a/core/test/gather/mock-driver.js +++ b/core/test/gather/mock-driver.js @@ -157,8 +157,9 @@ function createMockDriver() { const context = createMockExecutionContext(); const targetManager = createMockTargetManager(session); - // our `fatalRejection` - let rej; + // The `fatalRejection` + /** @param {any} _ */ + let rej = _ => {}; const promise = new Promise((_, theRej) => { rej = theRej; }); @@ -177,8 +178,8 @@ function createMockDriver() { fetchResource: fnAny(), }, networkMonitor: new NetworkMonitor(targetManager.asTargetManager()), - listenForCrashes: session.on('Inspector.targetCrashed', _ => { - rej(new Error('TARGETCRAHSZHZD')); + listenForCrashes: session.on('Inspector.targetCrashed', () => { + rej(new Error('TARGET_CRASHED')); }), fatalRejection: {promise, rej}, diff --git a/core/test/gather/session-test.js b/core/test/gather/session-test.js index a0c63c68686b..b69818917ce8 100644 --- a/core/test/gather/session-test.js +++ b/core/test/gather/session-test.js @@ -104,6 +104,7 @@ describe('ProtocolSession', () => { describe('.dispose', () => { it('should detach from the session', async () => { const detach = fnAny(); + detach.mockResolvedValue(undefined); class MockCdpSession extends EventEmitter { constructor() { super();