Skip to content

Commit f5e54f5

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 28a5ce1 commit f5e54f5

File tree

4 files changed

+27
-30
lines changed

4 files changed

+27
-30
lines changed

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
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

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-
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

Lines changed: 6 additions & 8 deletions
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

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

105105
SlowStream.prototype.resume = function() {
106-
var self = this;
107-
if (self.ended) return;
108-
self.emit('resume');
109-
if (!self.chunk) return;
110-
self.paused = false;
111-
emit();
112-
function emit() {
113-
if (self.paused) return;
114-
if (self.offset >= self.length) {
115-
self.ended = true;
116-
return self.emit('end');
106+
const emit = () => {
107+
if (this.paused) return;
108+
if (this.offset >= this.length) {
109+
this.ended = true;
110+
return this.emit('end');
117111
}
118-
var end = Math.min(self.offset + self.trickle, self.length);
119-
var c = self.chunk.slice(self.offset, end);
120-
self.offset += c.length;
121-
self.emit('data', c);
112+
var end = Math.min(this.offset + this.trickle, this.length);
113+
var c = this.chunk.slice(this.offset, end);
114+
this.offset += c.length;
115+
this.emit('data', c);
122116
process.nextTick(emit);
123-
}
117+
};
118+
119+
if (this.ended) return;
120+
this.emit('resume');
121+
if (!this.chunk) return;
122+
this.paused = false;
123+
emit();
124124
};
125125

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

0 commit comments

Comments
 (0)