It can be extremely helpfull to new users if a library comes with some examples. Sadly though, it often happens that examples stop working as the code base moves forward. This can create a lot of confusion.
This gulp task takes your example files and turns them into test suites. That way you can be sure your examples and library work as specified.
You can install
gulp-example-to-test as a development dependency.
npm install gulp-example-to-test --save-dev
Now add it to your
gulpfile.js. The generated testcases can be executed with
mocha, using the
var exampleToTest = ;gulp
The plugin understands a very basic example-format. Unindented single line
comments are interpeted as test descriptions and split the file into test cases.
console.log()s are turned into assertions. The
done() callback that
signifies a test case is completed, is called after the last assertion.
Take the following example in a file
var mylib = ; //The foo method returns a number.var result = mylib;console; //=> 'number' //The bar method takes a method that gets a number.mylib;
It gets transformed into something like this (though less nicely formatted).
;var assert = ;var mylib = ;