Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 83f9604

Browse filesBrowse files
tniessenevanlucas
authored andcommitted
test: use ES6 classes instead of util.inherits
PR-URL: #16938 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
1 parent c4e2343 commit 83f9604
Copy full SHA for 83f9604
Expand file treeCollapse file tree

25 files changed

+364
-422
lines changed
Open diff view settings
Collapse file

‎test/parallel/test-crypto-lazy-transform-writable.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-crypto-lazy-transform-writable.js
+5-6Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ if (!common.hasCrypto)
77
const assert = require('assert');
88
const crypto = require('crypto');
99
const Stream = require('stream');
10-
const util = require('util');
1110

1211
const hasher1 = crypto.createHash('sha256');
1312
const hasher2 = crypto.createHash('sha256');
@@ -18,12 +17,12 @@ hasher1.end();
1817

1918
const expected = hasher1.read().toString('hex');
2019

21-
function OldStream() {
22-
Stream.call(this);
23-
24-
this.readable = true;
20+
class OldStream extends Stream {
21+
constructor() {
22+
super();
23+
this.readable = true;
24+
}
2525
}
26-
util.inherits(OldStream, Stream);
2726

2827
const stream = new OldStream();
2928

Collapse file

‎test/parallel/test-crypto-stream.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-crypto-stream.js
+15-15Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,26 @@ if (!common.hasCrypto)
2626

2727
const assert = require('assert');
2828
const stream = require('stream');
29-
const util = require('util');
3029
const crypto = require('crypto');
3130

32-
// Small stream to buffer converter
33-
function Stream2buffer(callback) {
34-
stream.Writable.call(this);
31+
if (!common.hasFipsCrypto) {
32+
// Small stream to buffer converter
33+
class Stream2buffer extends stream.Writable {
34+
constructor(callback) {
35+
super();
3536

36-
this._buffers = [];
37-
this.once('finish', function() {
38-
callback(null, Buffer.concat(this._buffers));
39-
});
40-
}
41-
util.inherits(Stream2buffer, stream.Writable);
37+
this._buffers = [];
38+
this.once('finish', function() {
39+
callback(null, Buffer.concat(this._buffers));
40+
});
41+
}
4242

43-
Stream2buffer.prototype._write = function(data, encodeing, done) {
44-
this._buffers.push(data);
45-
return done(null);
46-
};
43+
_write(data, encodeing, done) {
44+
this._buffers.push(data);
45+
return done(null);
46+
}
47+
}
4748

48-
if (!common.hasFipsCrypto) {
4949
// Create an md5 hash of "Hallo world"
5050
const hasher1 = crypto.createHash('md5');
5151
hasher1.pipe(new Stream2buffer(common.mustCall(function end(err, hash) {
Collapse file

‎test/parallel/test-event-emitter-listeners.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-event-emitter-listeners.js
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,9 @@
2424
require('../common');
2525
const assert = require('assert');
2626
const events = require('events');
27-
const util = require('util');
2827

2928
function listener() {}
3029
function listener2() {}
31-
class TestStream { constructor() { } }
32-
util.inherits(TestStream, events.EventEmitter);
3330

3431
{
3532
const ee = new events.EventEmitter();
@@ -81,6 +78,7 @@ util.inherits(TestStream, events.EventEmitter);
8178
}
8279

8380
{
81+
class TestStream extends events.EventEmitter {}
8482
const s = new TestStream();
8583
assert.deepStrictEqual(s.listeners('foo'), []);
8684
}
Collapse file

‎test/parallel/test-http-client-read-in-error.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-http-client-read-in-error.js
+21-25Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,34 @@
22
require('../common');
33
const net = require('net');
44
const http = require('http');
5-
const util = require('util');
65

7-
function Agent() {
8-
http.Agent.call(this);
9-
}
10-
util.inherits(Agent, http.Agent);
11-
12-
Agent.prototype.createConnection = function() {
13-
const self = this;
14-
const socket = new net.Socket();
6+
class Agent extends http.Agent {
7+
createConnection() {
8+
const socket = new net.Socket();
159

16-
socket.on('error', function() {
17-
socket.push('HTTP/1.1 200\r\n\r\n');
18-
});
10+
socket.on('error', function() {
11+
socket.push('HTTP/1.1 200\r\n\r\n');
12+
});
1913

20-
socket.on('newListener', function onNewListener(name) {
21-
if (name !== 'error')
22-
return;
23-
socket.removeListener('newListener', onNewListener);
14+
let onNewListener;
15+
socket.on('newListener', onNewListener = (name) => {
16+
if (name !== 'error')
17+
return;
18+
socket.removeListener('newListener', onNewListener);
2419

25-
// Let other listeners to be set up too
26-
process.nextTick(function() {
27-
self.breakSocket(socket);
20+
// Let other listeners to be set up too
21+
process.nextTick(() => {
22+
this.breakSocket(socket);
23+
});
2824
});
29-
});
3025

31-
return socket;
32-
};
26+
return socket;
27+
}
3328

34-
Agent.prototype.breakSocket = function breakSocket(socket) {
35-
socket.emit('error', new Error('Intentional error'));
36-
};
29+
breakSocket(socket) {
30+
socket.emit('error', new Error('Intentional error'));
31+
}
32+
}
3733

3834
const agent = new Agent();
3935

Collapse file

‎test/parallel/test-http-client-readable.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-http-client-readable.js
+23-27Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,41 +23,37 @@
2323
const common = require('../common');
2424
const assert = require('assert');
2525
const http = require('http');
26-
const util = require('util');
2726

2827
const Duplex = require('stream').Duplex;
2928

30-
function FakeAgent() {
31-
http.Agent.call(this);
32-
}
33-
util.inherits(FakeAgent, http.Agent);
34-
35-
FakeAgent.prototype.createConnection = function() {
36-
const s = new Duplex();
37-
let once = false;
29+
class FakeAgent extends http.Agent {
30+
createConnection() {
31+
const s = new Duplex();
32+
let once = false;
3833

39-
s._read = function() {
40-
if (once)
41-
return this.push(null);
42-
once = true;
34+
s._read = function() {
35+
if (once)
36+
return this.push(null);
37+
once = true;
4338

44-
this.push('HTTP/1.1 200 Ok\r\nTransfer-Encoding: chunked\r\n\r\n');
45-
this.push('b\r\nhello world\r\n');
46-
this.readable = false;
47-
this.push('0\r\n\r\n');
48-
};
39+
this.push('HTTP/1.1 200 Ok\r\nTransfer-Encoding: chunked\r\n\r\n');
40+
this.push('b\r\nhello world\r\n');
41+
this.readable = false;
42+
this.push('0\r\n\r\n');
43+
};
4944

50-
// Blackhole
51-
s._write = function(data, enc, cb) {
52-
cb();
53-
};
45+
// Blackhole
46+
s._write = function(data, enc, cb) {
47+
cb();
48+
};
5449

55-
s.destroy = s.destroySoon = function() {
56-
this.writable = false;
57-
};
50+
s.destroy = s.destroySoon = function() {
51+
this.writable = false;
52+
};
5853

59-
return s;
60-
};
54+
return s;
55+
}
56+
}
6157

6258
let received = '';
6359

Collapse file

‎test/parallel/test-pipe-outgoing-message-data-emitted-after-ended.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-pipe-outgoing-message-data-emitted-after-ended.js
+1-5Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@
22
const common = require('../common');
33
const http = require('http');
44
const assert = require('assert');
5-
const util = require('util');
65
const stream = require('stream');
76

87
// Verify that when piping a stream to an `OutgoingMessage` (or a type that
98
// inherits from `OutgoingMessage`), if data is emitted after the
109
// `OutgoingMessage` was closed - a `write after end` error is raised
1110

12-
function MyStream() {
13-
stream.call(this);
14-
}
15-
util.inherits(MyStream, stream);
11+
class MyStream extends stream {}
1612

1713
const server = http.createServer(common.mustCall(function(req, res) {
1814
const myStream = new MyStream();
Collapse file

‎test/parallel/test-readline-interface.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-readline-interface.js
+5-8Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,14 @@ const assert = require('assert');
2727
const readline = require('readline');
2828
const internalReadline = require('internal/readline');
2929
const EventEmitter = require('events').EventEmitter;
30-
const inherits = require('util').inherits;
3130
const { Writable, Readable } = require('stream');
3231

33-
function FakeInput() {
34-
EventEmitter.call(this);
32+
class FakeInput extends EventEmitter {
33+
resume() {}
34+
pause() {}
35+
write() {}
36+
end() {}
3537
}
36-
inherits(FakeInput, EventEmitter);
37-
FakeInput.prototype.resume = () => {};
38-
FakeInput.prototype.pause = () => {};
39-
FakeInput.prototype.write = () => {};
40-
FakeInput.prototype.end = () => {};
4138

4239
function isWarned(emitter) {
4340
for (const name in emitter) {
Collapse file

‎test/parallel/test-readline-keys.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-readline-keys.js
+1-6Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@
22
const common = require('../common');
33
const PassThrough = require('stream').PassThrough;
44
const assert = require('assert');
5-
const inherits = require('util').inherits;
65
const Interface = require('readline').Interface;
76

8-
9-
function FakeInput() {
10-
PassThrough.call(this);
11-
}
12-
inherits(FakeInput, PassThrough);
7+
class FakeInput extends PassThrough {}
138

149
function extend(k) {
1510
return Object.assign({ ctrl: false, meta: false, shift: false }, k);
Collapse file

‎test/parallel/test-stream-big-packet.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-stream-big-packet.js
+13-18Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,26 @@
2222
'use strict';
2323
require('../common');
2424
const assert = require('assert');
25-
const util = require('util');
2625
const stream = require('stream');
2726

2827
let passed = false;
2928

30-
function PassThrough() {
31-
stream.Transform.call(this);
29+
class PassThrough extends stream.Transform {
30+
_transform(chunk, encoding, done) {
31+
this.push(chunk);
32+
done();
33+
}
3234
}
33-
util.inherits(PassThrough, stream.Transform);
34-
PassThrough.prototype._transform = function(chunk, encoding, done) {
35-
this.push(chunk);
36-
done();
37-
};
3835

39-
function TestStream() {
40-
stream.Transform.call(this);
41-
}
42-
util.inherits(TestStream, stream.Transform);
43-
TestStream.prototype._transform = function(chunk, encoding, done) {
44-
if (!passed) {
45-
// Char 'a' only exists in the last write
46-
passed = chunk.toString().includes('a');
36+
class TestStream extends stream.Transform {
37+
_transform(chunk, encoding, done) {
38+
if (!passed) {
39+
// Char 'a' only exists in the last write
40+
passed = chunk.toString().includes('a');
41+
}
42+
done();
4743
}
48-
done();
49-
};
44+
}
5045

5146
const s1 = new PassThrough();
5247
const s2 = new PassThrough();
Collapse file

‎test/parallel/test-stream-events-prepend.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-stream-events-prepend.js
+13-16Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
'use strict';
22
const common = require('../common');
33
const stream = require('stream');
4-
const util = require('util');
54

6-
function Writable() {
7-
this.writable = true;
8-
stream.Writable.call(this);
9-
this.prependListener = undefined;
5+
class Writable extends stream.Writable {
6+
constructor() {
7+
super();
8+
this.prependListener = undefined;
9+
}
10+
11+
_write(chunk, end, cb) {
12+
cb();
13+
}
1014
}
11-
util.inherits(Writable, stream.Writable);
12-
Writable.prototype._write = function(chunk, end, cb) {
13-
cb();
14-
};
1515

16-
function Readable() {
17-
this.readable = true;
18-
stream.Readable.call(this);
16+
class Readable extends stream.Readable {
17+
_read() {
18+
this.push(null);
19+
}
1920
}
20-
util.inherits(Readable, stream.Readable);
21-
Readable.prototype._read = function() {
22-
this.push(null);
23-
};
2421

2522
const w = new Writable();
2623
w.on('pipe', common.mustCall());

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.