This repository has been archived by the owner. It is now read-only.
Mock readable and writable streams for UTF-8 text.
Clone or download
Latest commit 3778963 Dec 14, 2015
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test
.gitignore
.travis.yml
LICENSE
README.md Add startCapture, stopCapture, clearCapturedData. Feb 28, 2014
index.js Add startCapture, stopCapture, clearCapturedData. Feb 28, 2014
package.json

README.md

mock-utf8-stream

Mock readable and writable streams for UTF-8 text. Useful for testing command-line programs by mocking stdin, stdout, and stderr.

Example

var assert = require("assert");
var stream = require("mock-utf8-stream");

var stdin = new stream.MockReadableStream();
var stdout = new stream.MockWritableStream();

function example(opts, cb) {
    opts.stdin.on("data", function (data) {
        if (data === "hello") {
            opts.stdout.write("hello\n");
        }
        cb(null);
    });
}

// Begin capturing data events.
// You can read captured data as a UTF-8
// string on the `stdout.capturedData` property.
stdout.startCapture();

example({
    stdin: stdin,
    stdout: stdout
}, function (err) {
    if (err) { throw err; }
    assert.strictEqual(stdout.capturedData, "hello\n");
    console.log("OK");
});

stdin.write("hello");

Author & License

BSD. See LICENSE for details and copyright information.