tapsoneer
A simple Node.js/io.js interface to the tapson test protocol, version 1.0.0.
Tests are planned, then run asynchronously. If some of your tests depend on each other, you can specify how.
Exports a readable tapson protocol stream.
Tutorial
// Instantiatevar taps = ; // Create 2 tests that finish in 0 - 1 secondsvar test1 = taps;var test2 = taps;// Tell tapsoneer we're done with planning teststaps; // Run the tests in parallel;; // Read the output data streamtapsout;
With the above, tapsoneer runs both tests in parallel. You can expect output that looks like—
Exported things
var tests = tapsoneer([options])
Creates a new tapsoneer test set, ready and waiting for tests.
By default, the emitted stream outputs Node Buffers. If you want a stream of
objects instead, pass an options object with { objectMode : true }
.
var test = tests.plan([description], testFunction)
Plans a new test with an optional description and a function that runs it. Returns a function that you can call to immediately run the test.
The test
will be passed a callback function as its only argument, which it
should call once it is finished. As is the usual Node.js practice, if there's
a failure, pass an Error
object or String
error message as the first
parameter. If it succeeded, pass null
as the first parameter and an optional
String describing the success as the second.
test([callback])
Runs the given test immediately. Its results will be on the output stream as soon as the test completes.
You can optionally pass it a callback
argument, to be notified when the test
finishes. This is handy if some of your tests depend on other tests, and means
you can use async.js to do stuff like—
var databaseConnection = null; var testSetupDatabase = tests;var testQuery = tests; tests; async;
—to ensure they run sequentially. If you have a tangly mess of dependencies,
async.auto
is your friend.
If you want to run a test immediately after you plan it because it has no dependencies on anything, that's fine too. It'll run in parallel with other tests:
tests;
If you want to pass data between tests (some stuff from a database, say), just
call your test function's result callback with that data as additional
arguments. They'll be prepended to the test callback's arguments in a way
that's compatible with async.waterfall
:
var queryDatabase = tests; var checkData = tests
tests.out
This is a stream containing tapson. All test plans and test results are emitted from it as they happen. The stream finishes when all the tests finish.
If you want it on stdout
, just do tests.out.pipe(process.stdout)
.
License
ISC.