summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <thiago@mapbox.com>2017-04-19 13:41:52 +0300
committerThiago Marcos P. Santos <tmpsantos@gmail.com>2017-04-20 18:46:35 +0300
commit1470ee7db6700edbc8ac69f07d8bbc737e497aa9 (patch)
treed4c793def74925306589047e538a64e2909a2252
parent51ebb96b1da5217d6742ba05ea67a66c7787f0da (diff)
downloadqtlocation-mapboxgl-1470ee7db6700edbc8ac69f07d8bbc737e497aa9.tar.gz
[node] Add test for request not found
-rw-r--r--platform/node/test/js/request_notfound.test.js74
1 files changed, 74 insertions, 0 deletions
diff --git a/platform/node/test/js/request_notfound.test.js b/platform/node/test/js/request_notfound.test.js
new file mode 100644
index 0000000000..d2d2812784
--- /dev/null
+++ b/platform/node/test/js/request_notfound.test.js
@@ -0,0 +1,74 @@
+'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);
+});