-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: use ES6 classes instead of util.inherits #16938
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,12 +24,10 @@ | |
require('../common'); | ||
const assert = require('assert'); | ||
const events = require('events'); | ||
const util = require('util'); | ||
|
||
function listener() {} | ||
function listener2() {} | ||
class TestStream { constructor() { } } | ||
util.inherits(TestStream, events.EventEmitter); | ||
class TestStream extends events.EventEmitter {} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment as above - confining the scope into the block where it is used. |
||
{ | ||
const ee = new events.EventEmitter(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,38 +2,34 @@ | |
require('../common'); | ||
const net = require('net'); | ||
const http = require('http'); | ||
const util = require('util'); | ||
|
||
function Agent() { | ||
http.Agent.call(this); | ||
} | ||
util.inherits(Agent, http.Agent); | ||
|
||
Agent.prototype.createConnection = function() { | ||
const self = this; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about eliminating the need for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did that in a couple of other places, seems like I missed it here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh I remember why I did not do it, because it is simpler to remove the listener this way. Can still refactor it, but it's not pretty. |
||
const socket = new net.Socket(); | ||
class Agent extends http.Agent { | ||
createConnection() { | ||
const self = this; | ||
const socket = new net.Socket(); | ||
|
||
socket.on('error', function() { | ||
socket.push('HTTP/1.1 200\r\n\r\n'); | ||
}); | ||
socket.on('error', function() { | ||
socket.push('HTTP/1.1 200\r\n\r\n'); | ||
}); | ||
|
||
socket.on('newListener', function onNewListener(name) { | ||
if (name !== 'error') | ||
return; | ||
socket.removeListener('newListener', onNewListener); | ||
socket.on('newListener', function onNewListener(name) { | ||
if (name !== 'error') | ||
return; | ||
socket.removeListener('newListener', onNewListener); | ||
|
||
// Let other listeners to be set up too | ||
process.nextTick(function() { | ||
self.breakSocket(socket); | ||
// Let other listeners to be set up too | ||
process.nextTick(function() { | ||
self.breakSocket(socket); | ||
}); | ||
}); | ||
}); | ||
|
||
return socket; | ||
}; | ||
return socket; | ||
} | ||
|
||
Agent.prototype.breakSocket = function breakSocket(socket) { | ||
socket.emit('error', new Error('Intentional error')); | ||
}; | ||
breakSocket(socket) { | ||
socket.emit('error', new Error('Intentional error')); | ||
} | ||
} | ||
|
||
const agent = new Agent(); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(while we are here) how about eclosing the class definition inside the
common.hasFipsCrypto
block as it is used only if the conditional is met?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean enclosing