Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(driver): type check #10123

Merged
merged 14 commits into from
Jan 10, 2020
Merged

tests(driver): type check #10123

merged 14 commits into from
Jan 10, 2020

Conversation

connorjclark
Copy link
Collaborator

@connorjclark connorjclark commented Dec 17, 2019

Previous work: #6874

inspectablePromise.getDebugValues = () => ({resolvedValue, rejectionError});

return inspectablePromise;
return Object.assign(inspectablePromise, {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern allows type script to infer the type correctly, while not changing the prototype of the return value (it is still a Promise).

/**
* @template {keyof LH.CrdpCommands} C
* @param {C} command
* @param {RecursivePartial<LH.CrdpCommands[C]['returnType']>=} response
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test code often doesn't provide a full protocol response, so this makes everything optional (yet well-typed for the properties that are given).

@@ -28,8 +28,9 @@ declare global {

/** Make optional all properties on T and any properties on object properties of T. */
type RecursivePartial<T> = {
[P in keyof T]+?: T[P] extends object ?
RecursivePartial<T[P]> :
[P in keyof T]+?:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change adds array support.

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM so far, I'm sure you've done @brendankenny proud! :)

lighthouse-core/test/gather/driver-test.js Outdated Show resolved Hide resolved
lighthouse-core/test/gather/driver-test.js Outdated Show resolved Hide resolved
connect() {
return Promise.resolve();
}
disconnect() {
return Promise.resolve();
}
replayLog() {
redirectDevtoolsLog.forEach(msg => this.emit('protocolevent', msg));
// @ts-ignore
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this one isn't redirectDevtoolsLog any? ts-ignore explanation would be nice :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was given some ungodly mega inferred type. Fixed at the import level.

@@ -587,6 +604,7 @@ describe('.gotoURL', () => {
driver._waitForNetworkIdle = createMockWaitForFn();
driver._waitForCPUIdle = createMockWaitForFn();

// @ts-ignore
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this so we don't need to create an entire passcontext?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ya

lighthouse-core/test/gather/driver-test.js Outdated Show resolved Hide resolved
expect(connectionStub.sendCommand).toHaveBeenCalledTimes(1);
// Network still has one enable.

// @ts-ignore: Fetch is not in protocol typings yet.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can/should we update? or it's not even typed at all yet?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was gonna defer to #9459 but we can just update now

connectionStub.sendCommand = jest.fn()
.mockImplementationOnce(() => new Promise(r => setTimeout(r), 5000));
.mockImplementationOnce(() => new Promise(r => setTimeout(r, 5000)));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is why types are important

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm now very concerned how this was working before, wouldn't this have resolved immediately and we shouldn't have gotten protocol_timeout? 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#10135
tldr: microtasks

@connorjclark
Copy link
Collaborator Author

@patrickhulce anything else you'd like to see changed here?

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

return mockFn.mock.calls.find(call => call[0] === event)[1];
};
const mockFn = Object.assign(mockFnImpl, {
...mockFnImpl,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same q here

return mockFn.mock.calls.find(call => call[0] === event)[1];
};
const mockFn = Object.assign(mockFnImpl, {
...mockFnImpl,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we assigning its spread to itself?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how strange

@vercel vercel bot temporarily deployed to Preview January 10, 2020 21:04 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants