Skip to content

Commit 83f9604

Browse 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

25 files changed

Lines changed: 364 additions & 422 deletions

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ if (!common.hasCrypto)
77
constassert=require('assert');
88
constcrypto=require('crypto');
99
constStream=require('stream');
10-
constutil=require('util');
1110

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

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

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

2827
conststream=newOldStream();
2928

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,26 @@ if (!common.hasCrypto)
2626

2727
constassert=require('assert');
2828
conststream=require('stream');
29-
constutil=require('util');
3029
constcrypto=require('crypto');
3130

32-
// Small stream to buffer converter
33-
functionStream2buffer(callback){
34-
stream.Writable.call(this);
31+
if(!common.hasFipsCrypto){
32+
// Small stream to buffer converter
33+
classStream2bufferextendsstream.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-
returndone(null);
46-
};
43+
_write(data,encodeing,done){
44+
this._buffers.push(data);
45+
returndone(null);
46+
}
47+
}
4748

48-
if(!common.hasFipsCrypto){
4949
// Create an md5 hash of "Hallo world"
5050
consthasher1=crypto.createHash('md5');
5151
hasher1.pipe(newStream2buffer(common.mustCall(functionend(err,hash){

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,9 @@
2424
require('../common');
2525
constassert=require('assert');
2626
constevents=require('events');
27-
constutil=require('util');
2827

2928
functionlistener(){}
3029
functionlistener2(){}
31-
classTestStream{constructor(){}}
32-
util.inherits(TestStream,events.EventEmitter);
3330

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

8380
{
81+
classTestStreamextendsevents.EventEmitter{}
8482
consts=newTestStream();
8583
assert.deepStrictEqual(s.listeners('foo'),[]);
8684
}

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

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,34 @@
22
require('../common');
33
constnet=require('net');
44
consthttp=require('http');
5-
constutil=require('util');
65

7-
functionAgent(){
8-
http.Agent.call(this);
9-
}
10-
util.inherits(Agent,http.Agent);
11-
12-
Agent.prototype.createConnection=function(){
13-
constself=this;
14-
constsocket=newnet.Socket();
6+
classAgentextendshttp.Agent{
7+
createConnection(){
8+
constsocket=newnet.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',functiononNewListener(name){
21-
if(name!=='error')
22-
return;
23-
socket.removeListener('newListener',onNewListener);
14+
letonNewListener;
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-
returnsocket;
32-
};
26+
returnsocket;
27+
}
3328

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

3834
constagent=newAgent();
3935

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

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,41 +23,37 @@
2323
constcommon=require('../common');
2424
constassert=require('assert');
2525
consthttp=require('http');
26-
constutil=require('util');
2726

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

30-
functionFakeAgent(){
31-
http.Agent.call(this);
32-
}
33-
util.inherits(FakeAgent,http.Agent);
34-
35-
FakeAgent.prototype.createConnection=function(){
36-
consts=newDuplex();
37-
letonce=false;
29+
classFakeAgentextendshttp.Agent{
30+
createConnection(){
31+
consts=newDuplex();
32+
letonce=false;
3833

39-
s._read=function(){
40-
if(once)
41-
returnthis.push(null);
42-
once=true;
34+
s._read=function(){
35+
if(once)
36+
returnthis.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-
returns;
60-
};
54+
returns;
55+
}
56+
}
6157

6258
letreceived='';
6359

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@
22
constcommon=require('../common');
33
consthttp=require('http');
44
constassert=require('assert');
5-
constutil=require('util');
65
conststream=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-
functionMyStream(){
13-
stream.call(this);
14-
}
15-
util.inherits(MyStream,stream);
11+
classMyStreamextendsstream{}
1612

1713
constserver=http.createServer(common.mustCall(function(req,res){
1814
constmyStream=newMyStream();

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,14 @@ const assert = require('assert');
2727
constreadline=require('readline');
2828
constinternalReadline=require('internal/readline');
2929
constEventEmitter=require('events').EventEmitter;
30-
constinherits=require('util').inherits;
3130
const{ Writable, Readable }=require('stream');
3231

33-
functionFakeInput(){
34-
EventEmitter.call(this);
32+
classFakeInputextendsEventEmitter{
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
functionisWarned(emitter){
4340
for(constnameinemitter){

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@
22
constcommon=require('../common');
33
constPassThrough=require('stream').PassThrough;
44
constassert=require('assert');
5-
constinherits=require('util').inherits;
65
constInterface=require('readline').Interface;
76

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

149
functionextend(k){
1510
returnObject.assign({ctrl: false,meta: false,shift: false},k);

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

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,26 @@
2222
'use strict';
2323
require('../common');
2424
constassert=require('assert');
25-
constutil=require('util');
2625
conststream=require('stream');
2726

2827
letpassed=false;
2928

30-
functionPassThrough(){
31-
stream.Transform.call(this);
29+
classPassThroughextendsstream.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-
functionTestStream(){
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+
classTestStreamextendsstream.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
consts1=newPassThrough();
5247
consts2=newPassThrough();

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

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
'use strict';
22
constcommon=require('../common');
33
conststream=require('stream');
4-
constutil=require('util');
54

6-
functionWritable(){
7-
this.writable=true;
8-
stream.Writable.call(this);
9-
this.prependListener=undefined;
5+
classWritableextendsstream.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-
functionReadable(){
17-
this.readable=true;
18-
stream.Readable.call(this);
16+
classReadableextendsstream.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
constw=newWritable();
2623
w.on('pipe',common.mustCall());

0 commit comments

Comments
 (0)