Open gziolo opened 5 years ago
See this for inspiration https://github.com/hoaproject/Kitab (cc @Hywan)
@youknowriad shared also this npm package in our private discussion: https://yamadapc.github.io/jsdoctest It integrates with Mocha but provides the same functionality I was thinking about.
This would be great.
A few questions on specifics:
// =>
expected result could be used both for documentation and for constructing a test case. At the very least, from the provided proposal, the expected 3
value would be nice to include somewhere in the documented example.
- Would these expected results be included anywhere in the documentation? I actually quite like the jsdoctest example where the conventional
// =>
expected result could be used both for documentation and for constructing a test case. At the very least, from the provided proposal, the expected3
value would be nice to include somewhere in the documented example.
This seems like a great proposal as we could operate using @example
exclusively 👍
I will update the description according to your proposal.
- I wonder if we still might run the code for examples without the expected result, to at least check against runtime errors (which would be quite likely in cases where code has become outdated).
Yes, we totally could do that as well 👍
Related https://github.com/WordPress/gutenberg/pull/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.
It should be tackled after #21238 is merged.
Awesome, @sainthkh let me know when you have PR opened or is it that you wanted to highlight the dependency? 😄
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 https://github.com/WordPress/gutenberg/issues/15735#issuecomment-493971244 mentioned the // =>
convention. If we want to settle on this, we can already start to update existing code samples today, which would make future integration more seamless, and also bring some consistency to auto-documentation.
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 https://github.com/WordPress/gutenberg/issues/15735#issuecomment-493971244.
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: