GeezerVison is showing github.com — test: use ES6 classes instead of util.inherits · nodejs/node@83f9604
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-crypto-lazy-transform-writable.js +5-6Lines changed: 5 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -7,7 +7,6 @@ if (!common.hasCrypto) | 7 | 7 | const assert = require('assert'); | 8 | 8 | const crypto = require('crypto'); | 9 | 9 | const Stream = require('stream'); | 10 | | -const util = require('util'); | 11 | 10 |
| 12 | 11 | const hasher1 = crypto.createHash('sha256'); | 13 | 12 | const hasher2 = crypto.createHash('sha256'); | @@ -18,12 +17,12 @@ hasher1.end(); | 18 | 17 |
| 19 | 18 | const expected = hasher1.read().toString('hex'); | 20 | 19 |
| 21 | | -function OldStream() { | 22 | | - Stream.call(this); | 23 | | - | 24 | | - this.readable = true; | | 20 | +class OldStream extends Stream { | | 21 | + constructor() { | | 22 | + super(); | | 23 | + this.readable = true; | | 24 | + } | 25 | 25 | } | 26 | | -util.inherits(OldStream, Stream); | 27 | 26 |
| 28 | 27 | const stream = new OldStream(); | 29 | 28 |
| |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-crypto-stream.js +15-15Lines changed: 15 additions & 15 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -26,26 +26,26 @@ if (!common.hasCrypto) | 26 | 26 |
| 27 | 27 | const assert = require('assert'); | 28 | 28 | const stream = require('stream'); | 29 | | -const util = require('util'); | 30 | 29 | const crypto = require('crypto'); | 31 | 30 |
| 32 | | -// Small stream to buffer converter | 33 | | -function Stream2buffer(callback) { | 34 | | - stream.Writable.call(this); | | 31 | +if (!common.hasFipsCrypto) { | | 32 | + // Small stream to buffer converter | | 33 | + class Stream2buffer extends stream.Writable { | | 34 | + constructor(callback) { | | 35 | + super(); | 35 | 36 |
| 36 | | - this._buffers = []; | 37 | | - this.once('finish', function() { | 38 | | - callback(null, Buffer.concat(this._buffers)); | 39 | | - }); | 40 | | -} | 41 | | -util.inherits(Stream2buffer, stream.Writable); | | 37 | + this._buffers = []; | | 38 | + this.once('finish', function() { | | 39 | + callback(null, Buffer.concat(this._buffers)); | | 40 | + }); | | 41 | + } | 42 | 42 |
| 43 | | -Stream2buffer.prototype._write = function(data, encodeing, done) { | 44 | | - this._buffers.push(data); | 45 | | - return done(null); | 46 | | -}; | | 43 | + _write(data, encodeing, done) { | | 44 | + this._buffers.push(data); | | 45 | + return done(null); | | 46 | + } | | 47 | + } | 47 | 48 |
| 48 | | -if (!common.hasFipsCrypto) { | 49 | 49 | // Create an md5 hash of "Hallo world" | 50 | 50 | const hasher1 = crypto.createHash('md5'); | 51 | 51 | hasher1.pipe(new Stream2buffer(common.mustCall(function end(err, hash) { | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-event-emitter-listeners.js +1-3Lines changed: 1 addition & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 24 | 24 | require('../common'); | 25 | 25 | const assert = require('assert'); | 26 | 26 | const events = require('events'); | 27 | | -const util = require('util'); | 28 | 27 |
| 29 | 28 | function listener() {} | 30 | 29 | function listener2() {} | 31 | | -class TestStream { constructor() { } } | 32 | | -util.inherits(TestStream, events.EventEmitter); | 33 | 30 |
| 34 | 31 | { | 35 | 32 | const ee = new events.EventEmitter(); | @@ -81,6 +78,7 @@ util.inherits(TestStream, events.EventEmitter); | 81 | 78 | } | 82 | 79 |
| 83 | 80 | { | | 81 | + class TestStream extends events.EventEmitter {} | 84 | 82 | const s = new TestStream(); | 85 | 83 | assert.deepStrictEqual(s.listeners('foo'), []); | 86 | 84 | } |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-http-client-read-in-error.js +21-25Lines changed: 21 additions & 25 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 | require('../common'); | 3 | 3 | const net = require('net'); | 4 | 4 | const http = require('http'); | 5 | | -const util = require('util'); | 6 | 5 |
| 7 | | -function Agent() { | 8 | | - http.Agent.call(this); | 9 | | -} | 10 | | -util.inherits(Agent, http.Agent); | 11 | | - | 12 | | -Agent.prototype.createConnection = function() { | 13 | | - const self = this; | 14 | | - const socket = new net.Socket(); | | 6 | +class Agent extends http.Agent { | | 7 | + createConnection() { | | 8 | + const socket = new net.Socket(); | 15 | 9 |
| 16 | | - socket.on('error', function() { | 17 | | - socket.push('HTTP/1.1 200\r\n\r\n'); | 18 | | - }); | | 10 | + socket.on('error', function() { | | 11 | + socket.push('HTTP/1.1 200\r\n\r\n'); | | 12 | + }); | 19 | 13 |
| 20 | | - socket.on('newListener', function onNewListener(name) { | 21 | | - if (name !== 'error') | 22 | | - return; | 23 | | - socket.removeListener('newListener', onNewListener); | | 14 | + let onNewListener; | | 15 | + socket.on('newListener', onNewListener = (name) => { | | 16 | + if (name !== 'error') | | 17 | + return; | | 18 | + socket.removeListener('newListener', onNewListener); | 24 | 19 |
| 25 | | - // Let other listeners to be set up too | 26 | | - process.nextTick(function() { | 27 | | - self.breakSocket(socket); | | 20 | + // Let other listeners to be set up too | | 21 | + process.nextTick(() => { | | 22 | + this.breakSocket(socket); | | 23 | + }); | 28 | 24 | }); | 29 | | - }); | 30 | 25 |
| 31 | | - return socket; | 32 | | -}; | | 26 | + return socket; | | 27 | + } | 33 | 28 |
| 34 | | -Agent.prototype.breakSocket = function breakSocket(socket) { | 35 | | - socket.emit('error', new Error('Intentional error')); | 36 | | -}; | | 29 | + breakSocket(socket) { | | 30 | + socket.emit('error', new Error('Intentional error')); | | 31 | + } | | 32 | +} | 37 | 33 |
| 38 | 34 | const agent = new Agent(); | 39 | 35 |
| |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-http-client-readable.js +23-27Lines changed: 23 additions & 27 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 23 | 23 | const common = require('../common'); | 24 | 24 | const assert = require('assert'); | 25 | 25 | const http = require('http'); | 26 | | -const util = require('util'); | 27 | 26 |
| 28 | 27 | const Duplex = require('stream').Duplex; | 29 | 28 |
| 30 | | -function FakeAgent() { | 31 | | - http.Agent.call(this); | 32 | | -} | 33 | | -util.inherits(FakeAgent, http.Agent); | 34 | | - | 35 | | -FakeAgent.prototype.createConnection = function() { | 36 | | - const s = new Duplex(); | 37 | | - let once = false; | | 29 | +class FakeAgent extends http.Agent { | | 30 | + createConnection() { | | 31 | + const s = new Duplex(); | | 32 | + let once = false; | 38 | 33 |
| 39 | | - s._read = function() { | 40 | | - if (once) | 41 | | - return this.push(null); | 42 | | - once = true; | | 34 | + s._read = function() { | | 35 | + if (once) | | 36 | + return this.push(null); | | 37 | + once = true; | 43 | 38 |
| 44 | | - this.push('HTTP/1.1 200 Ok\r\nTransfer-Encoding: chunked\r\n\r\n'); | 45 | | - this.push('b\r\nhello world\r\n'); | 46 | | - this.readable = false; | 47 | | - this.push('0\r\n\r\n'); | 48 | | - }; | | 39 | + this.push('HTTP/1.1 200 Ok\r\nTransfer-Encoding: chunked\r\n\r\n'); | | 40 | + this.push('b\r\nhello world\r\n'); | | 41 | + this.readable = false; | | 42 | + this.push('0\r\n\r\n'); | | 43 | + }; | 49 | 44 |
| 50 | | - // Blackhole | 51 | | - s._write = function(data, enc, cb) { | 52 | | - cb(); | 53 | | - }; | | 45 | + // Blackhole | | 46 | + s._write = function(data, enc, cb) { | | 47 | + cb(); | | 48 | + }; | 54 | 49 |
| 55 | | - s.destroy = s.destroySoon = function() { | 56 | | - this.writable = false; | 57 | | - }; | | 50 | + s.destroy = s.destroySoon = function() { | | 51 | + this.writable = false; | | 52 | + }; | 58 | 53 |
| 59 | | - return s; | 60 | | -}; | | 54 | + return s; | | 55 | + } | | 56 | +} | 61 | 57 |
| 62 | 58 | let received = ''; | 63 | 59 |
| |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-pipe-outgoing-message-data-emitted-after-ended.js +1-5Lines changed: 1 addition & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 | const common = require('../common'); | 3 | 3 | const http = require('http'); | 4 | 4 | const assert = require('assert'); | 5 | | -const util = require('util'); | 6 | 5 | const stream = require('stream'); | 7 | 6 |
| 8 | 7 | // Verify that when piping a stream to an `OutgoingMessage` (or a type that | 9 | 8 | // inherits from `OutgoingMessage`), if data is emitted after the | 10 | 9 | // `OutgoingMessage` was closed - a `write after end` error is raised | 11 | 10 |
| 12 | | -function MyStream() { | 13 | | - stream.call(this); | 14 | | -} | 15 | | -util.inherits(MyStream, stream); | | 11 | +class MyStream extends stream {} | 16 | 12 |
| 17 | 13 | const server = http.createServer(common.mustCall(function(req, res) { | 18 | 14 | const myStream = new MyStream(); | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-readline-interface.js +5-8Lines changed: 5 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -27,17 +27,14 @@ const assert = require('assert'); | 27 | 27 | const readline = require('readline'); | 28 | 28 | const internalReadline = require('internal/readline'); | 29 | 29 | const EventEmitter = require('events').EventEmitter; | 30 | | -const inherits = require('util').inherits; | 31 | 30 | const { Writable, Readable } = require('stream'); | 32 | 31 |
| 33 | | -function FakeInput() { | 34 | | - EventEmitter.call(this); | | 32 | +class FakeInput extends EventEmitter { | | 33 | + resume() {} | | 34 | + pause() {} | | 35 | + write() {} | | 36 | + end() {} | 35 | 37 | } | 36 | | -inherits(FakeInput, EventEmitter); | 37 | | -FakeInput.prototype.resume = () => {}; | 38 | | -FakeInput.prototype.pause = () => {}; | 39 | | -FakeInput.prototype.write = () => {}; | 40 | | -FakeInput.prototype.end = () => {}; | 41 | 38 |
| 42 | 39 | function isWarned(emitter) { | 43 | 40 | for (const name in emitter) { | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-readline-keys.js +1-6Lines changed: 1 addition & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 | const common = require('../common'); | 3 | 3 | const PassThrough = require('stream').PassThrough; | 4 | 4 | const assert = require('assert'); | 5 | | -const inherits = require('util').inherits; | 6 | 5 | const Interface = require('readline').Interface; | 7 | 6 |
| 8 | | - | 9 | | -function FakeInput() { | 10 | | - PassThrough.call(this); | 11 | | -} | 12 | | -inherits(FakeInput, PassThrough); | | 7 | +class FakeInput extends PassThrough {} | 13 | 8 |
| 14 | 9 | function extend(k) { | 15 | 10 | return Object.assign({ ctrl: false, meta: false, shift: false }, k); | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-stream-big-packet.js +13-18Lines changed: 13 additions & 18 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 22 | 22 | 'use strict'; | 23 | 23 | require('../common'); | 24 | 24 | const assert = require('assert'); | 25 | | -const util = require('util'); | 26 | 25 | const stream = require('stream'); | 27 | 26 |
| 28 | 27 | let passed = false; | 29 | 28 |
| 30 | | -function PassThrough() { | 31 | | - stream.Transform.call(this); | | 29 | +class PassThrough extends stream.Transform { | | 30 | + _transform(chunk, encoding, done) { | | 31 | + this.push(chunk); | | 32 | + done(); | | 33 | + } | 32 | 34 | } | 33 | | -util.inherits(PassThrough, stream.Transform); | 34 | | -PassThrough.prototype._transform = function(chunk, encoding, done) { | 35 | | - this.push(chunk); | 36 | | - done(); | 37 | | -}; | 38 | 35 |
| 39 | | -function TestStream() { | 40 | | - stream.Transform.call(this); | 41 | | -} | 42 | | -util.inherits(TestStream, stream.Transform); | 43 | | -TestStream.prototype._transform = function(chunk, encoding, done) { | 44 | | - if (!passed) { | 45 | | - // Char 'a' only exists in the last write | 46 | | - passed = chunk.toString().includes('a'); | | 36 | +class TestStream extends stream.Transform { | | 37 | + _transform(chunk, encoding, done) { | | 38 | + if (!passed) { | | 39 | + // Char 'a' only exists in the last write | | 40 | + passed = chunk.toString().includes('a'); | | 41 | + } | | 42 | + done(); | 47 | 43 | } | 48 | | - done(); | 49 | | -}; | | 44 | +} | 50 | 45 |
| 51 | 46 | const s1 = new PassThrough(); | 52 | 47 | const s2 = new PassThrough(); | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-stream-events-prepend.js +13-16Lines changed: 13 additions & 16 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | 'use strict'; | 2 | 2 | const common = require('../common'); | 3 | 3 | const stream = require('stream'); | 4 | | -const util = require('util'); | 5 | 4 |
| 6 | | -function Writable() { | 7 | | - this.writable = true; | 8 | | - stream.Writable.call(this); | 9 | | - this.prependListener = undefined; | | 5 | +class Writable extends stream.Writable { | | 6 | + constructor() { | | 7 | + super(); | | 8 | + this.prependListener = undefined; | | 9 | + } | | 10 | + | | 11 | + _write(chunk, end, cb) { | | 12 | + cb(); | | 13 | + } | 10 | 14 | } | 11 | | -util.inherits(Writable, stream.Writable); | 12 | | -Writable.prototype._write = function(chunk, end, cb) { | 13 | | - cb(); | 14 | | -}; | 15 | 15 |
| 16 | | -function Readable() { | 17 | | - this.readable = true; | 18 | | - stream.Readable.call(this); | | 16 | +class Readable extends stream.Readable { | | 17 | + _read() { | | 18 | + this.push(null); | | 19 | + } | 19 | 20 | } | 20 | | -util.inherits(Readable, stream.Readable); | 21 | | -Readable.prototype._read = function() { | 22 | | - this.push(null); | 23 | | -}; | 24 | 21 |
| 25 | 22 | const w = new Writable(); | 26 | 23 | w.on('pipe', common.mustCall()); | |
|