summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <thiago@mapbox.com>2017-03-01 11:41:55 -0800
committerThiago Marcos P. Santos <thiago@mapbox.com>2017-04-11 18:48:06 +0300
commitd8cc196d376554f15214fd4b9b6d61b25d8065f5 (patch)
treea9989886810582a1750eef5b02aa590858f66637
parent1d33bf774f7d0248a72529840e155c4716a99851 (diff)
downloadqtlocation-mapboxgl-d8cc196d376554f15214fd4b9b6d61b25d8065f5.tar.gz
[node] Add request failure tests
Test for timeout and when the request fails.
-rw-r--r--platform/node/test/js/request_fail.test.js59
1 files changed, 59 insertions, 0 deletions
diff --git a/platform/node/test/js/request_fail.test.js b/platform/node/test/js/request_fail.test.js
new file mode 100644
index 0000000000..fad116a2b8
--- /dev/null
+++ b/platform/node/test/js/request_fail.test.js
@@ -0,0 +1,59 @@
+'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);
+});