yamadapc / jsdoctest

Run jsdoc examples as doctests.
https://yamadapc.github.io/jsdoctest
MIT License
92 stars 9 forks source link

inter-requiring modules have trouble with the first-require trick #26

Closed tmcw closed 8 years ago

tmcw commented 8 years ago

This module is awesome! Starting to use it to test simple-statistics docs. One thing I ran into is that the trick for only testing the directly-required module ( https://github.com/yamadapc/jsdoctest/blob/master/lib/mocha.js#L74 ) runs into a bit of trouble when source files require each other: let's say you have

src/a.js // requires b.js
src/b.js

If both files have tests, then you'll initially require a, which requires b internally and b isn't turned into tests. then the next time you want b, it's in the require cache, so it isn't tested.

A workaround, which works but is slower:

for f in src/*.js; mocha --require jsdoctest $f

This runs the test suite on each file, in order, so that each test run has a fresh require cache.

yamadapc commented 8 years ago

Mm... Perhaps just black-listing node_modules is a better idea. I assume if I try running your tests I'll reproduce?

tmcw commented 8 years ago

I think blacklisting node_modules should work, since the require cache should also keep files from being executed more than once. Yep, and you can tweak the tests in simple-statistics to test