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

Convert NetworkController unit tests to TypeScript #18476

Merged
merged 59 commits into from
Apr 12, 2023

Conversation

mcmire
Copy link
Contributor

@mcmire mcmire commented Apr 5, 2023

Explanation

This helps us more easily compare the unit tests for NetworkController in this repo and the NetworkController in the core repo.

Closes #18424.

Manual Testing Steps

No functional changes. All tests should pass.

Pre-merge author checklist

  • I've clearly explained:
    • What problem this PR is solving
    • How this problem was solved
    • How reviewers can test my changes
  • Sufficient automated test coverage has been added

Pre-merge reviewer checklist

  • Manual testing (e.g. pull and build branch, run in browser, test code being changed)
  • PR is linked to the appropriate GitHub issue
  • IF this PR fixes a bug in the release milestone, add this PR to the release milestone

If further QA is required (e.g. new feature, complex testing steps, large refactor), add the Extension QA Board label.

In this case, a QA Engineer approval will be be required.

mcmire and others added 30 commits March 28, 2023 11:58
We want to convert NetworkController to TypeScript in order to be able
to compare differences in the controller between in this repo and the
core repo. To do this, however, we need to convert the dependencies of
the controller to TypeScript.

As a part of this effort, this commit converts
`shared/constants/metametrics` to TypeScript. Note that simple objects
have been largely replaced with enums. There are some cases where I even
split up some of these objects into multiple enums.
Co-authored-by: Mark Stacey <[email protected]>
Co-authored-by: Mark Stacey <[email protected]>
Co-authored-by: Mark Stacey <[email protected]>
Co-authored-by: Mark Stacey <[email protected]>
Co-authored-by: Mark Stacey <[email protected]>
Co-authored-by: Mark Stacey <[email protected]>
- There are several categories of event sources. Rearrange the constant
  names to accentuate this. For instance, `MetaMetricsEventNetworkSource`
  would seem (when reading this as English) to indicate that we have a
  "network source" that is related to a MetaMetrics event. But really,
  it's a MetaMetrics event source that we've classified under "network".
- An external link type is just a link type (according to how it's
  used). There is no other kind of link type. Rename this constant
  accordingly.
- We don't include "properties" in the name of the types. For instance a
  key type is passed as a property, but we just call the type
  `MetaMetricsEventKeyType`. Rename
  `MetaMetricsEventUiCustomizationPropertyValue` accordingly.
Converting this controller to TypeScript furthers the goal of getting
this whole codebase converted, of course, but it also helps in comparing
the differences between this version of the NetworkController and the
version in the `core` repo more easily, which will ultimately help us in
coalescing the two implementations.
Base automatically changed from convert-network-controller-to-ts to develop April 11, 2023 16:07
@mcmire mcmire removed the DO-NOT-MERGE Pull requests that should not be merged label Apr 11, 2023
@metamaskbot
Copy link
Collaborator

Builds ready [b5402a6]
Page Load Metrics (1780 ± 83 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1002791374722
domContentLoaded14582011175516479
load14772073178017383
domInteractive14582011175516479
Bundle size diffs
  • background: 0 bytes
  • ui: 0 bytes
  • common: 0 bytes

}): Promise<E['payload'][]> {
const promiseForEventPayloads = new Promise<E['payload'][]>(
(resolve, reject) => {
// Everything depends on `eventListener` circularly, so we need to declare
Copy link
Member

Choose a reason for hiding this comment

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

Nit: This could be simplifed by using a function declaration for end, stopTimer, and resetTimer. Function declarations make circular references easier to handle due to function hoisting; the declaration is hoisted to the top of the scope, so they can be referenced before the declaration.

That lets use const when defining the event listener, and saves us from needing this comment to explain the awkward order of operations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm you're right! I notice the same thing happens in waitForStateChanges but I'll fix that later. But I can fix this one now: 45f001b

@metamaskbot
Copy link
Collaborator

Builds ready [f27584c]
Page Load Metrics (1693 ± 69 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint92160119189
domContentLoaded15242018167614972
load15242019169314369
domInteractive15242018167614972
Bundle size diffs
  • background: 0 bytes
  • ui: 0 bytes
  • common: 0 bytes

Gudahtt
Gudahtt previously approved these changes Apr 12, 2023
Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM! A few comments/suggestions remaining but no blockers

Comment on lines +518 to +519
* @param args.infuraProjectId - TODO.
* @param args.infuraNetwork - TODO.
Copy link
Contributor

Choose a reason for hiding this comment

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

what are these TODO comments for? 👀

@mcmire

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, good catch, thanks. Fortunately I'm going to update this test file again in another PR very soon so I will address them then.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@digiwand digiwand left a comment

Choose a reason for hiding this comment

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

LGTM! nice cleanup with the conversion and thanks for the helpful comments

small, non-blocking question in regards to 2 TODO comments

@metamaskbot
Copy link
Collaborator

Builds ready [ace10d6]
Page Load Metrics (1553 ± 31 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint90133105115
domContentLoaded1419165915327234
load1427165915536431
domInteractive1419165915327234
Bundle size diffs
  • background: 0 bytes
  • ui: 0 bytes
  • common: 0 bytes

@mcmire mcmire merged commit 6439551 into develop Apr 12, 2023
@mcmire mcmire deleted the convert-network-controller-tests-to-ts branch April 12, 2023 19:53
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Convert NetworkController unit tests to TypeScript
5 participants