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

deno test should run jsdoc example code #4716

Closed
ry opened this issue Apr 11, 2020 · 8 comments · Fixed by #25220
Closed

deno test should run jsdoc example code #4716

ry opened this issue Apr 11, 2020 · 8 comments · Fixed by #25220
Labels
cli related to cli/ dir feat new feature (which has been agreed to/accepted) testing related to deno test and coverage

Comments

@ry
Copy link
Member

ry commented Apr 11, 2020

As cargo test does. This makes example code way more robust.

We’d need a way to extract all the examples - but now that we have deno doc - this should be not too difficult.

@ry ry added the feat new feature (which has been agreed to/accepted) label Apr 11, 2020
@akshatagarwl
Copy link
Contributor

@ry Can I work on this?

@ry
Copy link
Member Author

ry commented Apr 12, 2020

@humancalico Sure go for it. I'd start by defining an internal rust API for getting all of the code examples given a script's URL. Once that's working and tested, it should be just a bit more work to hook it into "deno test".

@akshatagarwl
Copy link
Contributor

@ry Should this be implemented directly for deno test or as a part of deno doc --test first? Kinda like Rust does it with rustdoc --test

@iykekings
Copy link

@humancalico and @ry what is the progress on this? I'm interested on working on it if nobody is on it.

@akshatagarwl
Copy link
Contributor

@iykekings I got sidetracked. Go ahead if you want to.😊

@bartlomieju
Copy link
Member

For posterity: we now support type-checking docstrings, running examples is still a TODO that @caspervonb was looking into

@waldyrious
Copy link
Contributor

we now support type-checking docstrings

For the record, that was done in #10521, and later #11421 extended that to also type-check code blocks within markdown files.

@linus
Copy link

linus commented Jan 11, 2023

I have published a module which could potentially handle this: https://deno.land/x/[email protected]

A couple of improvements I would like to make, but not sure how:

  1. It runs all tests using indirect eval in a Worker. It would feel better to implement this using something similar to Node's vm.runInContext.
  2. Currently, it doesn't automatically discover and run the @example, it needs to be wrapped in Deno.test((t) => doctest(t, file)) in a file under test. Any pointers on hooking it into deno test would be appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli related to cli/ dir feat new feature (which has been agreed to/accepted) testing related to deno test and coverage
Projects
None yet
7 participants