Skip to content

Commit

Permalink
types in mockdriver
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed Apr 3, 2024
1 parent 512ec69 commit fa7da07
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion core/gather/navigation-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Check warning on line 97 in core/gather/navigation-runner.js

View check run for this annotation

Codecov / codecov/patch

core/gather/navigation-runner.js#L96-L97

Added lines #L96 - L97 were not covered by tests
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.
Expand Down
9 changes: 5 additions & 4 deletions core/test/gather/mock-driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand All @@ -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},

Expand Down
1 change: 1 addition & 0 deletions core/test/gather/session-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit fa7da07

Please sign in to comment.