Version 0.13.0
This release improves webpack compatibility as a result of #83.
Sometimes usage examples must reference data constructors which are not in scope. These can be imported in the doctests themselves:
//. > var List = require('./test/internal/List')
//. > var Nil = List.Nil
//. > var Cons = List.Cons
//.
//. > reverse(Nil)
//. Nil
//.
//. > reverse(Cons(1, Cons(2, Cons(3, Nil))))
//. Cons(3, Cons(2, Cons(1, Nil)))
The above approach may not be optimal when using Transcribe, as the preamble will be included in the generated readme. To keep the readme clean, one may include doctest-specific imports in the source code itself, guarded to ensure they are ignored in other contexts:
if (typeof __doctest !== 'undefined') {
var List = require('./test/internal/List');
var Nil = List.Nil;
var Cons = List.Cons;
}
The above approach does not work well in conjunction with build tools such as webpack, which attempt to include guarded modules when generating a bundle. This is particularly problematic for those who depend on the package in question: test modules are not distributed, so ./test/internal/List
will not exist.
Fortunately, webpack can be tricked. This release introduces __doctest.require
, which is simply a reference to require
. The indirection is sufficient to throw webpack off the scent:
if (typeof __doctest !== 'undefined') {
var List = __doctest.require('./test/internal/List');
var Nil = List.Nil;
var Cons = List.Cons;
}