summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <tmpsantos@gmail.com>2017-07-11 17:28:50 +0300
committerThiago Marcos P. Santos <tmpsantos@gmail.com>2017-07-11 19:50:09 +0300
commitd013b12bf0bb9a868df80c66a95d9db78605d630 (patch)
tree1155726be9ddfaf3f18de721d96d0e21db1e6de6
parent0b0a8ac278fe3e06f939e0e8052be1ec9ccc050b (diff)
downloadqtlocation-mapboxgl-d013b12bf0bb9a868df80c66a95d9db78605d630.tar.gz
[node] Port the tests to the new file source
-rw-r--r--package.json1
-rw-r--r--platform/node/test/fixtures/style.json2
-rw-r--r--platform/node/test/js/cancel.test.js116
-rw-r--r--platform/node/test/js/map.test.js110
-rw-r--r--platform/node/test/js/request_fail.test.js59
-rw-r--r--platform/node/test/js/request_notfound.test.js74
-rw-r--r--platform/node/test/memory.test.js5
-rw-r--r--platform/node/test/suite_implementation.js15
8 files changed, 5 insertions, 377 deletions
diff --git a/package.json b/package.json
index 219ccabe01..f7d70d28b5 100644
--- a/package.json
+++ b/package.json
@@ -24,7 +24,6 @@
"lodash": "^4.16.4",
"pixelmatch": "^4.0.2",
"pngjs": "^3.0.0",
- "request": "^2.72.0",
"tape": "^4.5.1"
},
"engines": {
diff --git a/platform/node/test/fixtures/style.json b/platform/node/test/fixtures/style.json
index 222ac82bf8..d7421ad468 100644
--- a/platform/node/test/fixtures/style.json
+++ b/platform/node/test/fixtures/style.json
@@ -6,7 +6,7 @@
"type": "vector",
"maxzoom": 15,
"tiles": [
- "./fixtures/tiles/{z}-{x}-{y}.vector.pbf"
+ "asset://fixtures/tiles/{z}-{x}-{y}.vector.pbf"
]
}
},
diff --git a/platform/node/test/js/cancel.test.js b/platform/node/test/js/cancel.test.js
deleted file mode 100644
index 17525fb863..0000000000
--- a/platform/node/test/js/cancel.test.js
+++ /dev/null
@@ -1,116 +0,0 @@
-'use strict';
-
-var mockfs = require('./../mockfs');
-var mbgl = require('../../index');
-var test = require('tape');
-
-var options = {
- request: function(req, callback) {
- callback(null, { data: mockfs.dataForRequest(req) });
- },
- ratio: 1,
-};
-
-test('Cancel', function(t) {
- t.test('sanity', function(t) {
- var renderCount = 0;
- var cancelCount = 0;
- var map = new mbgl.Map(options);
-
- var renderCallback = function(err, pixels) {
- if (err) {
- cancelCount++;
- } else {
- renderCount++;
- }
- };
-
- map.load(mockfs.style_vector);
-
- map.render({ zoom: 16 }, renderCallback);
- map.cancel();
-
- map.render({ zoom: 16 }, renderCallback);
- map.cancel();
-
- map.render({ zoom: 16 }, renderCallback);
- map.cancel();
-
- t.equal(renderCount, 0);
- t.equal(cancelCount, 3);
-
- t.end();
- });
-
- t.test('render after cancel', function(t) {
- var map = new mbgl.Map(options);
- var renderCallback = function(err, pixels) { if (!err) t.end(); };
-
- map.load(mockfs.style_vector);
-
- map.render({ zoom: 16 }, renderCallback);
- map.cancel();
-
- map.render({ zoom: 16 }, renderCallback);
- });
-
- t.test('cancel after cancel', function(t) {
- var cancelCount = 0;
- var map = new mbgl.Map(options);
-
- map.load(mockfs.style_vector);
- map.render({ zoom: 16 }, function(err, pixels) {
- cancelCount++;
- });
-
- map.cancel();
-
- t.throws(function() {
- map.cancel();
- }, 'already canceled');
-
- t.equal(cancelCount, 1);
-
- t.end();
- });
-
- t.test('cancel without rendering', function(t) {
- var cancelCount = 0;
- var map = new mbgl.Map(options);
-
- map.load(mockfs.style_vector);
-
- t.throws(function() {
- map.cancel();
- }, 'nothing to cancel');
-
- t.end();
- });
-
- t.test('release after cancel', function(t) {
- var map = new mbgl.Map(options);
-
- map.load(mockfs.style_vector);
- map.render({ zoom: 16 }, function(err, pixels) {});
-
- map.cancel();
- map.release();
-
- t.end();
- });
-
- t.test('cancel after release', function(t) {
- var map = new mbgl.Map(options);
-
- map.load(mockfs.style_vector);
- map.render({ zoom: 16 }, function(err, pixels) {});
-
- map.release();
-
- t.throws(function() {
- map.cancel();
- }, 'map resources already released');
-
- t.end();
- });
-})
diff --git a/platform/node/test/js/map.test.js b/platform/node/test/js/map.test.js
index 286b0bd01e..3a5cc483bd 100644
--- a/platform/node/test/js/map.test.js
+++ b/platform/node/test/js/map.test.js
@@ -27,50 +27,8 @@ test('Map', function(t) {
t.end();
});
- t.test('requires request property', function(t) {
- var options = {};
-
- t.throws(function() {
- new mbgl.Map(options);
- }, /Options object must have a 'request' method/);
-
- options.request = 'test';
- t.throws(function() {
- new mbgl.Map(options);
- }, /Options object must have a 'request' method/);
-
- options.request = function() {};
- t.doesNotThrow(function() {
- var map = new mbgl.Map(options);
- map.release();
- });
-
- t.end();
- });
-
- t.test('optional cancel property must be a function', function(t) {
- var options = {
- request: function() {}
- };
-
- options.cancel = 'test';
- t.throws(function() {
- new mbgl.Map(options);
- }, /Options object 'cancel' property must be a function/);
-
- options.cancel = function() {};
- t.doesNotThrow(function() {
- var map = new mbgl.Map(options);
- map.release();
- });
-
- t.end();
- });
-
-
t.test('optional ratio property must be a number', function(t) {
var options = {
- request: function() {}
};
options.ratio = 'test';
@@ -81,7 +39,6 @@ test('Map', function(t) {
options.ratio = 1.0;
t.doesNotThrow(function() {
var map = new mbgl.Map(options);
- map.release();
});
t.end();
@@ -89,7 +46,6 @@ test('Map', function(t) {
t.test('instanceof mbgl.Map', function(t) {
var options = {
- request: function() {},
ratio: 1
};
@@ -104,8 +60,6 @@ test('Map', function(t) {
'load',
'loaded',
'render',
- 'release',
- 'cancel',
'addSource',
'addLayer',
'removeLayer',
@@ -131,7 +85,6 @@ test('Map', function(t) {
t.test('.addImage', function(t) {
var options = {
- request: function() {},
ratio: 1
};
@@ -142,7 +95,6 @@ test('Map', function(t) {
map.addImage();
}, /Three arguments required/);
- map.release();
t.end();
});
@@ -153,7 +105,6 @@ test('Map', function(t) {
map.addImage('foo', '', {});
}, /Second argument must be an object/);
- map.release();
t.end();
});
@@ -167,7 +118,6 @@ test('Map', function(t) {
});
}, /height parameter required/);
- map.release();
t.end();
});
@@ -181,7 +131,6 @@ test('Map', function(t) {
});
}, /pixelRatio parameter required/);
- map.release();
t.end();
});
@@ -196,7 +145,6 @@ test('Map', function(t) {
}, 'Image size does not match buffer size');
});
- map.release();
t.end();
});
@@ -211,7 +159,6 @@ test('Map', function(t) {
}, 'Max height and width is 1024');
});
- map.release();
t.end();
});
@@ -227,7 +174,6 @@ test('Map', function(t) {
}, 'Image size does not match buffer size');
});
- map.release();
t.end();
});
@@ -242,14 +188,12 @@ test('Map', function(t) {
});
});
- map.release();
t.end();
});
});
t.test('.removeImage', function(t) {
var options = {
- request: function() {},
ratio: 1
};
@@ -260,7 +204,6 @@ test('Map', function(t) {
map.removeImage();
}, /One argument required/);
- map.release();
t.end();
});
@@ -271,7 +214,6 @@ test('Map', function(t) {
map.removeImage({});
}, /First argument must be a string/);
- map.release();
t.end();
});
@@ -282,14 +224,12 @@ test('Map', function(t) {
map.removeImage('fooBar');
});
- map.release();
t.end();
});
});
t.test('.load', function(t) {
var options = {
- request: function() {},
ratio: 1
};
@@ -300,7 +240,6 @@ test('Map', function(t) {
map.load();
}, /Requires a map style as first argument/);
- map.release();
t.end();
});
@@ -315,7 +254,6 @@ test('Map', function(t) {
map.load('""');
}, /Failed to parse style: style must be an object/);
- map.release();
t.end();
});
@@ -327,7 +265,6 @@ test('Map', function(t) {
t.equal(msg.class, 'ParseStyle');
t.ok(msg.text.match(/Invalid value/));
- map.release();
t.end();
});
@@ -343,7 +280,6 @@ test('Map', function(t) {
map.load('{}');
});
- map.release();
t.end();
});
@@ -354,7 +290,6 @@ test('Map', function(t) {
map.load(style);
});
- map.release();
t.end();
});
@@ -365,22 +300,17 @@ test('Map', function(t) {
map.load(JSON.stringify(style));
});
- map.release();
t.end();
});
t.test('does not immediately trigger any tile loads', function(t) {
var map = new mbgl.Map({
- request: function(req) {
- t.fail('unexpected request ' + req.url);
- },
ratio: 1
});
map.load(style);
setTimeout(function() {
- map.release();
t.end();
}, 100);
});
@@ -388,11 +318,6 @@ test('Map', function(t) {
t.test('.render', function(t) {
var options = {
- request: function(req, callback) {
- fs.readFile(path.join(__dirname, '..', req.url), function(err, data) {
- callback(err, { data: data });
- });
- },
ratio: 1
};
@@ -407,7 +332,6 @@ test('Map', function(t) {
map.render('invalid');
}, /First argument must be an options object/);
- map.release();
t.end();
});
@@ -422,7 +346,6 @@ test('Map', function(t) {
map.render({}, 'invalid');
}, /Second argument must be a callback function/);
- map.release();
t.end();
});
@@ -433,7 +356,6 @@ test('Map', function(t) {
map.render({}, function() {});
}, /Style is not loaded/);
- map.release();
t.end();
});
@@ -450,8 +372,6 @@ test('Map', function(t) {
});
map.load(style);
map.render({ zoom: 1 }, function(err, data) {
- map.release();
-
t.ok(err, 'returns error');
t.end();
});
@@ -461,30 +381,16 @@ test('Map', function(t) {
var map = new mbgl.Map(options);
map.load(style);
map.render({ zoom: 1 }, function(err, data) {
- map.release();
-
t.ok(err, 'returns error');
t.end();
});
});
- t.test('double release', function(t) {
- var map = new mbgl.Map(options);
- map.release();
-
- t.throws(function() {
- map.release();
- }, /Map resources have already been released/);
-
- t.end();
- });
-
t.test('returns an image', function(t) {
var map = new mbgl.Map(options);
map.load(style);
map.render({}, function(err, pixels) {
t.error(err);
- map.release();
t.ok(pixels);
t.ok(pixels instanceof Buffer);
t.equal(pixels.length, 512 * 512 * 4)
@@ -506,7 +412,6 @@ test('Map', function(t) {
t.ok(true, 'render @ ' + ((+new Date) - start) + 'ms');
if (++completed === remaining) {
- map.release();
t.end();
} else {
render();
@@ -526,7 +431,6 @@ test('Map', function(t) {
map.render({}, function() {});
}, /Map is currently rendering an image/);
- map.release();
t.end();
});
@@ -584,7 +488,6 @@ test('Map', function(t) {
});
map.load(style);
map.render({ zoom: 1 }, function(err, data) {
- map.release();
t.ok(err, 'returns error');
t.equal(err.message, 'request error');
t.end();
@@ -592,14 +495,9 @@ test('Map', function(t) {
});
t.test('returning no content for a tile', function(t) {
- var map = new mbgl.Map({
- request: function(req, callback) {
- callback();
- },
- });
+ var map = new mbgl.Map({});
map.load(style);
map.render({ zoom: 1 }, function(err, data) {
- map.release();
t.ok(data, 'no error');
t.end();
});
@@ -607,13 +505,11 @@ test('Map', function(t) {
t.test('not holding references', function(t) {
var options = {
- request: function() {},
ratio: 1
};
- // We explicitly don't call release. mbgl.Map should
- // not hold any reference to the node's main loop and
- // prevent the test from exit.
+ // mbgl.Map should not hold any reference to the
+ // node's main loop and prevent the test from exit.
var map1 = new mbgl.Map(options);
var map2 = new mbgl.Map(options);
var map3 = new mbgl.Map(options);
diff --git a/platform/node/test/js/request_fail.test.js b/platform/node/test/js/request_fail.test.js
deleted file mode 100644
index fad116a2b8..0000000000
--- a/platform/node/test/js/request_fail.test.js
+++ /dev/null
@@ -1,59 +0,0 @@
-'use strict';
-
-var mockfs = require('../mockfs');
-var mbgl = require('../../index');
-var test = require('tape');
-
-function asyncReply(callback, data) {
- setTimeout(function() { callback(null, { data: data }); }, 0);
-};
-
-function asyncFail(callback) {
- setTimeout(function() { callback(new Error('not found')); }, 0);
-};
-
-function failRequest(t, style, failedResource) {
- var options = {
- request: function(req, callback) {
- var data = mockfs.dataForRequest(req);
-
- if (failedResource != data) {
- asyncReply(callback, data);
- } else {
- asyncFail(callback);
- }
- },
- ratio: 2,
- };
-
- var map = new mbgl.Map(options);
- map.load(style);
-
- map.render({ zoom: 16 }, function(err, pixels) {
- if (err) {
- t.pass("pass");
- map.release();
- }
- });
-};
-
-test('Vector', function(t) {
- t.plan(5);
-
- failRequest(t, mockfs.style_vector, null);
- failRequest(t, mockfs.style_vector, mockfs.sprite_png);
- failRequest(t, mockfs.style_vector, mockfs.sprite_json);
- failRequest(t, mockfs.style_vector, mockfs.source_vector);
- failRequest(t, mockfs.style_vector, mockfs.tile_vector);
- failRequest(t, mockfs.style_vector, mockfs.glyph);
-});
-
-test('Raster', function(t) {
- t.plan(4);
-
- failRequest(t, mockfs.style_raster, null);
- failRequest(t, mockfs.style_raster, mockfs.sprite_png);
- failRequest(t, mockfs.style_raster, mockfs.sprite_json);
- failRequest(t, mockfs.style_raster, mockfs.source_raster);
- failRequest(t, mockfs.style_raster, mockfs.tile_raster);
-});
diff --git a/platform/node/test/js/request_notfound.test.js b/platform/node/test/js/request_notfound.test.js
deleted file mode 100644
index d2d2812784..0000000000
--- a/platform/node/test/js/request_notfound.test.js
+++ /dev/null
@@ -1,74 +0,0 @@
-'use strict';
-
-var mockfs = require('../mockfs');
-var mbgl = require('../../index');
-var test = require('tape');
-
-function isTile(data) {
- return data == mockfs.tile_vector || data == mockfs.tile_raster;
-}
-
-function asyncReply(callback, data) {
- setTimeout(function() { callback(null, { data: data }); }, 0);
-};
-
-function asyncFail(callback, data) {
- // Do not set an error for tile when not found. A not found
- // tile is a valid tile.
- if (isTile(data)) {
- setTimeout(function() { callback(); }, 0);
- } else {
- setTimeout(function() { callback(new Error('not found')); }, 0);
- }
-};
-
-function notfoundRequest(t, style, notfoundResource) {
- var options = {
- request: function(req, callback) {
- var data = mockfs.dataForRequest(req);
-
- if (notfoundResource != data) {
- asyncReply(callback, data);
- } else {
- asyncFail(callback, data);
- }
- },
- ratio: 2,
- };
-
- var map = new mbgl.Map(options);
- map.load(style);
-
- map.render({ zoom: 16 }, function(err, pixels) {
- if (err && !isTile(notfoundResource)) {
- t.pass("pass");
- return;
- }
-
- if (!err && isTile(notfoundResource)) {
- t.pass("pass");
- return;
- }
-
- t.fail("fail");
- });
-};
-
-test('Vector', function(t) {
- t.plan(5);
-
- notfoundRequest(t, mockfs.style_vector, mockfs.sprite_png);
- notfoundRequest(t, mockfs.style_vector, mockfs.sprite_json);
- notfoundRequest(t, mockfs.style_vector, mockfs.source_vector);
- notfoundRequest(t, mockfs.style_vector, mockfs.tile_vector);
- notfoundRequest(t, mockfs.style_vector, mockfs.glyph);
-});
-
-test('Raster', function(t) {
- t.plan(4);
-
- notfoundRequest(t, mockfs.style_raster, mockfs.sprite_png);
- notfoundRequest(t, mockfs.style_raster, mockfs.sprite_json);
- notfoundRequest(t, mockfs.style_raster, mockfs.source_raster);
- notfoundRequest(t, mockfs.style_raster, mockfs.tile_raster);
-});
diff --git a/platform/node/test/memory.test.js b/platform/node/test/memory.test.js
index 717ac2c5cb..74014cbd30 100644
--- a/platform/node/test/memory.test.js
+++ b/platform/node/test/memory.test.js
@@ -18,10 +18,7 @@ test('Memory', function(t) {
var lastHeapSize = process.memoryUsage()['heapUsed'];
var options = {
- request: function(req, callback) {
- callback(null, { data: mockfs.dataForRequest(req) });
- },
- ratio: testParams.ratio,
+ ratio: testParams.ratio
};
var mapPool = []
diff --git a/platform/node/test/suite_implementation.js b/platform/node/test/suite_implementation.js
index 14d2e8a6e9..6c782c2f69 100644
--- a/platform/node/test/suite_implementation.js
+++ b/platform/node/test/suite_implementation.js
@@ -1,7 +1,6 @@
'use strict';
var mbgl = require('../../../lib/mapbox_gl_native');
-var request = require('request');
var PNG = require('pngjs').PNG;
var fs = require('fs');
var path = require('path');
@@ -13,19 +12,6 @@ mbgl.on('message', function(msg) {
module.exports = function (style, options, callback) {
var map = new mbgl.Map({
ratio: options.pixelRatio,
- request: function(req, callback) {
- request(req.url, {encoding: null}, function (err, response, body) {
- if (err) {
- callback(err);
- } else if (response.statusCode == 404) {
- callback();
- } else if (response.statusCode != 200) {
- callback(new Error(response.statusMessage));
- } else {
- callback(null, {data: body});
- }
- });
- }
});
var timedOut = false;
@@ -53,7 +39,6 @@ module.exports = function (style, options, callback) {
var results = options.queryGeometry ?
map.queryRenderedFeatures(options.queryGeometry, options.queryOptions || {}) :
[];
- map.release();
if (timedOut) return;
clearTimeout(watchdog);
callback(err, pixels, results.map(prepareFeatures));