🔧 Spec: Don’t use deprecated new Buffer()
This commit is contained in:
parent
f7d6e3fa7b
commit
0278e380de
6 changed files with 16 additions and 16 deletions
|
@ -27,7 +27,7 @@ describe('BrowserWindow module', () => {
|
||||||
postData = [
|
postData = [
|
||||||
{
|
{
|
||||||
type: 'rawData',
|
type: 'rawData',
|
||||||
bytes: new Buffer('username=test&file=')
|
bytes: Buffer.from('username=test&file=')
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'file',
|
type: 'file',
|
||||||
|
@ -270,7 +270,7 @@ describe('BrowserWindow module', () => {
|
||||||
assert.equal(isMainFrame, true)
|
assert.equal(isMainFrame, true)
|
||||||
done()
|
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}`)
|
w.loadURL(`data:image/png;base64,${data}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -145,7 +145,7 @@ describe('ipc module', () => {
|
||||||
|
|
||||||
describe('remote.createFunctionWithReturnValue', () => {
|
describe('remote.createFunctionWithReturnValue', () => {
|
||||||
it('should be called in browser synchronously', () => {
|
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 call = remote.require(path.join(fixtures, 'module', 'call.js'))
|
||||||
const result = call.call(remote.createFunctionWithReturnValue(buf))
|
const result = call.call(remote.createFunctionWithReturnValue(buf))
|
||||||
assert.equal(result.constructor.name, 'Buffer')
|
assert.equal(result.constructor.name, 'Buffer')
|
||||||
|
@ -239,7 +239,7 @@ describe('ipc module', () => {
|
||||||
const printName = remote.require(print)
|
const printName = remote.require(print)
|
||||||
|
|
||||||
it('keeps its constructor name for objects', () => {
|
it('keeps its constructor name for objects', () => {
|
||||||
const buf = new Buffer('test')
|
const buf = Buffer.from('test')
|
||||||
assert.equal(printName.print(buf), 'Buffer')
|
assert.equal(printName.print(buf), 'Buffer')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ describe('protocol module', () => {
|
||||||
const body = stream.PassThrough()
|
const body = stream.PassThrough()
|
||||||
|
|
||||||
async function sendChunks () {
|
async function sendChunks () {
|
||||||
let buf = new Buffer(data)
|
let buf = Buffer.from(data)
|
||||||
for (;;) {
|
for (;;) {
|
||||||
body.push(buf.slice(0, chunkSize))
|
body.push(buf.slice(0, chunkSize))
|
||||||
buf = buf.slice(chunkSize)
|
buf = buf.slice(chunkSize)
|
||||||
|
@ -204,7 +204,7 @@ describe('protocol module', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('protocol.registerBufferProtocol', () => {
|
describe('protocol.registerBufferProtocol', () => {
|
||||||
const buffer = new Buffer(text)
|
const buffer = Buffer.from(text)
|
||||||
it('sends Buffer as response', (done) => {
|
it('sends Buffer as response', (done) => {
|
||||||
const handler = (request, callback) => callback(buffer)
|
const handler = (request, callback) => callback(buffer)
|
||||||
protocol.registerBufferProtocol(protocolName, handler, (error) => {
|
protocol.registerBufferProtocol(protocolName, handler, (error) => {
|
||||||
|
@ -767,7 +767,7 @@ describe('protocol module', () => {
|
||||||
|
|
||||||
describe('protocol.interceptBufferProtocol', () => {
|
describe('protocol.interceptBufferProtocol', () => {
|
||||||
it('can intercept http protocol', (done) => {
|
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) => {
|
protocol.interceptBufferProtocol('http', handler, (error) => {
|
||||||
if (error) return done(error)
|
if (error) return done(error)
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
|
|
@ -242,7 +242,7 @@ describe('session module', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can cancel default download behavior', (done) => {
|
it('can cancel default download behavior', (done) => {
|
||||||
const mockFile = new Buffer(1024)
|
const mockFile = Buffer.alloc(1024)
|
||||||
const contentDisposition = 'inline; filename="mockFile.txt"'
|
const contentDisposition = 'inline; filename="mockFile.txt"'
|
||||||
const downloadServer = http.createServer((req, res) => {
|
const downloadServer = http.createServer((req, res) => {
|
||||||
res.writeHead(200, {
|
res.writeHead(200, {
|
||||||
|
@ -271,7 +271,7 @@ describe('session module', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('DownloadItem', () => {
|
describe('DownloadItem', () => {
|
||||||
const mockPDF = new Buffer(1024 * 1024 * 5)
|
const mockPDF = Buffer.alloc(1024 * 1024 * 5)
|
||||||
let contentDisposition = 'inline; filename="mock.pdf"'
|
let contentDisposition = 'inline; filename="mock.pdf"'
|
||||||
const downloadFilePath = path.join(fixtures, 'mock.pdf')
|
const downloadFilePath = path.join(fixtures, 'mock.pdf')
|
||||||
const downloadServer = http.createServer((req, res) => {
|
const downloadServer = http.createServer((req, res) => {
|
||||||
|
|
|
@ -15,7 +15,7 @@ describe('asar package', function () {
|
||||||
|
|
||||||
describe('node api', function () {
|
describe('node api', function () {
|
||||||
it('supports paths specified as a Buffer', 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)
|
assert.equal(fs.existsSync(file), true)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -491,7 +491,7 @@ describe('asar package', function () {
|
||||||
file = ref2[j]
|
file = ref2[j]
|
||||||
p = path.join(fixtures, 'asar', 'a.asar', file)
|
p = path.join(fixtures, 'asar', 'a.asar', file)
|
||||||
fd = fs.openSync(p, 'r')
|
fd = fs.openSync(p, 'r')
|
||||||
buffer = new Buffer(6)
|
buffer = Buffer.alloc(6)
|
||||||
fs.readSync(fd, buffer, 0, 6, 0)
|
fs.readSync(fd, buffer, 0, 6, 0)
|
||||||
assert.equal(String(buffer).trim(), 'file1')
|
assert.equal(String(buffer).trim(), 'file1')
|
||||||
fs.closeSync(fd)
|
fs.closeSync(fd)
|
||||||
|
@ -512,7 +512,7 @@ describe('asar package', function () {
|
||||||
var p = path.join(fixtures, 'asar', 'a.asar', 'file1')
|
var p = path.join(fixtures, 'asar', 'a.asar', 'file1')
|
||||||
fs.open(p, 'r', function (err, fd) {
|
fs.open(p, 'r', function (err, fd) {
|
||||||
assert.equal(err, null)
|
assert.equal(err, null)
|
||||||
var buffer = new Buffer(6)
|
var buffer = Buffer.alloc(6)
|
||||||
fs.read(fd, buffer, 0, 6, 0, function (err) {
|
fs.read(fd, buffer, 0, 6, 0, function (err) {
|
||||||
assert.equal(err, null)
|
assert.equal(err, null)
|
||||||
assert.equal(String(buffer).trim(), 'file1')
|
assert.equal(String(buffer).trim(), 'file1')
|
||||||
|
|
|
@ -274,7 +274,7 @@ describe('node feature', () => {
|
||||||
it('can be created from WebKit external string', () => {
|
it('can be created from WebKit external string', () => {
|
||||||
const p = document.createElement('p')
|
const p = document.createElement('p')
|
||||||
p.innerText = '闲云潭影日悠悠,物换星移几度秋'
|
p.innerText = '闲云潭影日悠悠,物换星移几度秋'
|
||||||
const b = new Buffer(p.innerText)
|
const b = Buffer.from(p.innerText)
|
||||||
assert.equal(b.toString(), '闲云潭影日悠悠,物换星移几度秋')
|
assert.equal(b.toString(), '闲云潭影日悠悠,物换星移几度秋')
|
||||||
assert.equal(Buffer.byteLength(p.innerText), 45)
|
assert.equal(Buffer.byteLength(p.innerText), 45)
|
||||||
})
|
})
|
||||||
|
@ -282,15 +282,15 @@ describe('node feature', () => {
|
||||||
it('correctly parses external one-byte UTF8 string', () => {
|
it('correctly parses external one-byte UTF8 string', () => {
|
||||||
const p = document.createElement('p')
|
const p = document.createElement('p')
|
||||||
p.innerText = 'Jøhänñéß'
|
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(b.toString(), 'Jøhänñéß')
|
||||||
assert.equal(Buffer.byteLength(p.innerText), 13)
|
assert.equal(Buffer.byteLength(p.innerText), 13)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does not crash when creating large Buffers', () => {
|
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)
|
assert.equal(buffer.length, 4095)
|
||||||
buffer = new Buffer(new Array(4097).join(' '))
|
buffer = Buffer.from(new Array(4097).join(' '))
|
||||||
assert.equal(buffer.length, 4096)
|
assert.equal(buffer.length, 4096)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue