Skip to content

Commit 6971630

Browse files
cjihrigMylesBorins
authored andcommitted
test: avoid assigning this to variables
This commit removes assignments of this to a variable in the tests. PR-URL: #10548 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent f45793c commit 6971630

4 files changed

Lines changed: 27 additions & 30 deletions

File tree

‎test/parallel/test-cluster-worker-wait-server-close.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ if (cluster.isWorker) {
3232
// start worker
3333
varworker=cluster.fork();
3434

35-
varsocket;
3635
// Disconnect worker when it is ready
3736
worker.once('listening',function(){
38-
net.createConnection(common.PORT,common.localhostIPv4,function(){
39-
socket=this;
40-
this.on('data',function(){
37+
constsocket=net.createConnection(common.PORT,common.localhostIPv4);
38+
39+
socket.on('connect',function(){
40+
socket.on('data',function(){
4141
console.log('got data from client');
4242
// socket definitely connected to worker if we got data
4343
worker.disconnect();

‎test/parallel/test-http-client-timeout-agent.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ server.listen(0, options.host, function() {
5050
this.destroy();
5151
});
5252
req.setTimeout(50,function(){
53-
varreq=this;
5453
console.log('req#'+this.id+' timeout');
55-
req.abort();
54+
this.abort();
5655
requests_done+=1;
5756
});
5857
req.end();

‎test/parallel/test-repl-persistent-history.js‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,24 @@ os.homedir = function() {
2121
classActionStreamextendsstream.Stream{
2222
run(data){
2323
const_iter=data[Symbol.iterator]();
24-
constself=this;
25-
26-
functiondoAction(){
24+
constdoAction=()=>{
2725
constnext=_iter.next();
2826
if(next.done){
2927
// Close the repl. Note that it must have a clean prompt to do so.
30-
setImmediate(function(){
31-
self.emit('keypress','',{ctrl: true,name: 'd'});
28+
setImmediate(()=>{
29+
this.emit('keypress','',{ctrl: true,name: 'd'});
3230
});
3331
return;
3432
}
3533
constaction=next.value;
3634

3735
if(typeofaction==='object'){
38-
self.emit('keypress','',action);
36+
this.emit('keypress','',action);
3937
}else{
40-
self.emit('data',action+'\n');
38+
this.emit('data',action+'\n');
4139
}
4240
setImmediate(doAction);
43-
}
41+
};
4442
setImmediate(doAction);
4543
}
4644
resume(){}

‎test/parallel/test-zlib.js‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,24 +102,24 @@ SlowStream.prototype.pause = function() {
102102
};
103103

104104
SlowStream.prototype.resume=function(){
105-
varself=this;
106-
if(self.ended)return;
107-
self.emit('resume');
108-
if(!self.chunk)return;
109-
self.paused=false;
110-
emit();
111-
functionemit(){
112-
if(self.paused)return;
113-
if(self.offset>=self.length){
114-
self.ended=true;
115-
returnself.emit('end');
105+
constemit=()=>{
106+
if(this.paused)return;
107+
if(this.offset>=this.length){
108+
this.ended=true;
109+
returnthis.emit('end');
116110
}
117-
varend=Math.min(self.offset+self.trickle,self.length);
118-
varc=self.chunk.slice(self.offset,end);
119-
self.offset+=c.length;
120-
self.emit('data',c);
111+
varend=Math.min(this.offset+this.trickle,this.length);
112+
varc=this.chunk.slice(this.offset,end);
113+
this.offset+=c.length;
114+
this.emit('data',c);
121115
process.nextTick(emit);
122-
}
116+
};
117+
118+
if(this.ended)return;
119+
this.emit('resume');
120+
if(!this.chunk)return;
121+
this.paused=false;
122+
emit();
123123
};
124124

125125
SlowStream.prototype.end=function(chunk){

0 commit comments

Comments
 (0)