mactest
A NodeJS/Express library for quick'n dirty unit testing
Install it
npm install mactest
Use it
Express
Configure withAssuming you are running a server with express, this will create a page available at http://yourserver.host/mactest, where your tests will be listed, and can be executed
express = ;mactest = ;app = ; app ; mactestmactest
Define your test suites
Say we want to test a module that resolves url redirects
mactest = ; {};moduleexports = resolve ; mactest
Now your browser should show a util functions > url resolve link when you got to http://my.host/mactest (and you can execute the test & visualize the outcome by clicking the link)
API
mactest.configure(options)
to configure mactest
options is a hash with 2 keys:
rootPath
(string, defaults to/mactest
) is the path on your server to access the page where all your tests are listedexcludeSampleTests
(boolean, defaults to false) unless you override, you will see some built-in mock tests in addition to the tests you have defined in your code
mactest.add(name, testFn)
to add a test suite
- name is a string that identifies your test suite
- testFn is your test suite. It's a function with a
(result, callback)
signature. Useresult.info(..), result.failure(..), result.success(..)
any (multiple) time to report failure, info, success at different step of execution, then callcallback(error, result)
after the test suite has completed its execution