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

test: [M3-7139] - Enable TypeScript typechecking in Cypress directory #10086

Merged
merged 30 commits into from
Jan 26, 2024

Conversation

jdamore-linode
Copy link
Contributor

@jdamore-linode jdamore-linode commented Jan 19, 2024

Description πŸ“

This updates the Cypress tsconfig.json file to allow typechecking against files in the Cypress directory, and fixes some TypeScript errors.

Changes πŸ”„

List any change relevant to the reviewer.

  • Extend Cypress's tsconfig from Manager's tsconfig, remove a lot of unneeded config
  • Fix various TypeScript issues
    • Removed lots of unused imports/consts/etc.
    • Added missing function param annotations
    • Fixed a couple issues where incorrect types or properties were specified
  • Update API-v4 CreateLinodeRequest interfaces property to accept InterfacePayload objects instead of Interface objects

How to test πŸ§ͺ

We can lean on the automated tests to make sure the e2e tests themselves aren't broken. I did make a really minor change to vite.config.ts, and any issues there should also manifest during the tests, but it might be good to build Cloud and give it a quick look just to make sure there are no unexpected issues.

To run typechecking against the Cypress code, you can run this command from within packages/manager:

yarn tsc -p cypress --noEmit

As an Author I have considered πŸ€”

Check all that apply

  • πŸ‘€ Doing a self review
  • ❔ Our contribution guidelines
  • 🀏 Splitting feature into small PRs
  • βž• Adding a changeset
  • πŸ§ͺ Providing/Improving test coverage
  • πŸ” Removing all sensitive information from the code and PR description
  • 🚩 Using a feature flag to protect the release
  • πŸ‘£ Providing comprehensive reproduction steps
  • πŸ“‘ Providing or updating our documentation
  • πŸ•› Scheduling a pair reviewing session
  • πŸ“± Providing mobile support
  • β™Ώ Providing accessibility support

@abailly-akamai
Copy link
Contributor

Thanks @jdamore-linode! This is exciting. Do you still need help to fix types in here? Happy to jump in in my leisurely time to help with the PR

@jdamore-linode
Copy link
Contributor Author

jdamore-linode commented Jan 22, 2024

Thanks @jdamore-linode! This is exciting. Do you still need help to fix types in here? Happy to jump in in my leisurely time to help with the PR

Thanks @abailly-akamai!

Just pushed changes that get the typecheck passing, although some of the fixes are pretty ugly and I'd love a second set of eyes on those in case there are opportunities to make things better/safer/etc. (And if you do see anything to improve, you're absolutely welcome to push improvements here)

Some examples of questionable fixes:

(Also CCing @bnussman-akamai since he normally advocates for increased type safety and I'd like to hear his opinion)

@jdamore-linode jdamore-linode marked this pull request as ready for review January 22, 2024 19:24
@jdamore-linode jdamore-linode requested review from a team as code owners January 22, 2024 19:24
@jdamore-linode jdamore-linode requested review from cliu-akamai, hana-linode and cpathipa and removed request for a team January 22, 2024 19:24
@@ -354,7 +354,7 @@ export interface CreateLinodeRequest {
tags?: string[];
private_ip?: boolean;
authorized_users?: string[];
interfaces?: Interface[];
interfaces?: InterfacePayload[];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I want to draw attention to this change in case it's incorrect. Without this change, I encountered type errors in the config test because TypeScript expected id and active properties to be specified when creating a Linode with Interfaces via the API SDK's createLinode function.

Copy link
Contributor

Choose a reason for hiding this comment

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

Linode API docs show active in the request payload (after VPC beta), but I have a feeling that it's supposed to be a read-only property? Anyways I think InterfacePayload is correct and id definitely shouldn't be in there.

Copy link

github-actions bot commented Jan 22, 2024

Coverage Report: βœ…
Base Coverage: 80.33%
Current Coverage: 80.33%

@hkhalil-akamai
Copy link
Contributor

hkhalil-akamai commented Jan 22, 2024

Wonder if we should add tsc -p cypress --noEmit to packages/manager/package.json:86, which currently looks like:

    "start": "concurrently --raw \"vite\" \"tsc --watch --preserveWatchOutput\"",

This might bring up any new type errors as team members are working on the cloud instead of having to run typechecks manually or relying on test failures.

Copy link
Contributor

@hkhalil-akamai hkhalil-akamai left a comment

Choose a reason for hiding this comment

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

Nice work on getting types working here, I'm confident this can help prevent some testing bugs in the future.

@bnussman-akamai
Copy link
Contributor

This is great! πŸŽ‰ You may have been use to it @jdamore-linode, but for me it was very frustrating working on the e2es without proper language server help! This is gonna be super nice and help me move faster πŸš€

Before After
Screen.Recording.2024-01-22.at.8.43.59.PM.mov
Screen.Recording.2024-01-22.at.8.44.50.PM.mov

I'm not too stressed about any of the "questionable fixes". I think we can iron those out over time.

Regarding what @hkhalil-akamai said about adding tsc to the start command, I'm personally fine without it, but I think I'd be okay with whatever. I think most of the value here for me is the proper language server auto-completion and whatnot as shown in the videos.

I'll continue reviewing and thinking over the changes!

Copy link
Contributor

@abailly-akamai abailly-akamai left a comment

Choose a reason for hiding this comment

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

Thanks @jdamore-linode - this is a great improvement.

Also agree we don't need the --watch as much here, but we can always change our mind

I pushed a few type improvements around any and type casting which I hope won't break anything!

// });
// const volume = await createVolume(volumeRequest);
// return [linode, volume];
// };
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add a comment as to commenting this out?

@jdamore-linode
Copy link
Contributor Author

jdamore-linode commented Jan 23, 2024

This is great! πŸŽ‰ You may have been use to it @jdamore-linode, but for me it was very frustrating working on the e2es without proper language server help!

@bnussman-akamai Interestingly, using Sublime Text with the lsp-typescript plugin, I always had (some) editor annotations which led me to assume that our setup was working as expected -- I'd get imports added automatically when I'd refer to api-v4 types, could see inline type docs when applicable, and so on. I was really surprised by some of the type mistakes that were revealed by this change!

@bnussman-akamai
Copy link
Contributor

@jdamore-linode Ahh, very interesting. In VSCode it seemed that things were partially working in general.

Copy link
Contributor

@bnussman-akamai bnussman-akamai left a comment

Choose a reason for hiding this comment

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

Awesome stuff πŸš€

Copy link
Contributor

@cpathipa cpathipa left a comment

Choose a reason for hiding this comment

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

Thank you @jdamore-linode Nice work!

@jdamore-linode jdamore-linode merged commit a8e51e7 into linode:develop Jan 26, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants