Skip to content

Commit

Permalink
test: cleanup stream tests
Browse files Browse the repository at this point in the history
const and let instead var
assert.strictEqual instead assert.equal

PR-URL: nodejs#8668
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
italoacasas authored and imyller committed Sep 22, 2016
1 parent e7d4176 commit 4d95872
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 82 deletions.
16 changes: 8 additions & 8 deletions test/parallel/test-stream-big-packet.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';
require('../common');
var assert = require('assert');
var util = require('util');
var stream = require('stream');
const assert = require('assert');
const util = require('util');
const stream = require('stream');

var passed = false;
let passed = false;

function PassThrough() {
stream.Transform.call(this);
Expand All @@ -27,15 +27,15 @@ TestStream.prototype._transform = function(chunk, encoding, done) {
done();
};

var s1 = new PassThrough();
var s2 = new PassThrough();
var s3 = new TestStream();
const s1 = new PassThrough();
const s2 = new PassThrough();
const s3 = new TestStream();
s1.pipe(s3);
// Don't let s2 auto close which may close s3
s2.pipe(s3, {end: false});

// We must write a buffer larger than highWaterMark
var big = Buffer.alloc(s1._writableState.highWaterMark + 1, 'x');
const big = Buffer.alloc(s1._writableState.highWaterMark + 1, 'x');

// Since big is larger than highWaterMark, it will be buffered internally.
assert(!s1.write(big));
Expand Down
26 changes: 13 additions & 13 deletions test/parallel/test-stream-big-push.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
'use strict';
require('../common');
var assert = require('assert');
var stream = require('stream');
var str = 'asdfasdfasdfasdfasdf';
const assert = require('assert');
const stream = require('stream');
const str = 'asdfasdfasdfasdfasdf';

var r = new stream.Readable({
const r = new stream.Readable({
highWaterMark: 5,
encoding: 'utf8'
});

var reads = 0;
var eofed = false;
var ended = false;
let reads = 0;
let eofed = false;
let ended = false;

r._read = function(n) {
if (reads === 0) {
Expand All @@ -21,7 +21,7 @@ r._read = function(n) {
reads++;
} else if (reads === 1) {
var ret = r.push(str);
assert.equal(ret, false);
assert.strictEqual(ret, false);
reads++;
} else {
assert(!eofed);
Expand All @@ -40,25 +40,25 @@ var ret = r.push(str);
// should be false. > hwm
assert(!ret);
var chunk = r.read();
assert.equal(chunk, str);
assert.strictEqual(chunk, str);
chunk = r.read();
assert.equal(chunk, null);
assert.strictEqual(chunk, null);

r.once('readable', function() {
// this time, we'll get *all* the remaining data, because
// it's been added synchronously, as the read WOULD take
// us below the hwm, and so it triggered a _read() again,
// which synchronously added more, which we then return.
chunk = r.read();
assert.equal(chunk, str + str);
assert.strictEqual(chunk, str + str);

chunk = r.read();
assert.equal(chunk, null);
assert.strictEqual(chunk, null);
});

process.on('exit', function() {
assert(eofed);
assert(ended);
assert.equal(reads, 2);
assert.strictEqual(reads, 2);
console.log('ok');
});
11 changes: 5 additions & 6 deletions test/parallel/test-stream-duplex.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
'use strict';
require('../common');
var assert = require('assert');
const assert = require('assert');
const Duplex = require('stream').Transform;

var Duplex = require('stream').Transform;

var stream = new Duplex({ objectMode: true });
const stream = new Duplex({ objectMode: true });

assert(stream._readableState.objectMode);
assert(stream._writableState.objectMode);

var written;
var read;
let written;
let read;

stream._write = function(obj, _, cb) {
written = obj;
Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-stream-end-paused.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';
const common = require('../common');
var assert = require('assert');
const assert = require('assert');

// Make sure we don't miss the end event for paused 0-length streams

var Readable = require('stream').Readable;
var stream = new Readable();
var calledRead = false;
const Readable = require('stream').Readable;
const stream = new Readable();
let calledRead = false;
stream._read = function() {
assert(!calledRead);
calledRead = true;
Expand Down
7 changes: 3 additions & 4 deletions test/parallel/test-stream-ispaused.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';
require('../common');
var assert = require('assert');
const assert = require('assert');
const stream = require('stream');

var stream = require('stream');

var readable = new stream.Readable();
const readable = new stream.Readable();

// _read is a noop, here.
readable._read = Function();
Expand Down
21 changes: 10 additions & 11 deletions test/parallel/test-stream-pipe-after-end.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';
require('../common');
var assert = require('assert');

var Readable = require('_stream_readable');
var Writable = require('_stream_writable');
var util = require('util');
const assert = require('assert');
const Readable = require('_stream_readable');
const Writable = require('_stream_writable');
const util = require('util');

util.inherits(TestReadable, Readable);
function TestReadable(opt) {
Expand Down Expand Up @@ -35,11 +34,11 @@ TestWritable.prototype._write = function(chunk, encoding, cb) {
};

// this one should not emit 'end' until we read() from it later.
var ender = new TestReadable();
var enderEnded = false;
const ender = new TestReadable();
let enderEnded = false;

// what happens when you pipe() a Readable that's already ended?
var piper = new TestReadable();
const piper = new TestReadable();
// pushes EOF null, and length=0, so this will trigger 'end'
piper.read();

Expand All @@ -48,11 +47,11 @@ setTimeout(function() {
enderEnded = true;
});
assert(!enderEnded);
var c = ender.read();
const c = ender.read();
assert.equal(c, null);

var w = new TestWritable();
var writableFinished = false;
const w = new TestWritable();
let writableFinished = false;
w.on('finish', function() {
writableFinished = true;
});
Expand Down
72 changes: 36 additions & 36 deletions test/parallel/test-stream-pipe-cleanup.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
'use strict';
// This test asserts that Stream.prototype.pipe does not leave listeners
// hanging on the source or dest.

require('../common');
var stream = require('stream');
var assert = require('assert');
var util = require('util');
const stream = require('stream');
const assert = require('assert');
const util = require('util');

function Writable() {
this.writable = true;
Expand Down Expand Up @@ -33,20 +32,20 @@ function Duplex() {
}
util.inherits(Duplex, Writable);

var i = 0;
var limit = 100;
let i = 0;
const limit = 100;

var w = new Writable();
let w = new Writable();

var r;
let r;

for (i = 0; i < limit; i++) {
r = new Readable();
r.pipe(w);
r.emit('end');
}
assert.equal(0, r.listeners('end').length);
assert.equal(limit, w.endCalls);
assert.strictEqual(0, r.listeners('end').length);
assert.strictEqual(limit, w.endCalls);

w.endCalls = 0;

Expand All @@ -55,8 +54,8 @@ for (i = 0; i < limit; i++) {
r.pipe(w);
r.emit('close');
}
assert.equal(0, r.listeners('close').length);
assert.equal(limit, w.endCalls);
assert.strictEqual(0, r.listeners('close').length);
assert.strictEqual(limit, w.endCalls);

w.endCalls = 0;

Expand All @@ -67,36 +66,37 @@ for (i = 0; i < limit; i++) {
r.pipe(w);
w.emit('close');
}
assert.equal(0, w.listeners('close').length);
assert.strictEqual(0, w.listeners('close').length);

r = new Readable();
w = new Writable();
var d = new Duplex();
const d = new Duplex();
r.pipe(d); // pipeline A
d.pipe(w); // pipeline B
assert.equal(r.listeners('end').length, 2); // A.onend, A.cleanup
assert.equal(r.listeners('close').length, 2); // A.onclose, A.cleanup
assert.equal(d.listeners('end').length, 2); // B.onend, B.cleanup
assert.equal(d.listeners('close').length, 3); // A.cleanup, B.onclose, B.cleanup
assert.equal(w.listeners('end').length, 0);
assert.equal(w.listeners('close').length, 1); // B.cleanup
assert.strictEqual(r.listeners('end').length, 2); // A.onend, A.cleanup
assert.strictEqual(r.listeners('close').length, 2); // A.onclose, A.cleanup
assert.strictEqual(d.listeners('end').length, 2); // B.onend, B.cleanup
// A.cleanup, B.onclose, B.cleanup
assert.strictEqual(d.listeners('close').length, 3);
assert.strictEqual(w.listeners('end').length, 0);
assert.strictEqual(w.listeners('close').length, 1); // B.cleanup

r.emit('end');
assert.equal(d.endCalls, 1);
assert.equal(w.endCalls, 0);
assert.equal(r.listeners('end').length, 0);
assert.equal(r.listeners('close').length, 0);
assert.equal(d.listeners('end').length, 2); // B.onend, B.cleanup
assert.equal(d.listeners('close').length, 2); // B.onclose, B.cleanup
assert.equal(w.listeners('end').length, 0);
assert.equal(w.listeners('close').length, 1); // B.cleanup
assert.strictEqual(d.endCalls, 1);
assert.strictEqual(w.endCalls, 0);
assert.strictEqual(r.listeners('end').length, 0);
assert.strictEqual(r.listeners('close').length, 0);
assert.strictEqual(d.listeners('end').length, 2); // B.onend, B.cleanup
assert.strictEqual(d.listeners('close').length, 2); // B.onclose, B.cleanup
assert.strictEqual(w.listeners('end').length, 0);
assert.strictEqual(w.listeners('close').length, 1); // B.cleanup

d.emit('end');
assert.equal(d.endCalls, 1);
assert.equal(w.endCalls, 1);
assert.equal(r.listeners('end').length, 0);
assert.equal(r.listeners('close').length, 0);
assert.equal(d.listeners('end').length, 0);
assert.equal(d.listeners('close').length, 0);
assert.equal(w.listeners('end').length, 0);
assert.equal(w.listeners('close').length, 0);
assert.strictEqual(d.endCalls, 1);
assert.strictEqual(w.endCalls, 1);
assert.strictEqual(r.listeners('end').length, 0);
assert.strictEqual(r.listeners('close').length, 0);
assert.strictEqual(d.listeners('end').length, 0);
assert.strictEqual(d.listeners('close').length, 0);
assert.strictEqual(w.listeners('end').length, 0);
assert.strictEqual(w.listeners('close').length, 0);

0 comments on commit 4d95872

Please sign in to comment.