-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Deno Doctest Support #6124
Deno Doctest Support #6124
Conversation
Formatted
* fix clippy errors * break extract_jsdoc_examples to smaller fns * fix error when ran without arguments
This is a really cool feature. Thanks! Rather than adding a new subcommand, can you make this "deno test --docs" instead? We're releasing v1.1.0 on June 13 - hopefully we'll be able to get this in before then. |
Okay, l will do that. |
* test: extract_jsdoc_examples * add more tests * formatting
let res = extract_jsdoc_examples(test.to_string(), PathBuf::from("user")); | ||
assert!(res.is_none()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice tests!
cli/doctest_runner.rs
Outdated
let mut import_set = HashSet::new(); | ||
|
||
let test_bodies = JS_DOC_PATTERN | ||
.captures_iter(&input) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm worried about the use of regex here. I'm fine for using regex to extract example code from jsdoc comments, but we have a complete TypeScript parser (SWC) built-in. We should be using this to extract the JSDocs. There should be examples of this in cli/doc/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently there is no way to recursively loop through DocNodes returned by the parser to get all the JSDocs but @bartlomieju promises to include the feature by next week. Should I go on with this or hold off till that feature is ready?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Impressive @iykekings! Here are initial thoughts on the patch. Please update manual entry for deno test
describing this feature.
Lots of heavy lifting is done using regexes, I wonder if @dsherret's Markdown parser could be used in the future to make extracting the code more robust.
@bartlomieju I think we need a JSDoc parser in swc. I was thinking about it over the weekend. Opened swc-project/swc#827 |
This PR is waiting for SWC to implement JSDoc parser(instead of using Regex). You can track the progress here swc-project/swc#829. |
A recent change in rustc or cargo made it so that rusty_v8's `build.rs`, which is responsible for downloading `librusty_v8.a`, does not get rebuilt or re-run when its build output directory is restored from the Github Actions cache. However, rusty_v8's custom build script does not save the download to its build output directory; it puts the file in `target/debug|release/gn_out/obj` instead. To get CI going again we opted to add `target/*/gn_out` to the Github Actions cache. A more robust fix would be make rusty_v8 save the download to the cargo-designated output directory.
This commit rewrites deno::Worker to not implement Future trait. Instead there are two separate methods: - Worker::poll_event_loop() - does single tick of event loop - Worker::run_event_loop() - runs event loop to completion Additionally some cleanup to Worker's field visibility was done.
Also re-export serde from deno_core, since its now a dependency.
* Revert "refactor: Worker is not a Future (denoland#7895)" This reverts commit f4357f0. * Revert "refactor(core): JsRuntime is not a Future (denoland#7855)" This reverts commit d8879fe. * Revert "fix(core): module execution with top level await (denoland#7672)" This reverts commit c7c7677.
continued in #7916 |
This PR adds
--docs
todeno test
sub-command for running tests on JSDoc @example blocks.To use:
sections with three back-ticks as in markdown code blocksdeno test --docs
runs all non-test filessrc/linkedlist.ts
https://deno.land/std/testing/asserts.ts
can be used without importing them in anassert object
. (assert.assert, assert.assertEquals, assert.assertNotEquals etc.)await
keyword can be used without wrapping in async function. NB: This is not due to TLA, butawait
will be detected in the example and the generated test is wrapped in an async function.To ignore test:
ignore
, and it will be picked up but not tested, will be recorded by Deno test as ignored.text
, and it will be seen as normal textThis is inspired by
rustdoc --test
Example output
Resolves #4716