From 0278e380de36977ec853ec610c192a08dd2a0101 Mon Sep 17 00:00:00 2001 From: Felix Rieseberg Date: Thu, 23 Nov 2017 14:22:31 -0800 Subject: [PATCH] =?UTF-8?q?:wrench:=20Spec:=20Don=E2=80=99t=20use=20deprec?= =?UTF-8?q?ated=20`new=20Buffer()`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/api-browser-window-spec.js | 4 ++-- spec/api-ipc-spec.js | 4 ++-- spec/api-protocol-spec.js | 6 +++--- spec/api-session-spec.js | 4 ++-- spec/asar-spec.js | 6 +++--- spec/node-spec.js | 8 ++++---- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index 2adc82df05d0..066d47d9b708 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -27,7 +27,7 @@ describe('BrowserWindow module', () => { postData = [ { type: 'rawData', - bytes: new Buffer('username=test&file=') + bytes: Buffer.from('username=test&file=') }, { type: 'file', @@ -270,7 +270,7 @@ describe('BrowserWindow module', () => { assert.equal(isMainFrame, true) done() }) - const data = new Buffer(2 * 1024 * 1024).toString('base64') + const data = Buffer.alloc(2 * 1024 * 1024).toString('base64') w.loadURL(`data:image/png;base64,${data}`) }) diff --git a/spec/api-ipc-spec.js b/spec/api-ipc-spec.js index 79f7c0927037..4bb563184ad2 100644 --- a/spec/api-ipc-spec.js +++ b/spec/api-ipc-spec.js @@ -145,7 +145,7 @@ describe('ipc module', () => { describe('remote.createFunctionWithReturnValue', () => { it('should be called in browser synchronously', () => { - const buf = new Buffer('test') + const buf = Buffer.from('test') const call = remote.require(path.join(fixtures, 'module', 'call.js')) const result = call.call(remote.createFunctionWithReturnValue(buf)) assert.equal(result.constructor.name, 'Buffer') @@ -239,7 +239,7 @@ describe('ipc module', () => { const printName = remote.require(print) it('keeps its constructor name for objects', () => { - const buf = new Buffer('test') + const buf = Buffer.from('test') assert.equal(printName.print(buf), 'Buffer') }) diff --git a/spec/api-protocol-spec.js b/spec/api-protocol-spec.js index 2d76d49c6a53..a9d69867157b 100644 --- a/spec/api-protocol-spec.js +++ b/spec/api-protocol-spec.js @@ -28,7 +28,7 @@ describe('protocol module', () => { const body = stream.PassThrough() async function sendChunks () { - let buf = new Buffer(data) + let buf = Buffer.from(data) for (;;) { body.push(buf.slice(0, chunkSize)) buf = buf.slice(chunkSize) @@ -204,7 +204,7 @@ describe('protocol module', () => { }) describe('protocol.registerBufferProtocol', () => { - const buffer = new Buffer(text) + const buffer = Buffer.from(text) it('sends Buffer as response', (done) => { const handler = (request, callback) => callback(buffer) protocol.registerBufferProtocol(protocolName, handler, (error) => { @@ -767,7 +767,7 @@ describe('protocol module', () => { describe('protocol.interceptBufferProtocol', () => { it('can intercept http protocol', (done) => { - const handler = (request, callback) => callback(new Buffer(text)) + const handler = (request, callback) => callback(Buffer.from(text)) protocol.interceptBufferProtocol('http', handler, (error) => { if (error) return done(error) $.ajax({ diff --git a/spec/api-session-spec.js b/spec/api-session-spec.js index 54235a334a54..50504ccadae1 100644 --- a/spec/api-session-spec.js +++ b/spec/api-session-spec.js @@ -242,7 +242,7 @@ describe('session module', () => { }) it('can cancel default download behavior', (done) => { - const mockFile = new Buffer(1024) + const mockFile = Buffer.alloc(1024) const contentDisposition = 'inline; filename="mockFile.txt"' const downloadServer = http.createServer((req, res) => { res.writeHead(200, { @@ -271,7 +271,7 @@ describe('session module', () => { }) describe('DownloadItem', () => { - const mockPDF = new Buffer(1024 * 1024 * 5) + const mockPDF = Buffer.alloc(1024 * 1024 * 5) let contentDisposition = 'inline; filename="mock.pdf"' const downloadFilePath = path.join(fixtures, 'mock.pdf') const downloadServer = http.createServer((req, res) => { diff --git a/spec/asar-spec.js b/spec/asar-spec.js index 31f15ef77284..f87554f32e26 100644 --- a/spec/asar-spec.js +++ b/spec/asar-spec.js @@ -15,7 +15,7 @@ describe('asar package', function () { describe('node api', function () { it('supports paths specified as a Buffer', function () { - var file = new Buffer(path.join(fixtures, 'asar', 'a.asar', 'file1')) + var file = Buffer.from(path.join(fixtures, 'asar', 'a.asar', 'file1')) assert.equal(fs.existsSync(file), true) }) @@ -491,7 +491,7 @@ describe('asar package', function () { file = ref2[j] p = path.join(fixtures, 'asar', 'a.asar', file) fd = fs.openSync(p, 'r') - buffer = new Buffer(6) + buffer = Buffer.alloc(6) fs.readSync(fd, buffer, 0, 6, 0) assert.equal(String(buffer).trim(), 'file1') fs.closeSync(fd) @@ -512,7 +512,7 @@ describe('asar package', function () { var p = path.join(fixtures, 'asar', 'a.asar', 'file1') fs.open(p, 'r', function (err, fd) { assert.equal(err, null) - var buffer = new Buffer(6) + var buffer = Buffer.alloc(6) fs.read(fd, buffer, 0, 6, 0, function (err) { assert.equal(err, null) assert.equal(String(buffer).trim(), 'file1') diff --git a/spec/node-spec.js b/spec/node-spec.js index 57cb31e2b528..ae639167ff07 100644 --- a/spec/node-spec.js +++ b/spec/node-spec.js @@ -274,7 +274,7 @@ describe('node feature', () => { it('can be created from WebKit external string', () => { const p = document.createElement('p') p.innerText = '闲云潭影日悠悠,物换星移几度秋' - const b = new Buffer(p.innerText) + const b = Buffer.from(p.innerText) assert.equal(b.toString(), '闲云潭影日悠悠,物换星移几度秋') assert.equal(Buffer.byteLength(p.innerText), 45) }) @@ -282,15 +282,15 @@ describe('node feature', () => { it('correctly parses external one-byte UTF8 string', () => { const p = document.createElement('p') p.innerText = 'Jøhänñéß' - const b = new Buffer(p.innerText) + const b = Buffer.from(p.innerText) assert.equal(b.toString(), 'Jøhänñéß') assert.equal(Buffer.byteLength(p.innerText), 13) }) it('does not crash when creating large Buffers', () => { - let buffer = new Buffer(new Array(4096).join(' ')) + let buffer = Buffer.from(new Array(4096).join(' ')) assert.equal(buffer.length, 4095) - buffer = new Buffer(new Array(4097).join(' ')) + buffer = Buffer.from(new Array(4097).join(' ')) assert.equal(buffer.length, 4096) }) })