On Tuesday, July 17, 2012 3:13:44 AM UTC-7, Alex Young wrote: > The CommonJS test module uses those export-based tests, and somehow I've been assuming this is the 'right' way to write tests. It seems like there are three options: > * CommonJS unit testing module style > * Mocha (and similar) where a program is used to execute the test because it contains top-level functions without relying on a require > * A plain old Node script
There are also test runners like tap that give you some useful abstractions in a form that you can require() with no global namespace pollution hacks or export inspection with the effect that you can just run tests written in this fashion directly with `node`. https://github.com/isaacs/node-tap And now some ranty thoughts about test harnesses and libraries. I find it very strange that so many people are comfortable with some very bizarre programming practices when it comes to writing tests that are universally abhorred in "regular programming". For instance, running a test, which you might expect to behave like any other program, by defining exports which indirectly get run by a harness. Or in other cases, the test harness will punch a punch of global prototypes to make a ruby-esque DSL for doing assertions. (`should` does this) These lines of thought do not seem at all consistent and I am curious about why people feel justified in taking these rather absurd design decisions when it comes to writing tests which are so vilified in the rest of programming. I tend to dismiss these ideas as needless complications and inconsistencies we can and should purge from our thinking and code unless and until very compelling reasons present themselves to the contrary. I have few problems with using node/assert directly as a test runner/harness except that I have seen test suites written in this matter get out of hand. I don't mind it much when test runners like vows or nodeunit have some custom strange way of doing exports or defining tests except that I find them a bit awkward. I do however have a massive problem with test harnesses like jasmine or mocha that take it upon themselves to dump a bunch of globals into a namespace because it destroys the paper trail of how those units of functionality came to be in the program to begin with. This is the reason why commonjs-esque requires are so nice and ruby-style requires are so terrible. Worse, in mocha which globals are polluted into your namespace is defined by runtime configuration. I am completely baffled why so many popular testing harnesses are so absurd! -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to nodejs@googlegroups.com To unsubscribe from this group, send email to nodejs+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en