test: changed function to arrow function
Convert callback functions that are anonymous to arrow functions for better readability. Also adjusted the `this` object in places where that was required. PR-URL: https://github.com/nodejs/node/pull/28726 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Masashi Hirano <shisama07@gmail.com> Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
parent
21ec137859
commit
19b21987d2
@ -40,7 +40,7 @@ const http = require('http');
|
|||||||
// content-length is not provided, that the connection is in fact
|
// content-length is not provided, that the connection is in fact
|
||||||
// closed.
|
// closed.
|
||||||
|
|
||||||
const server = http.createServer(function(req, res) {
|
const server = http.createServer((req, res) => {
|
||||||
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
||||||
res.write('hello ');
|
res.write('hello ');
|
||||||
res.write('world\n');
|
res.write('world\n');
|
||||||
@ -48,30 +48,30 @@ const server = http.createServer(function(req, res) {
|
|||||||
});
|
});
|
||||||
server.listen(0);
|
server.listen(0);
|
||||||
|
|
||||||
server.on('listening', common.mustCall(function() {
|
server.on('listening', common.mustCall(() => {
|
||||||
const c = net.createConnection(this.address().port);
|
const c = net.createConnection(server.address().port);
|
||||||
let server_response = '';
|
let server_response = '';
|
||||||
|
|
||||||
c.setEncoding('utf8');
|
c.setEncoding('utf8');
|
||||||
|
|
||||||
c.on('connect', function() {
|
c.on('connect', () => {
|
||||||
c.write('GET / HTTP/1.0\r\n' +
|
c.write('GET / HTTP/1.0\r\n' +
|
||||||
'Connection: Keep-Alive\r\n\r\n');
|
'Connection: Keep-Alive\r\n\r\n');
|
||||||
});
|
});
|
||||||
|
|
||||||
c.on('data', function(chunk) {
|
c.on('data', (chunk) => {
|
||||||
console.log(chunk);
|
console.log(chunk);
|
||||||
server_response += chunk;
|
server_response += chunk;
|
||||||
});
|
});
|
||||||
|
|
||||||
c.on('end', common.mustCall(function() {
|
c.on('end', common.mustCall(() => {
|
||||||
const m = server_response.split('\r\n\r\n');
|
const m = server_response.split('\r\n\r\n');
|
||||||
assert.strictEqual(m[1], 'hello world\n');
|
assert.strictEqual(m[1], 'hello world\n');
|
||||||
console.log('got end');
|
console.log('got end');
|
||||||
c.end();
|
c.end();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
c.on('close', common.mustCall(function() {
|
c.on('close', common.mustCall(() => {
|
||||||
console.log('got close');
|
console.log('got close');
|
||||||
server.close();
|
server.close();
|
||||||
}));
|
}));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user