Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: refactor test-stream2-basic #13146

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ function run() {
const fn = next[1];
console.log('# %s', name);
fn({
same: assert.deepStrictEqual,
ok: assert,
equal: assert.strictEqual,
end: function() {
count--;
run();
Expand Down Expand Up @@ -147,7 +144,7 @@ test('a most basic test', function(t) {
'xxxxxxxxxxxxxxxxxxxxx' ];

r.on('end', function() {
t.same(reads, expect);
assert.deepStrictEqual(reads, expect);
t.end();
});

Expand Down Expand Up @@ -180,7 +177,7 @@ test('pipe', function(t) {
const w = new TestWriter();

w.on('end', function(received) {
t.same(received, expect);
assert.deepStrictEqual(received, expect);
t.end();
});

Expand Down Expand Up @@ -211,10 +208,10 @@ test('pipe', function(t) {
w[0].on('write', function() {
if (--writes === 0) {
r.unpipe();
t.equal(r._readableState.pipes, null);
assert.strictEqual(r._readableState.pipes, null);
w[0].end();
r.pipe(w[1]);
t.equal(r._readableState.pipes, w[1]);
assert.strictEqual(r._readableState.pipes, w[1]);
}
});

Expand All @@ -223,18 +220,18 @@ test('pipe', function(t) {
let ended0 = false;
let ended1 = false;
w[0].on('end', function(results) {
t.equal(ended0, false);
assert.strictEqual(ended0, false);
ended0 = true;
ended++;
t.same(results, expect[0]);
assert.deepStrictEqual(results, expect[0]);
});

w[1].on('end', function(results) {
t.equal(ended1, false);
assert.strictEqual(ended1, false);
ended1 = true;
ended++;
t.equal(ended, 2);
t.same(results, expect[1]);
assert.strictEqual(ended, 2);
assert.deepStrictEqual(results, expect[1]);
t.end();
});

Expand All @@ -261,11 +258,11 @@ test('multipipe', function(t) {

let c = 2;
w[0].on('end', function(received) {
t.same(received, expect, 'first');
assert.deepStrictEqual(received, expect, 'first');
if (--c === 0) t.end();
});
w[1].on('end', function(received) {
t.same(received, expect, 'second');
assert.deepStrictEqual(received, expect, 'second');
if (--c === 0) t.end();
});

Expand Down Expand Up @@ -306,13 +303,13 @@ test('multipipe', function(t) {

w[0].on('end', function(results) {
ended++;
t.same(results, expect[0]);
assert.deepStrictEqual(results, expect[0]);
});

w[1].on('end', function(results) {
ended++;
t.equal(ended, 2);
t.same(results, expect[1]);
assert.strictEqual(ended, 2);
assert.deepStrictEqual(results, expect[1]);
t.end();
});

Expand All @@ -323,7 +320,7 @@ test('multipipe', function(t) {

test('back pressure respected', function(t) {
const r = new R({ objectMode: true });
r._read = common.noop;
r._read = common.mustNotCall();
let counter = 0;
r.push(['one']);
r.push(['two']);
Expand All @@ -341,7 +338,7 @@ test('back pressure respected', function(t) {
r.pipe(w3);
});
};
w1.end = common.noop;
w1.end = common.mustNotCall();

r.pipe(w1);

Expand All @@ -367,7 +364,7 @@ test('back pressure respected', function(t) {

return false;
};
w2.end = common.noop;
w2.end = common.mustCall();

const w3 = new R();
w3.write = function(chunk) {
Expand Down Expand Up @@ -400,7 +397,7 @@ test('read(0) for ended streams', function(t) {
const r = new R();
let written = false;
let ended = false;
r._read = common.noop;
r._read = common.mustNotCall();

r.push(Buffer.from('foo'));
r.push(null);
Expand Down Expand Up @@ -463,16 +460,16 @@ test('adding readable triggers data flow', function(t) {
});

r.on('end', function() {
t.equal(readCalled, 3);
t.ok(onReadable);
assert.strictEqual(readCalled, 3);
assert.ok(onReadable);
t.end();
});
});

test('chainable', function(t) {
const r = new R();
r._read = common.noop;
r._read = common.mustCall();
const r2 = r.setEncoding('utf8').pause().resume().pause();
t.equal(r, r2);
assert.strictEqual(r, r2);
t.end();
});