Closed joewreschnig closed 10 years ago
If you're using jstest(1)
then your test suites don't need to call JS.Test.autorun()
. They shouldn't to that anyway, that call should be in a wrapper script that loads all your specs and then executes them.
e.g. define two specs:
// test_a.js
var JS = require("jstest")
JS.Test.describe("A", function() { with(this) {
it("works", function() {})
}})
// test_b.js
var JS = require("jstest")
JS.Test.describe("B", function() { with(this) {
it("works", function() {})
}})
Then run them:
$ ./node_modules/.bin/jstest test_*
Loaded suite: A, B
..
Finished in 0.01 seconds
2 tests, 0 assertions, 0 failures, 0 errors
OK. After some further debugging, I think I've found the source of the discrepancy. (But I've only been using node for like a week, so, maybe not.)
I'm running jstest
, which is /usr/local/share/npm/bin/jstest
- when I use this one it "doesn't work" unless I call autorun
. (I got it from npm -g install
.)
But I also have a local install of jstest in my project. When I call ./node_modules/.bin/jstest
, it doesn't need autorun
.
So I guess when I run jstest
(or the full path of the one in $PATH) the executable ends up importing the jstest install I have globally. But my test script imports the one I have locally because the node module search process is hilarious. So it registers the test in one copy of the jstest module but then default-autoruns the other copy. But my explicit autorun
is guaranteed to use the same copy as the test registered in.
So this is a user mistake but a really awful one that seems like it could catch other new users. I'm not sure how this can be solved on jstest's end, though. Would it make sense to error if you pass a file that doesn't create any test suites? That would at least fail earlier and louder - I wouldn't have gotten caught by the autorun
red herring.
If you want to just go ahead and close this that's fine too.
If I run
jstest tests_*.js
it seems to stop running tests after the first file that callsJS.Test.autorun()
(it doesn't even print them under "Loaded suite").If
autorun
is first called at the end oftest_a.js
it won't run any suites intest_b.js
. And if no files callautorun
, it runs no tests.An example from my project, with both files calling
autorun
:And with neither calling it: