ex-400-dev
Version:
EX-400 development library
101 lines (74 loc) • 1.98 kB
JavaScript
var assert = require("chai").assert,
stream = require("stream"),
dev = require("../");
describe("Transport", function() {
var t;
beforeEach(function() {
t = new dev.Transport();
});
it("should emit data event", function(done) {
t.on("data", function(str) {
assert.strictEqual(str, "hello");
done();
});
t.write("hello");
});
it("should pipe", function(done) {
var receiver = new stream.PassThrough({objectMode: true});
receiver.on("data", function(str) {
assert.strictEqual(str, "hello");
done();
});
t.pipe(receiver);
t.write("hello");
});
it("should get piped", function(done) {
var sender = new stream.PassThrough({objectMode: true});
t.on("data", function(str) {
assert.strictEqual(str, "hello");
done();
});
sender.pipe(t);
sender.write("hello");
});
it("should emit msg:1 ... msg:N", function(done) {
t.once("msg:1", function(num) {
assert.strictEqual(num, 1);
});
t.once("msg:2", function(num) {
assert.strictEqual(num, 2);
});
t.once("msg:3", function(num) {
assert.strictEqual(num, 3);
});
t.once("msg:4", function(num) {
assert.strictEqual(num, 4);
});
t.once("msg:5", function(num) {
assert.strictEqual(num, 5);
});
t.once("msg:6", function(num) {
assert.strictEqual(num, 6);
});
t.once("msg:7", function(num) {
assert.strictEqual(num, 7);
});
t.once("msg:8", function(num) {
assert.strictEqual(num, 8);
});
t.once("msg:9", function(num) {
assert.strictEqual(num, 9);
});
t.once("msg:10", function(num) {
assert.strictEqual(num, 10);
});
t.once("msg:100", function(num) {
assert.strictEqual(num, 100);
});
t.once("msg:1000", function(num) {
assert.strictEqual(num, 1000);
done();
});
for (var n=1; n<=1000; n++) { t.write(n) };
});
});