From d89e78544013a24538c6149338067842838c58dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Mon, 21 Oct 2019 20:05:51 +0200 Subject: [PATCH] Stop using deprecated Buffer constructor --- lib/api/middlewares/lzma.js | 2 +- scripts/lzma2config.js | 2 +- test/acceptance/dataviews/histogram-test.js | 4 ++-- test/acceptance/multilayer-test.js | 4 ++-- .../named-layers-visibility-test.js | 2 +- .../named-maps-authentication-test.js | 4 ++-- .../acceptance/named-maps-static-view-test.js | 2 +- test/acceptance/named-maps-stats-test.js | 2 +- test/acceptance/ported/retina-test.js | 2 +- test/acceptance/ported/support/test-client.js | 2 +- test/acceptance/regressions-test.js | 2 +- .../acceptance/turbo-carto/named-maps-test.js | 4 ++-- .../mapconfig-named-layers-datasource-test.js | 24 +++++++++---------- .../mapconfig-named-layers-expanded-test.js | 12 +++++----- test/support/assert.js | 4 ++-- test/support/test-client.js | 12 +++++----- test/support/test-helper.js | 2 +- test/unit/ported/profiler-test.js | 2 +- 18 files changed, 44 insertions(+), 44 deletions(-) diff --git a/lib/api/middlewares/lzma.js b/lib/api/middlewares/lzma.js index 5b8d9f8b..6edf11bf 100644 --- a/lib/api/middlewares/lzma.js +++ b/lib/api/middlewares/lzma.js @@ -11,7 +11,7 @@ module.exports = function lzma () { } // Decode (from base64) - var lzma = new Buffer(req.query.lzma, 'base64') + var lzma = Buffer.from(req.query.lzma, 'base64') .toString('binary') .split('') .map(function (c) { diff --git a/scripts/lzma2config.js b/scripts/lzma2config.js index 0d8347b8..184cc0d2 100644 --- a/scripts/lzma2config.js +++ b/scripts/lzma2config.js @@ -6,7 +6,7 @@ if (process.argv.length !== 3) { var LZMA = require('lzma').LZMA; var lzmaWorker = new LZMA(); var lzmaInput = decodeURIComponent(process.argv[2]); -var lzmaBuffer = new Buffer(lzmaInput, 'base64') +var lzmaBuffer = Buffer.from(lzmaInput, 'base64') .toString('binary') .split('') .map(function(c) { diff --git a/test/acceptance/dataviews/histogram-test.js b/test/acceptance/dataviews/histogram-test.js index e0473579..49793c6e 100644 --- a/test/acceptance/dataviews/histogram-test.js +++ b/test/acceptance/dataviews/histogram-test.js @@ -1124,7 +1124,7 @@ describe('histogram-dataview for date column type', function() { self.testClient.getDataview('minute_histogram', params, function (err, dataviewWithOffset) { assert.ifError(err); - assert.notEqual(dataview.offset, dataviewWithOffset.offset); + assert.notStrictEqual(dataview.offset, dataviewWithOffset.offset); dataview.offset = dataviewWithOffset.offset; assert.deepStrictEqual(dataview, dataviewWithOffset); done(); @@ -1158,7 +1158,7 @@ describe('histogram-dataview for date column type', function() { function (err, filteredWithOffsetDataview) { assert.ifError(err); - assert.notEqual(filteredWithOffsetDataview.offset, filteredDataview.offset); + assert.notStrictEqual(filteredWithOffsetDataview.offset, filteredDataview.offset); filteredWithOffsetDataview.offset = filteredDataview.offset; assert.deepStrictEqual(filteredWithOffsetDataview, filteredDataview); done(); diff --git a/test/acceptance/multilayer-test.js b/test/acceptance/multilayer-test.js index 3222d524..f0ddbac7 100644 --- a/test/acceptance/multilayer-test.js +++ b/test/acceptance/multilayer-test.js @@ -310,7 +310,7 @@ var QueryTables = require('cartodb-query-tables').queryTables; method: 'GET', headers: { host: 'localhost' } }, {}, function (res) { - assert.notEqual(res.statusCode, 200); + assert.notStrictEqual(res.statusCode, 200); helper.checkNoCache(res); done(); }); @@ -335,7 +335,7 @@ var QueryTables = require('cartodb-query-tables').queryTables; method: 'GET', headers: { host: 'localhost' } }, {}, function (res) { - assert.notEqual(res.statusCode, 200); + assert.notStrictEqual(res.statusCode, 200); helper.checkNoCache(res); done(); }); diff --git a/test/acceptance/named-layers-visibility-test.js b/test/acceptance/named-layers-visibility-test.js index 0e5d0c6c..cafed045 100644 --- a/test/acceptance/named-layers-visibility-test.js +++ b/test/acceptance/named-layers-visibility-test.js @@ -195,7 +195,7 @@ describe('layers visibility for previews', function () { assert.ifError(err); var next = this; - var img = mapnik.Image.fromBytes(new Buffer(res.body, 'binary')); + var img = mapnik.Image.fromBytes(Buffer.from(res.body, 'binary')); var previewFixturePath = previewFixture(scenario.name); assert.imageIsSimilarToFile(img, previewFixturePath, IMAGE_TOLERANCE, next); diff --git a/test/acceptance/named-maps-authentication-test.js b/test/acceptance/named-maps-authentication-test.js index 120629db..f497c99d 100644 --- a/test/acceptance/named-maps-authentication-test.js +++ b/test/acceptance/named-maps-authentication-test.js @@ -161,7 +161,7 @@ describe('named maps authentication', function () { function (res, err) { var img; if (!err && res.headers['content-type'] === 'image/png') { - img = mapnik.Image.fromBytes(new Buffer(res.body, 'binary')); + img = mapnik.Image.fromBytes(Buffer.from(res.body, 'binary')); } return callback(err, res, img); } @@ -230,7 +230,7 @@ describe('named maps authentication', function () { function (res, err) { var img; if (!err && res.headers['content-type'] === 'image/png') { - img = mapnik.Image.fromBytes(new Buffer(res.body, 'binary')); + img = mapnik.Image.fromBytes(Buffer.from(res.body, 'binary')); } return callback(err, res, img); } diff --git a/test/acceptance/named-maps-static-view-test.js b/test/acceptance/named-maps-static-view-test.js index c4f9a3d2..ee926e5b 100644 --- a/test/acceptance/named-maps-static-view-test.js +++ b/test/acceptance/named-maps-static-view-test.js @@ -90,7 +90,7 @@ describe('named maps static view', function () { assert.response(server, requestOptions, expectedResponse, function (res, err) { testHelper.deleteRedisKeys({ 'user:localhost:mapviews:global': 5 }, function () { - return callback(err, mapnik.Image.fromBytes(new Buffer(res.body, 'binary'))); + return callback(err, mapnik.Image.fromBytes(Buffer.from(res.body, 'binary'))); }); }); } diff --git a/test/acceptance/named-maps-stats-test.js b/test/acceptance/named-maps-stats-test.js index 94a400a9..0d5fe9fc 100644 --- a/test/acceptance/named-maps-stats-test.js +++ b/test/acceptance/named-maps-stats-test.js @@ -92,7 +92,7 @@ describe('named maps preview stats', function () { function (res, err) { var img; if (!err && res.headers['content-type'] === 'image/png') { - img = mapnik.Image.fromBytes(new Buffer(res.body, 'binary')); + img = mapnik.Image.fromBytes(Buffer.from(res.body, 'binary')); } return callback(err, res, img); } diff --git a/test/acceptance/ported/retina-test.js b/test/acceptance/ported/retina-test.js index 18dff7b4..5515149e 100644 --- a/test/acceptance/ported/retina-test.js +++ b/test/acceptance/ported/retina-test.js @@ -91,7 +91,7 @@ describe('retina support', function () { function (res, err) { assert.ok(!err, 'Failed to request 0/0/0' + scaleFactor + '.png tile'); - var image = new mapnik.Image.fromBytes(new Buffer(res.body, 'binary')); + var image = new mapnik.Image.fromBytes(Buffer.from(res.body, 'binary')); assert.strictEqual(image.width(), imageSize); assert.strictEqual(image.height(), imageSize); diff --git a/test/acceptance/ported/support/test-client.js b/test/acceptance/ported/support/test-client.js index 3c05fb29..eb27a120 100644 --- a/test/acceptance/ported/support/test-client.js +++ b/test/acceptance/ported/support/test-client.js @@ -404,7 +404,7 @@ function getGeneric (layergroupConfig, url, expectedResponse, callback) { var img; if (contentType === pngContentType) { - img = new mapnik.Image.fromBytesSync(new Buffer(res.body, 'binary')); + img = new mapnik.Image.fromBytesSync(Buffer.from(res.body, 'binary')); } var keysToDelete = { diff --git a/test/acceptance/regressions-test.js b/test/acceptance/regressions-test.js index 3e5a8dc9..b777d729 100644 --- a/test/acceptance/regressions-test.js +++ b/test/acceptance/regressions-test.js @@ -128,7 +128,7 @@ describe('regressions', function () { const timestampA = parseInt(cacheBusterA, 10); const timestampB = parseInt(cacheBusterB, 10); - assert.notEqual(timestampA, timestampB); + assert.notStrictEqual(timestampA, timestampB); assert.ok(timestampA < timestampB, `timestampA: ${timestampA} > timestampB:${timestampB}`); testClient.drain(done); diff --git a/test/acceptance/turbo-carto/named-maps-test.js b/test/acceptance/turbo-carto/named-maps-test.js index 4b0b90f3..f8d05532 100644 --- a/test/acceptance/turbo-carto/named-maps-test.js +++ b/test/acceptance/turbo-carto/named-maps-test.js @@ -166,7 +166,7 @@ describe('turbo-carto for named maps', function () { assert.strictEqual(res.headers['content-type'], 'image/png'); var fixturePath = './test/fixtures/turbo-carto-named-maps-reds.png'; - var image = mapnik.Image.fromBytes(new Buffer(res.body, 'binary')); + var image = mapnik.Image.fromBytes(Buffer.from(res.body, 'binary')); assert.imageIsSimilarToFile(image, fixturePath, IMAGE_TOLERANCE_PER_MIL, next); }, @@ -225,7 +225,7 @@ describe('turbo-carto for named maps', function () { assert.strictEqual(res.headers['content-type'], 'image/png'); var fixturePath = './test/fixtures/turbo-carto-named-maps-blues.png'; - var image = mapnik.Image.fromBytes(new Buffer(res.body, 'binary')); + var image = mapnik.Image.fromBytes(Buffer.from(res.body, 'binary')); assert.imageIsSimilarToFile(image, fixturePath, IMAGE_TOLERANCE_PER_MIL, next); }, diff --git a/test/integration/mapconfig-named-layers-datasource-test.js b/test/integration/mapconfig-named-layers-datasource-test.js index cbfe93dd..8ff3f9ed 100644 --- a/test/integration/mapconfig-named-layers-datasource-test.js +++ b/test/integration/mapconfig-named-layers-datasource-test.js @@ -167,7 +167,7 @@ describe('named_layers datasources', function () { assert.strictEqual(layers[1].type, 'cartodb'); assert.strictEqual(layers[1].options.sql, wadusTemplateSql); var layerDatasource = datasource.getLayerDatasource(1); - assert.notEqual(layerDatasource, undefined); + assert.notStrictEqual(layerDatasource, undefined); assert.ok(layerDatasource.user); done(); @@ -188,13 +188,13 @@ describe('named_layers datasources', function () { assert.strictEqual(layers[1].type, 'mapnik'); assert.strictEqual(layers[1].options.sql, wadusMapnikSql); var layerDatasource = datasource.getLayerDatasource(1); - assert.notEqual(layerDatasource, undefined); + assert.notStrictEqual(layerDatasource, undefined); assert.ok(layerDatasource.user); assert.strictEqual(layers[2].type, 'cartodb'); assert.strictEqual(layers[2].options.sql, wadusTemplateSql); layerDatasource = datasource.getLayerDatasource(2); - assert.notEqual(layerDatasource, undefined); + assert.notStrictEqual(layerDatasource, undefined); assert.ok(layerDatasource.user); done(); @@ -211,19 +211,19 @@ describe('named_layers datasources', function () { assert.strictEqual(layers[0].type, 'mapnik'); assert.strictEqual(layers[0].options.sql, wadusMapnikSql); var layerDatasource = datasource.getLayerDatasource(0); - assert.notEqual(layerDatasource, undefined); + assert.notStrictEqual(layerDatasource, undefined); assert.ok(layerDatasource.user); assert.strictEqual(layers[1].type, 'cartodb'); assert.strictEqual(layers[1].options.sql, wadusTemplateSql); layerDatasource = datasource.getLayerDatasource(1); - assert.notEqual(layerDatasource, undefined); + assert.notStrictEqual(layerDatasource, undefined); assert.ok(layerDatasource.user); assert.strictEqual(layers[2].type, 'cartodb'); assert.strictEqual(layers[2].options.sql, wadusTemplateSql); layerDatasource = datasource.getLayerDatasource(2); - assert.notEqual(layerDatasource, undefined); + assert.notStrictEqual(layerDatasource, undefined); assert.ok(layerDatasource.user); done(); @@ -247,19 +247,19 @@ describe('named_layers datasources', function () { assert.strictEqual(layers[0].type, 'cartodb'); assert.strictEqual(layers[0].options.sql, wadusTemplateSql); var layerDatasource = datasource.getLayerDatasource(0); - assert.notEqual(layerDatasource, undefined); + assert.notStrictEqual(layerDatasource, undefined); assert.ok(layerDatasource.user); assert.strictEqual(layers[1].type, 'mapnik'); assert.strictEqual(layers[1].options.sql, wadusMapnikSql); layerDatasource = datasource.getLayerDatasource(1); - assert.notEqual(layerDatasource, undefined); + assert.notStrictEqual(layerDatasource, undefined); assert.ok(layerDatasource.user); assert.strictEqual(layers[2].type, 'cartodb'); assert.strictEqual(layers[2].options.sql, wadusTemplateSql); layerDatasource = datasource.getLayerDatasource(2); - assert.notEqual(layerDatasource, undefined); + assert.notStrictEqual(layerDatasource, undefined); assert.ok(layerDatasource.user); assert.strictEqual(layers[3].type, 'cartodb'); @@ -269,7 +269,7 @@ describe('named_layers datasources', function () { assert.strictEqual(layers[4].type, 'cartodb'); assert.strictEqual(layers[4].options.sql, wadusTemplateSql); layerDatasource = datasource.getLayerDatasource(4); - assert.notEqual(layerDatasource, undefined); + assert.notStrictEqual(layerDatasource, undefined); assert.ok(layerDatasource.user); assert.strictEqual(layers[5].type, 'cartodb'); @@ -279,13 +279,13 @@ describe('named_layers datasources', function () { assert.strictEqual(layers[6].type, 'mapnik'); assert.strictEqual(layers[6].options.sql, wadusMapnikSql); layerDatasource = datasource.getLayerDatasource(6); - assert.notEqual(layerDatasource, undefined); + assert.notStrictEqual(layerDatasource, undefined); assert.ok(layerDatasource.user); assert.strictEqual(layers[7].type, 'cartodb'); assert.strictEqual(layers[7].options.sql, wadusTemplateSql); layerDatasource = datasource.getLayerDatasource(7); - assert.notEqual(layerDatasource, undefined); + assert.notStrictEqual(layerDatasource, undefined); assert.ok(layerDatasource.user); done(); diff --git a/test/integration/mapconfig-named-layers-expanded-test.js b/test/integration/mapconfig-named-layers-expanded-test.js index 64524044..6785198e 100644 --- a/test/integration/mapconfig-named-layers-expanded-test.js +++ b/test/integration/mapconfig-named-layers-expanded-test.js @@ -235,7 +235,7 @@ describe('mapconfig-named-layers-adapter', function () { var layers = mapConfig.layers; assert.ok(layers.length, 1); assert.ok(layers[0].type, 'cartodb'); - assert.notEqual(context.datasource.getLayerDatasource(0), undefined); + assert.notStrictEqual(context.datasource.getLayerDatasource(0), undefined); done(); } @@ -257,7 +257,7 @@ describe('mapconfig-named-layers-adapter', function () { assert.ok(!err); var layers = mapConfig.layers; assert.strictEqual(layers.length, 1); - assert.notEqual(context.datasource.getLayerDatasource(0), undefined); + assert.notStrictEqual(context.datasource.getLayerDatasource(0), undefined); templateMaps.delTemplate(username, tokenAuthTemplateName, done); } @@ -283,11 +283,11 @@ describe('mapconfig-named-layers-adapter', function () { assert.strictEqual(layers[0].type, 'mapnik'); assert.strictEqual(layers[0].options.cartocss, '#layer { polygon-fill: green; }'); - assert.notEqual(context.datasource.getLayerDatasource(0), undefined); + assert.notStrictEqual(context.datasource.getLayerDatasource(0), undefined); assert.strictEqual(layers[1].type, 'cartodb'); assert.strictEqual(layers[1].options.cartocss, '#layer { marker-fill: red; }'); - assert.notEqual(context.datasource.getLayerDatasource(1), undefined); + assert.notStrictEqual(context.datasource.getLayerDatasource(1), undefined); templateMaps.delTemplate(username, multipleLayersTemplateName, done); } @@ -320,11 +320,11 @@ describe('mapconfig-named-layers-adapter', function () { assert.strictEqual(layers[0].type, 'mapnik'); assert.strictEqual(layers[0].options.cartocss, '#layer { polygon-fill: ' + polygonColor + '; }'); - assert.notEqual(context.datasource.getLayerDatasource(0), undefined); + assert.notStrictEqual(context.datasource.getLayerDatasource(0), undefined); assert.strictEqual(layers[1].type, 'cartodb'); assert.strictEqual(layers[1].options.cartocss, '#layer { marker-fill: ' + color + '; }'); - assert.notEqual(context.datasource.getLayerDatasource(1), undefined); + assert.notStrictEqual(context.datasource.getLayerDatasource(1), undefined); templateMaps.delTemplate(username, multipleLayersTemplateName, done); } diff --git a/test/support/assert.js b/test/support/assert.js index 5c07bb3d..84d7e7f3 100644 --- a/test/support/assert.js +++ b/test/support/assert.js @@ -33,8 +33,8 @@ assert.imageBufferIsSimilarToFile = function (buffer, referenceImageRelativeFile }; assert.imageBuffersAreSimilar = function (bufferA, bufferB, tolerance, callback) { - var testImage = mapnik.Image.fromBytes(Buffer.isBuffer(bufferA) ? bufferA : new Buffer(bufferA, 'binary')); - var referenceImage = mapnik.Image.fromBytes(Buffer.isBuffer(bufferB) ? bufferB : new Buffer(bufferB, 'binary')); + var testImage = mapnik.Image.fromBytes(Buffer.isBuffer(bufferA) ? bufferA : Buffer.from(bufferA, 'binary')); + var referenceImage = mapnik.Image.fromBytes(Buffer.isBuffer(bufferB) ? bufferB : Buffer.from(bufferB, 'binary')); imagesAreSimilar(testImage, referenceImage, tolerance, callback); }; diff --git a/test/support/test-client.js b/test/support/test-client.js index 34cdad73..e7c76109 100644 --- a/test/support/test-client.js +++ b/test/support/test-client.js @@ -924,11 +924,11 @@ TestClient.prototype.getTile = function (z, x, y, params, callback) { var body; switch (res.headers['content-type']) { case 'image/png': - body = mapnik.Image.fromBytes(new Buffer(res.body, 'binary')); + body = mapnik.Image.fromBytes(Buffer.from(res.body, 'binary')); break; case 'application/x-protobuf': body = new mapnik.VectorTile(z, x, y); - body.setDataSync(new Buffer(res.body, 'binary')); + body.setDataSync(Buffer.from(res.body, 'binary')); break; case 'application/json; charset=utf-8': body = JSON.parse(res.body); @@ -1098,7 +1098,7 @@ TestClient.prototype.getStaticCenter = function (params, callback) { var body; switch (res.headers['content-type']) { case 'image/png': - body = mapnik.Image.fromBytes(new Buffer(res.body, 'binary')); + body = mapnik.Image.fromBytes(Buffer.from(res.body, 'binary')); break; case 'application/json; charset=utf-8': body = JSON.parse(res.body); @@ -1335,7 +1335,7 @@ module.exports.getStaticMap = function getStaticMap (templateName, params, callb assert.response(server, requestOptions, expectedResponse, function (res, err) { helper.deleteRedisKeys({ 'user:localhost:mapviews:global': 5 }, function () { - return callback(err, mapnik.Image.fromBytes(new Buffer(res.body, 'binary'))); + return callback(err, mapnik.Image.fromBytes(Buffer.from(res.body, 'binary'))); }); }); }; @@ -1537,11 +1537,11 @@ TestClient.prototype.getNamedTile = function (name, z, x, y, format, options, ca let body; switch (res.headers['content-type']) { case 'image/png': - body = mapnik.Image.fromBytes(new Buffer(res.body, 'binary')); + body = mapnik.Image.fromBytes(Buffer.from(res.body, 'binary')); break; case 'application/x-protobuf': body = new mapnik.VectorTile(z, x, y); - body.setDataSync(new Buffer(res.body, 'binary')); + body.setDataSync(Buffer.from(res.body, 'binary')); break; case 'application/json; charset=utf-8': body = JSON.parse(res.body); diff --git a/test/support/test-helper.js b/test/support/test-helper.js index 1334fce4..6a007378 100644 --- a/test/support/test-helper.js +++ b/test/support/test-helper.js @@ -33,7 +33,7 @@ function lzma_compress_to_base64 (payload, mode, callback) { lzmaWorker.compress(payload, mode, function (ints) { ints = ints.map(function (c) { return String.fromCharCode(c + 128); }).join(''); - var base64 = new Buffer(ints, 'binary').toString('base64'); + var base64 = Buffer.from(ints, 'binary').toString('base64'); callback(null, base64); }, function (/* percent */) { diff --git a/test/unit/ported/profiler-test.js b/test/unit/ported/profiler-test.js index e9a0f9b4..f2a105c8 100644 --- a/test/unit/ported/profiler-test.js +++ b/test/unit/ported/profiler-test.js @@ -13,6 +13,6 @@ describe('profiler', function () { it('Profiler is NOT null in ProfilerProxy when profiling is enabled', function () { var profilerProxy = new ProfilerProxy({ profile: true }); - assert.notEqual(profilerProxy.profiler, null); + assert.notStrictEqual(profilerProxy.profiler, null); }); });