Acme.BookStore.HttpApi.Host/node_modules/stream-exhaust/test.js

(开头部分) 4KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

var test = require('tape');
var exhaust = require('./index.js');
var Stream = require('stream');
var Readable = Stream.Readable;
var Writable = Stream.Writable;
var Duplex = Stream.Duplex;
var through = require('through2');
var S2Readable = require('readable-stream').Readable;

test('it should cause a Readable stream to complete if it\'s not piped anywhere', function(assert) {
  var rs = new Readable({highWaterMark: 2});
  var a = 0;
  var ended = false;
  rs._read = function() {
    if (a++ < 100) {
      rs.push(a + "");
    } else {
      ended = true;
      rs.push(null);
    }
  };

  rs.on("end", function() {
    assert.ok(a > 99, 'a should be > 99');
    assert.ok(ended, 'it should end');
    assert.end();
  });

  exhaust(rs);
});

test('should work with Readable streams in objectMode', function(assert) {
  var rs = new Readable({highWaterMark: 2, objectMode: true});
  var a = 0;
  var ended = false;
  rs._read = function() {
    if (a++ < 100) {
      rs.push(a);
    } else {
      ended = true;
      rs.push(null);
    }
  };

  rs.on("end", function() {
    assert.ok(a > 99, 'a > 99');
    assert.ok(ended, 'ended is true');
    assert.end();
  });

  exhaust(rs);
});

test('should not interfere with a Readable stream that is piped somewhere', function(assert) {
  var rs = new Readable({highWaterMark: 2});
  var a = 0;
  var ended = false;
  rs._read = function() {
    if (a++ < 100) {
      rs.push(".");
后面还有 149 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。