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

+27
-30
lines changed

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ if (cluster.isWorker) {
3232
// start worker
3333
var worker = cluster.fork();
3434

35-
var socket;
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+
const socket = 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

+1-2
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-
var req = 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

+6-8
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,24 @@ os.homedir = function() {
2121
class ActionStream extends stream.Stream {
2222
run(data) {
2323
const _iter = data[Symbol.iterator]();
24-
const self = this;
25-
26-
function doAction() {
24+
const doAction = () => {
2725
const next = _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
const action = next.value;
3634

3735
if (typeof action === '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

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

104104
SlowStream.prototype.resume = function() {
105-
var self = this;
106-
if (self.ended) return;
107-
self.emit('resume');
108-
if (!self.chunk) return;
109-
self.paused = false;
110-
emit();
111-
function emit() {
112-
if (self.paused) return;
113-
if (self.offset >= self.length) {
114-
self.ended = true;
115-
return self.emit('end');
105+
const emit = () => {
106+
if (this.paused) return;
107+
if (this.offset >= this.length) {
108+
this.ended = true;
109+
return this.emit('end');
116110
}
117-
var end = Math.min(self.offset + self.trickle, self.length);
118-
var c = self.chunk.slice(self.offset, end);
119-
self.offset += c.length;
120-
self.emit('data', c);
111+
var end = Math.min(this.offset + this.trickle, this.length);
112+
var c = 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)