Skip to content

Commit

Permalink
test: improve assert error messages
Browse files Browse the repository at this point in the history
Improve the assert error message so it includes actual value in
the error message.

PR-URL: #21160
Reviewed-By: Weijia Wang <starkwang@126.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Yuta Hiroto <hello@hiroppy.me>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
hristijankiko authored and targos committed Jun 13, 2018
1 parent 65b9c42 commit 4d782c4
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions test/parallel/test-stream-pipe-await-drain.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ writer1._write = common.mustCall(function(chunk, encoding, cb) {
}, 1);

writer1.once('chunk-received', function() {
assert.strictEqual(reader._readableState.awaitDrain, 0,
'initial value is not 0');
assert.strictEqual(
reader._readableState.awaitDrain,
0,
'awaitDrain initial value should be 0, actual is ' +
reader._readableState.awaitDrain
);
setImmediate(function() {
// This one should *not* get through to writer1 because writer2 is not
// "done" processing.
Expand All @@ -35,8 +39,10 @@ writer1.once('chunk-received', function() {
// A "slow" consumer:
writer2._write = common.mustCall(function(chunk, encoding, cb) {
assert.strictEqual(
reader._readableState.awaitDrain, 1,
'awaitDrain isn\'t 1 after first push'
reader._readableState.awaitDrain,
1,
'awaitDrain should be 1 after first push, actual is ' +
reader._readableState.awaitDrain
);
// Not calling cb here to "simulate" slow stream.
// This should be called exactly once, since the first .write() call
Expand All @@ -45,8 +51,10 @@ writer2._write = common.mustCall(function(chunk, encoding, cb) {

writer3._write = common.mustCall(function(chunk, encoding, cb) {
assert.strictEqual(
reader._readableState.awaitDrain, 2,
'awaitDrain isn\'t 2 after second push'
reader._readableState.awaitDrain,
2,
'awaitDrain should be 2 after second push, actual is ' +
reader._readableState.awaitDrain
);
// Not calling cb here to "simulate" slow stream.
// This should be called exactly once, since the first .write() call
Expand Down

0 comments on commit 4d782c4

Please sign in to comment.