Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So here's what I see people doing, and the method I've adopted in my own work:</p> <ol> <li>In your modules, only export the values that need to be exported. Personally, I try to limit myself to exporting no more than a single function but that's a separate discussion.</li> <li>Create a <code>test</code> directory and place all of your test cases in it. Use whatever naming convention you like. I prefer to have one test file for each source module. At the start of each file, simply require the module under test.</li> <li>Call mocha from a Makefile/Cakefile with the <code>--recursive</code> argument so it knows to examine the entire contents of your <code>test</code> directory.</li> </ol> <p>This means you are testing the modules through their interfaces, just as you would use them in normal code. The downside is, if you have non-exported functions with execution paths which are difficult to hit via the module's interface, you may find yourself a little frustrated.</p> <p>On one hand, I agree with the notion that modules should be tested as they are used. On the other hand I think I'd sleep better at night knowing that I directly tested every one of the aforementioned tricky execution paths. Prior to doing node.js programming I spent several years writing erlang code, which has the exact opposite convention: (tests are placed at the end of the source files so they have direct access to every function in the module, and testing includes/exports are handled by ifdef directives). Personally, I like the erlang approach better.</p> <p>Anyway, I hope this was helpful. If anyone reading this has a strong opinion to the contrary I'd love to hear it.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload