Détail du package

ferrum.doctest

adobe21Apache-2.01.0.5

Test the examples included in your documentation

readme

Ferrum Doctest

Ferrum.doctest allows you to test examples included in your documentation.

Did you every try an example from a project just to notice that it contains a syntax error? Did you ever avoid writing examples because it is extra work and you basically wrote the same code in your tests?

This is what ferrum.doctest is designed to solve! It parses your source code, extracts all the examples from your jsdoc and generates a file that can be executed with your test framework!

Using it

Install it:

$ npm install --only-dev ferrum.doctest

And execute your tests:

$ npx ferrum.doctest exec \
  -s src/ --mdsrc README.md \
  -c 'mocha --require source-map-support/register \"$DOCTEST_FILE\" test/'

The -s and --mdsrc indicate which source files/directories to scan for examples. The -c indicates your command to invoke tests. "$DOCTEST_FILE" is a variable indicating the location of the generated tests.

ferrum.doctest also features a generate command which just generates the tests without execting any actual tests. Invoke $ ferrum.doctest help for more information.

Selectively disabling tests

You can use the notest tag on code blocks inside markdown to disable testing that particular block

```notest
This will not be tested.
```

Other testing frameworks

You will have to provide a test file template for your particular testing framework.

$ npx ferrum.doctest exec \
  -t ./myJasmineTemplate.js.sqrl \
  -s src/ --mdsrc README.md \
  -c 'jasmine ...'

See defaultTemplate inside index.js.

Stack Traces/Source Maps

Ferrum.doctest automatically generates source maps. We use the source-map-support package to add support for them while testing.

Note that the mocha example above already provides support for source maps!

Unfortunately source maps currently do not work for syntax errors, but support for syntax errors is planned.

Using from javascript

Ferrum.doctest has an extensive api documentation. See index.js and the generateTests() function in particular.

Changelog

  • 1.0.0 Update to squirelly 8: The Render function is now called render; some other function names changed too. Variables passed to the render context are now addressed using it.<variable> in templates.

Build

$ npm install

Test

$ npm test

Lint

$ npm run lint

changelog

1.0.5 (2021-08-09)

Bug Fixes

1.0.4 (2021-05-18)

Bug Fixes

1.0.3 (2021-05-18)

Bug Fixes

1.0.2 (2021-05-04)

Bug Fixes

  • Downgrade documentationjs to 13.2.1 (bbaa1b9)

1.0.1 (2021-05-04)

Bug Fixes

  • deps: update dependency yargs to v17 (5e58390)
  • Who broke the build? Updates! (493a928)

1.0.0 (2021-05-04)

Features

1.4.1 (2019-10-08)

Bug Fixes

  • package: add descritpion (f56f59a)

1.4.0 (2019-10-07)

Features

1.3.0 (2019-08-27)

Bug Fixes

  • Ensure take supports multiple invocations and zero length (b5612cb)

Features

  • Add function repeatFn() (81de232)
  • Provide chunkify functions (9ff9603)
  • Provide takeShort() & takeWithFallback() (bafa834)
  • slidingWindow now returns an empty sequence if no=0 (533cff4)

1.2.2 (2019-07-11)

Bug Fixes

  • update all dependencies (2f3828b)

1.2.1 (2019-07-11)

Bug Fixes

  • Remove unnecessary dependency (7274bf2)

1.2.0 (2019-07-09)

Features

  • Bugfix: Support for objects with sequence (81ccc8c)

1.1.0 (2019-06-25)

Bug Fixes

  • Make sure test & eslint are not run on docs/ (8cd95d3)

Features

  • Provide assertSequenceEquals (7c0b4b8)

1.0.0 (2019-06-20)

Bug Fixes

  • docs: adjust jsdoc comments for better API readability (82e1f23)

Features

  • Extra functions for extracting values from sequences (b45a33e)
  • new function contains() (69e45db)
  • new functions cartesian, ifdef (bc72a25)