Asserts not counted by reporter
I'm curious why vanilla asserts don't get reported by nodeunit? Meaning test.ok(true) counts but assert.ok(true) doesn't get counted. Am I doing something wrong or do I need to hack something? I'd like to use something like should.js but I'd like nodeunit to track the assertions.
Thanks for any advice.
-Mike
Nodeunit will report AssertionErrors from using the methods available in the assert module. However, they will not be included in the assertion count because that only includes assertions using the 'test' object passed to each test function.
Assertions are associated with a test context for a reason, since with async code it can be difficult to know which function caused the assertion to occur. Wrapping the assert methods in a new test object for each test function allows us to keep track of which test caused which assertion to fire.
It might be nice if there was some mechanism to wrap other assertion libraries in the same manner. Maybe there could be some hook into nodeunit's assertion wrapper? I just feel it would be nice to plug in other assertion libraries (like should.js) to nodeunit without having to fork either. Any thoughts on this? I'm happy to do work on this but would need some input on how you think it should be done. Peace! Thanks.
Yes, I think that's a good idea. There have previously been forks to add cjohansen's node-assert-extras (http://gitorious.org/node-assert-extras) too, so its not just you wanting to do this sort of thing ;)
For inspiration on where to start, take a look at the following lines in lib/types.js: https://github.com/caolan/nodeunit/blob/master/lib/types.js#L155-160
However, I'm not sure what this nicest way to hook into this is. Perhaps additional assertion modules is an option that should be added to a nodeunit.json config?
Cool, seems easy enough. Any opinion on how to best get values from nodeunit.json to types#test()?
No, there isn't a nice way to pass options around inside nodeunit core, only within test reporters. I'd like to fix this and I'm open to suggestions. Perhaps you could add an optional 'options' argument to the runTest etc functions?
I want to use should.js with nodeunit too. Are there any progress?
Bump. I'd like to have this too! Or should I turn to Expresso? :(
+1
Instead of "recreating" the assert module, why not just require it and replace/extend bits of it by adding the counting method and all?
Didn't find an answer, so I wrote my own hack to should.js: https://gist.github.com/simonratner/5545556