0.1.5 • Published 9 years ago

jsmd-tape v0.1.5

Weekly downloads
1
License
MIT
Repository
github
Last release
9 years ago

Rewrite code examples in Markdown code blocks as test assertions.

Turns this:

# Title of Your README.md

This is _Markdown_!

<!--javascript
  var additionModule = require('./');
-->

The above won't be rendered in HTML, such as on GitHub or npmjs.com,
but it will be included in the rewritten JavaScript.

The JavaScript expressions with comments that follow will be
rewritten as asssertions.

```javascript
additionmodule(1, 1); // => 2
additionmodule(2, 2); // => 4
```

into this:

var additionModule = require('./');
__jsmd__(2, additionModule(1, 1));
__jsmd__(4, additionModule(2, 2));

Command-Line Interface

$ npm install --global jsmd-rewrite
$ jsmd-rewrite --version
$ jsmd-rewrite --help
$ jsmd-rewrite README.md
$ cat README.md | jsmd-rewrite

Node.js

Install:

$ npm install --save jsmd-rewrite

Then:

var rewrite = require('jsmd-rewrite');
rewrite(markdown); // returns string
rewrite(markdown, assertionFunctionName); // returns string

The function name used for assertions is "__jsmd__" by default.

Testing README.md with jsmd-tape

For a package called "addition" do:

$ npm install --save-dev jsmd-tape tape

Then add to package.json:

{
  "scripts": {
    "test": "jsmd-tape README.md | sed 's!addition!./!' | node"
  }
}

The sed substitution allows you to write require() calls in code examples exactly as they will appear in user code:

```javascript
var add = require('addition')
add(1, 1) // => 2
```
0.1.5

9 years ago

0.1.4

9 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago