summaryrefslogtreecommitdiff
path: root/platform/node/test/js/request.test.js
blob: 9715633e39a0a3b290a028c072e00dec4240f81a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
'use strict';

var mockfs = require('../mockfs');
var mbgl = require('../../index');
var test = require('tape');

[ 'sprite_png', 'sprite_json', 'source_vector', 'glyph' ].forEach(function (resource) {
    test(`render reports an error when the request function responds with an error (${resource})`, function(t) {
        var map = new mbgl.Map({
            request: function(req, callback) {
                var data = mockfs.dataForRequest(req);
                if (mockfs[resource] === data) {
                    callback(new Error('message'));
                } else {
                    callback(null, { data: data });
                }
            }
        });
        map.load(mockfs.style_vector);
        map.render({ zoom: 16 }, function(err, pixels) {
            t.assert(err);
            t.assert(/message/.test(err.message));
            t.assert(!pixels);
            t.end();
        });
    });
});

[ 'vector', 'raster' ].forEach(function (type) {
    test(`render does not report an error when the request function responds with no data for a tile (${type})`, function(t) {
        var map = new mbgl.Map({
            request: function(req, callback) {
                var data = mockfs.dataForRequest(req);
                if (mockfs[`tile_${type}`] === data) {
                    callback();
                } else {
                    callback(null, { data: data });
                }
            }
        });
        map.load(mockfs[`style_${type}`]);
        map.render({ zoom: 16 }, function(err, pixels) {
            t.error(err);
            t.assert(pixels);
            t.end();
        });
    });

    test(`render reports an error when the request function responds with an error for a tile (${type})`, function(t) {
        var map = new mbgl.Map({
            request: function(req, callback) {
                var data = mockfs.dataForRequest(req);
                if (mockfs[`tile_${type}`] === data) {
                    callback(new Error('message'));
                } else {
                    callback(null, { data: data });
                }
            }
        });
        map.load(mockfs[`style_${type}`]);
        map.render({ zoom: 16 }, function(err, pixels) {
            t.assert(err);
            t.assert(/message/.test(err.message));
            t.assert(!pixels);
            t.end();
        });
    });
});