babel-plugin-transform-comment-to-assert
Replace commented expressions with assert statements
Last updated 5 months ago by laat .
MIT · Repository · Original npm · Tarball · package.json
$ cnpm install babel-plugin-transform-comment-to-assert 
SYNC missed versions from official npm registry.

babel-plugin-transform-comment-to-assert travis npm

replace commented expressions with assert statements

Install

$ npm install --save babel-plugin-transform-comment-to-assert

Usage

import * as babel from 'babel-core'
import plugin from 'babel-plugin-transform-comment-to-assert'

function replace (code) {
  return babel.transform(code, { babelrc: false, plugins: [plugin] }).code.trim();
};

replace('1 //=> 1')
//=> 'assert.deepEqual(1, 1);'

Objects:


replace('a = { a: 1 }; a //=> {a: 1}')
//=> 'a = { a: 1 };assert.deepEqual(a, { a: 1 });'

Results of function calls:

replace("(() => 'foo')() //=> 'bar'")
//=> "assert.deepEqual((() => 'foo')(), 'bar');"

It also supports console.log:

replace("console.log('foo') //=> 'bar'")
//=> "console.log('foo');assert.deepEqual('foo', 'bar');"

Throws:

replace(`
const a = () => {
  throw new Error('fail');
};
a() // throws Error
`);
/*=>
`const a = () => {
  throw new Error('fail');
};
assert.throws(() => a(), Error);`
*/
replace(`
const a = () => {
  throw new Error('fail');
};
a() // throws /fail/
`);
/*=>
`const a = () => {
  throw new Error('fail');
};
assert.throws(() => a(), /fail/);`
*/

License

MIT © Sigurd Fosseng

Current Tags

  • 4.1.0                                ...           latest (5 months ago)

22 Versions

  • 4.1.0                                ...           5 months ago
  • 4.0.0                                ...           5 months ago
  • 3.1.2                                ...           2 years ago
  • 3.1.1                                ...           3 years ago
  • 3.1.0                                ...           3 years ago
  • 3.0.1                                ...           3 years ago
  • 3.0.0                                ...           3 years ago
  • 2.0.2                                ...           3 years ago
  • 2.0.1                                ...           3 years ago
  • 2.0.0                                ...           3 years ago
  • 1.0.12                                ...           4 years ago
  • 1.0.11                                ...           4 years ago
  • 1.0.10                                ...           4 years ago
  • 1.0.9                                ...           4 years ago
  • 1.0.8                                ...           4 years ago
  • 1.0.7                                ...           4 years ago
  • 1.0.6                                ...           4 years ago
  • 1.0.5                                ...           4 years ago
  • 1.0.4                                ...           4 years ago
  • 1.0.2                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 85
Last Day 0
Last Week 22
Last Month 60
Dependencies (1)
Dev Dependencies (15)

Copyright 2014 - 2016 © taobao.org |