jcoglan / jstest

The cross-platform JavaScript test framework
38 stars 3 forks source link

jstest -h suggests I can pass multiple files on the command line, but how? #2

Closed joewreschnig closed 10 years ago

joewreschnig commented 10 years ago

If I run jstest tests_*.js it seems to stop running tests after the first file that calls JS.Test.autorun() (it doesn't even print them under "Loaded suite").

If autorun is first called at the end of test_a.js it won't run any suites in test_b.js. And if no files call autorun, it runs no tests.

An example from my project, with both files calling autorun:

$ jstest test/spec/yf_spec.js test/spec/yT_spec.js 
Loaded suite: yT, an example Point type

......................

Finished in 0.022 seconds
22 tests, 68 assertions, 0 failures, 0 errors

$ jstest test/spec/yT_spec.js test/spec/yf_spec.js 
Loaded suite: yf

..

Finished in 0.019 seconds
2 tests, 5 assertions, 0 failures, 0 errors

And with neither calling it:

$ jstest test/spec/yf_spec.js test/spec/yT_spec.js 
Loaded suite: 

Finished in 0.012 seconds
0 tests, 0 assertions, 0 failures, 0 errors
jcoglan commented 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
joewreschnig commented 10 years ago

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.