874
edits
(reorganized things a bit, added docs for command-line tools) |
(→Examples: added an example) |
||
| Line 159: | Line 159: | ||
= Examples = | = Examples = | ||
Here's a simple package. | |||
<tt>package.json</tt>: | |||
<pre> | |||
{ | |||
"name": "hardmath", | |||
"description": "Ridiculously complex math routines." | |||
} | |||
</pre> | |||
<tt>lib/hardmath.js</tt>: | |||
<pre> | |||
exports.add = function add(a, b) { | |||
return a + b; | |||
}; | |||
</pre> | |||
<tt>tests/test-hardmath.js</tt>: | |||
<pre> | |||
exports.testAdditionWorks = function(test) { | |||
test.assertEqual(require("hardmath").add(1,1), 2, | |||
"hard addition should work."); | |||
}; | |||
</pre> | |||
Executing <tt>cfx test</tt> from the root of this package yields: | |||
<pre> | |||
. | |||
Malloc bytes allocated (in use by application): 6548640 | |||
Malloc bytes mapped (not necessarily committed): 14262272 | |||
Malloc bytes committed (r/w) in default zone: 6556144 | |||
Malloc bytes allocated (in use) in default zone: 13213696 | |||
Tracked memory objects in testing sandbox: 2 | |||
1 of 1 tests passed. | |||
OK | |||
Total time: 1.109022 seconds | |||
Program terminated successfully. | |||
</pre> | |||
edits