All Projects → yamadapc → Jsdoctest

yamadapc / Jsdoctest

Licence: mit
Run jsdoc examples as doctests.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Jsdoctest

Parse Comments
Parse JavaScript code comments. Works with block and line comments, and should work with CSS, LESS, SASS, or any language with the same comment formats.
Stars: ✭ 53 (-33.75%)
Mutual labels:  documentation, jsdoc
Jsdoc
An API documentation generator for JavaScript.
Stars: ✭ 12,555 (+15593.75%)
Mutual labels:  documentation, jsdoc
Doxdox
📚 JSDoc to Markdown, Bootstrap, and custom Handlebars template documentation generator.
Stars: ✭ 139 (+73.75%)
Mutual labels:  documentation, jsdoc
Compodoc
📔 The missing documentation tool for your Angular, Nest & Stencil application
Stars: ✭ 3,567 (+4358.75%)
Mutual labels:  documentation, jsdoc
Documentation
📖 documentation for modern JavaScript
Stars: ✭ 5,443 (+6703.75%)
Mutual labels:  documentation, jsdoc
Tsdoc
A doc comment standard for TypeScript
Stars: ✭ 3,785 (+4631.25%)
Mutual labels:  documentation, jsdoc
Docma
A powerful tool to easily generate beautiful HTML documentation from JavaScript (JSDoc), Markdown and HTML files.
Stars: ✭ 287 (+258.75%)
Mutual labels:  documentation, jsdoc
Jsdoc Baseline
An experimental, extensible template for JSDoc.
Stars: ✭ 51 (-36.25%)
Mutual labels:  documentation, jsdoc
Jsdoc To Markdown
Generate markdown documentation from jsdoc-annotated javascript
Stars: ✭ 1,199 (+1398.75%)
Mutual labels:  documentation, jsdoc
Markdownmonster
An extensible Markdown Editor, Viewer and Weblog Publisher for Windows
Stars: ✭ 1,203 (+1403.75%)
Mutual labels:  documentation
Tiger
Tiger Compiler from "Modern Compiler Implementation in ML" by Andrew W. Appel
Stars: ✭ 77 (-3.75%)
Mutual labels:  compiler
Vab
V Android Bootstrapper
Stars: ✭ 77 (-3.75%)
Mutual labels:  compiler
Architecture Center
Azure Architecture Center
Stars: ✭ 1,207 (+1408.75%)
Mutual labels:  documentation
Kitab
Kitab is the ideal companion for Documentation-Driven Quality: Render and Test your documentation.
Stars: ✭ 79 (-1.25%)
Mutual labels:  documentation
Personalfilterlistcollection
Total resources of documentation, filterlists, hosts file, ruleset that I've created, mostly for private use and/or test.
Stars: ✭ 77 (-3.75%)
Mutual labels:  documentation
Vim Plugin Viewdoc
Vim plugin: flexible viewer for any documentation
Stars: ✭ 79 (-1.25%)
Mutual labels:  documentation
Rubyx
RubyX compiles ruby to binary (in ruby), hoping to be that X times faster
Stars: ✭ 78 (-2.5%)
Mutual labels:  compiler
Kit
Tools for developing, documenting, and testing React component libraries
Stars: ✭ 1,201 (+1401.25%)
Mutual labels:  documentation
Serverless Boilerplate
Serverless project template
Stars: ✭ 80 (+0%)
Mutual labels:  mocha
Fennel
Lua Lisp Language
Stars: ✭ 1,225 (+1431.25%)
Mutual labels:  compiler

jsdoctest

Build Status Coverage Status Stories in Ready Dependency Status devDependency Status npm downloads npm version Gitter


jsdoctest parses jsdoc @example tags from annotated functions and runs them as if they were doctests.

Inspired by the doctest python library, as well as its doctestjs javascript implementation.

Demo

demo

Set-up

Here's a two line set-up you can use:

$ npm i -g jsdoctest && jsdoctest --init
Adding `jsdoctest` script to your package.json...
Installing `mocha` and `jsdoctest` with npm:
# ... npm doing some work...
You can now run doctests with `npm run jsdoctest` or `npm test`

This will add sensible defaults to your package.json which you can then edit.

Test-case Format

Examples need to be valid javascript, followed by a comment with the string => prefixing the results:

/**
 * @example
 *   returns10()
 *   // => 10
 *   returns20()
 *   // => 20
 */

It doesn't matter if the comment is on the same line or the next one, so the following is also valid:

/**
 * @example
 *   returns10() // => 10
 *   returns20()
 *   // => 20
 */

Async test cases are supported prefixing the expected results with the async => string and pretending to have the cb callback function.

/**
 * @example
 *   takesCallbackAndYields10('here', cb)
 *   // async => 10
 *   takesCallbackAndYields20('here', cb)
 *   // async => 30
 */

Promises are also supported, just add the same // async => prefix and be sure not to use a variable named cb on your text expression.

/**
 * @example
 *   returnsPromiseThatYields10('here')
 *   // async => 10
 */

Examples

The examples directory has a couple of examples, which may be useful. Better documentation will be added if the project raises in complexity.

Usage

The recommended way of using jsdoctest is to use mocha. That is made possible with:

npm i mocha jsdoctest
mocha --require jsdoctest <module-name>

There's also a rudimentary command-line interface, which can be ran with:

npm i jsdoctest
jsdoctest <module-name>

Disabling

To disable running jsdoctests, while still requiring it with mocha (I don't know why, but you may) you can set the JSDOCTEST_DISABLE environment variable to anything (JSDOCTEST_DISABLE=true mocha --require...).

License

This code is licensed under the MIT license for Pedro Tacla Yamada. For more information, please refer to the LICENSE file.

Donations

Would you like to buy me a beer? Send bitcoin to 3JjxJydvoJjTrhLL86LGMc8cNB16pTAF3y

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].