Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[node] Add test for request not found
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpsantos committed Apr 20, 2017
1 parent e080b72 commit 45840ad
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions platform/node/test/js/request_notfound.test.js
Original file line number Diff line number Diff line change
@@ -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);
});

0 comments on commit 45840ad

Please sign in to comment.