summaryrefslogtreecommitdiff
path: root/test/parallel/test-stream-pipe-error-handling.js
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2016-07-12 19:47:32 -0400
committercjihrig <cjihrig@gmail.com>2016-07-14 22:07:14 -0400
commit4a408321d9c4a6964c9d89a0dd09067f36b4dbfc (patch)
tree5014fee0b2ef8772f4ebf60fd4bf27a72b0ef5b9 /test/parallel/test-stream-pipe-error-handling.js
parent4220c24b17955f7f627bcedc89b6c2a0e655e618 (diff)
downloadandroid-node-v8-4a408321d9c4a6964c9d89a0dd09067f36b4dbfc.tar.gz
android-node-v8-4a408321d9c4a6964c9d89a0dd09067f36b4dbfc.tar.bz2
android-node-v8-4a408321d9c4a6964c9d89a0dd09067f36b4dbfc.zip
test: cleanup IIFE tests
A number of test files use IIFEs to separate distinct tests from each other in the same file. The project has been moving toward using block scopes and let/const in favor of IIFEs. This commit moves IIFE tests to block scopes. Some additional cleanup such as use of strictEqual() and common.mustCall() is also included. PR-URL: https://github.com/nodejs/node/pull/7694 Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Diffstat (limited to 'test/parallel/test-stream-pipe-error-handling.js')
-rw-r--r--test/parallel/test-stream-pipe-error-handling.js88
1 files changed, 34 insertions, 54 deletions
diff --git a/test/parallel/test-stream-pipe-error-handling.js b/test/parallel/test-stream-pipe-error-handling.js
index 88a70fb58e..b2c25cfe8c 100644
--- a/test/parallel/test-stream-pipe-error-handling.js
+++ b/test/parallel/test-stream-pipe-error-handling.js
@@ -1,33 +1,33 @@
'use strict';
-require('../common');
-var assert = require('assert');
-var Stream = require('stream').Stream;
+const common = require('../common');
+const assert = require('assert');
+const Stream = require('stream').Stream;
-(function testErrorListenerCatches() {
- var source = new Stream();
- var dest = new Stream();
+{
+ const source = new Stream();
+ const dest = new Stream();
source.pipe(dest);
- var gotErr = null;
+ let gotErr = null;
source.on('error', function(err) {
gotErr = err;
});
- var err = new Error('This stream turned into bacon.');
+ const err = new Error('This stream turned into bacon.');
source.emit('error', err);
assert.strictEqual(gotErr, err);
-})();
+}
-(function testErrorWithoutListenerThrows() {
- var source = new Stream();
- var dest = new Stream();
+{
+ const source = new Stream();
+ const dest = new Stream();
source.pipe(dest);
- var err = new Error('This stream turned into bacon.');
+ const err = new Error('This stream turned into bacon.');
- var gotErr = null;
+ let gotErr = null;
try {
source.emit('error', err);
} catch (e) {
@@ -35,30 +35,23 @@ var Stream = require('stream').Stream;
}
assert.strictEqual(gotErr, err);
-})();
+}
-(function testErrorWithRemovedListenerThrows() {
- var R = Stream.Readable;
- var W = Stream.Writable;
+{
+ const R = Stream.Readable;
+ const W = Stream.Writable;
- var r = new R();
- var w = new W();
- var removed = false;
- var didTest = false;
-
- process.on('exit', function() {
- assert(didTest);
- console.log('ok');
- });
+ const r = new R();
+ const w = new W();
+ let removed = false;
r._read = function() {
- setTimeout(function() {
+ setTimeout(common.mustCall(function() {
assert(removed);
assert.throws(function() {
w.emit('error', new Error('fail'));
});
- didTest = true;
- });
+ }));
};
w.on('error', myOnError);
@@ -69,41 +62,28 @@ var Stream = require('stream').Stream;
function myOnError(er) {
throw new Error('this should not happen');
}
-})();
+}
-(function testErrorWithRemovedListenerThrows() {
- var R = Stream.Readable;
- var W = Stream.Writable;
+{
+ const R = Stream.Readable;
+ const W = Stream.Writable;
- var r = new R();
- var w = new W();
- var removed = false;
- var didTest = false;
- var caught = false;
-
- process.on('exit', function() {
- assert(didTest);
- console.log('ok');
- });
+ const r = new R();
+ const w = new W();
+ let removed = false;
r._read = function() {
- setTimeout(function() {
+ setTimeout(common.mustCall(function() {
assert(removed);
w.emit('error', new Error('fail'));
- didTest = true;
- });
+ }));
};
- w.on('error', myOnError);
+ w.on('error', common.mustCall(function(er) {}));
w._write = function() {};
r.pipe(w);
// Removing some OTHER random listener should not do anything
w.removeListener('error', function() {});
removed = true;
-
- function myOnError(er) {
- assert(!caught);
- caught = true;
- }
-})();
+}