summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <thiago@mapbox.com>2017-03-01 11:41:55 -0800
committerThiago Marcos P. Santos <tmpsantos@gmail.com>2017-04-20 18:46:35 +0300
commit761cd136a897d58c74855869ac9324de864234e3 (patch)
treed1868810bb3487d03f44d0edd75c92c604fe8850
parent07573932a9dc4ff7fefaf4ac8490dd46901d20ca (diff)
downloadqtlocation-mapboxgl-761cd136a897d58c74855869ac9324de864234e3.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);
+});