-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Auto-generated unit tests from JSDoc #15735
Comments
See this for inspiration https://github.com/hoaproject/Kitab (cc @Hywan) |
@youknowriad shared also this npm package in our private discussion: |
Also for inspiration: python has something like this. |
This would be great. A few questions on specifics:
|
This seems like a great proposal as we could operate using
Yes, we totally could do that as well 👍 |
Related #18031. StoryShots is very similar but for stories written for Storybook. This will solve the issue for UI components. |
It should be tackled after #21238 is merged. |
Actually both. I wanted to highlight the dependency to make sure some volunteers mistakenly try to implement this before #21238 is done. And I also want to tackle it myself, too. |
Even prior to implementing any automation, it seems like a related task would be to ensure there's consistency in the existing documentation for how these "expected results" values are notated. My earlier comment #15735 (comment) mentioned the |
It didn’t catch any attention so let’s close it as non-actionable. |
Description
We are using JSDoc's
@example
token as of today to include code examples with the usage of public API methods. The issue is that those examples can get out of date and it won't get noticed until someone reports it. I'd like us to seek to improve this workflow and introduce internal auto-generated unit tests for those examples which could also play a role of better documentation at the same time.Example:
Proposal
Update: Edited based on feedback from @aduth in #15735 (comment).
Add handling for the result of operation assigned to
result
constant in@example
JSDoc token:Behind the scenes, we would generate test files in a similar way we do it for documentation. In the case of
@wordpress/wordcount
package we could createpackages/wordcount/src/test/public-api.jsdoc.js
file, hoist and deduplicates all imports (we should allow only imports from WordPress packages for simplicity) and wrap everything else withdescription
andtest
. In addition, the code comment with return value would be used to create assertion matcher.Example:
The text was updated successfully, but these errors were encountered: