-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Research and implement a testing strategy for types provided through @carbon/react
#16361
Comments
@tay1orjones It is really nice to see TSTyche in the list. I am its author. Long story short, I was writing and contributing type tests to Jest repo for some time. At the moment there are more than 1000 assertions. Working at this scale was a pain with the available tooling. That is why I wrote TSTyche. For instance, at large scale there was a need to have Differently from all other type testing tools, TSTyche is wrapping around TypeScript’s language service. It allows per file queries instead of working with the whole TS program. And more. For example, another feature I am thinking about is an API which makes possible testing in memory generate files, i.e. passing arbitrary text to the compiler and asking for diagnostics (and/or processing type test assertions). If this sounds like the automation solution you are looking for, I am more than interested to collaborate. The implementation on TSTyche side is rather trivial. The To be honest, I never had a chance to work with component type tests. And that sounds even more interesting ;D |
Earlier today TSTyche 2.1 shipped with new |
@mrazauskas Thanks for popping in here! The features you listed are definitely intriguing and something we'll consider when we take up this work. |
Thank you for submitting a feature request. Your proposal is open and will soon be triaged by the Carbon team. |
Background
Once #12513 is fully complete, it would be beneficial if we had a way to be more confident in future changes to the component types. Specifically to ensure that types provided through
@carbon/react
follow the established Semantic Versioning guidelines for the package.Important
Types will continue to be provided on an as-is basis and remain exempt from semver for the forseeable future as we establish a more robust framework around maintaining types. Completing the work in this issue does not mean that we're able to bound types to semver.
Click to expand details
carbon/docs/guides/versioning.md
Lines 75 to 86 in b8701c9
Potential approaches
Snapshot the type interfaces
For component proptypes we have a very helpful setup where the proptypes for all components are collected and snapshotted into a single file, PublicAPI-test.js.snap. As changes to proptypes are made, the snapshot requires being updated, which shows up in the PR diff. This makes it really clear what's changing and makes it much easier to spot potential issues. We could attempt to mirror this setup in some way to provide more explicit visibility on every PR when a potentially semver-incompatible change is made to component types. The prominent solution for this would be to use https://api-extractor.com/
Implicitly test types in storybook
If we converted our story files to TypeScript we'd be "testing" the component types. It wouldn't cover all use cases but it would be a quick way to get closer to how an end user/consumer actually uses the types. It should only be slightly more overhead to write story files in typescript, and could encourage greater TypeScript familiarity amongst our community contributors.
Directly test the types
This approach has probably the most overhead. Options to research include:
Additional concerns
Related resources
Tasks
The text was updated successfully, but these errors were encountered: