summaryrefslogtreecommitdiff
path: root/platform/node/test/js/consecutive.test.js
blob: 928ca1d8376e1f98278f844ac8a041b9b0293e14 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
'use strict';

/* jshint node:true */

var test = require('tape');
var mbgl = require('../../../..');
var fs = require('fs');
var path = require('path');

var suitePath = path.join(__dirname, '../../../../test/suite');

function renderTest(style, info, dir, key) {
    return function (t) {
        var completed = 0;
        var remaining = 10;
        var start = +new Date;

        var options = {};
        options.request = function(req) {
            fs.readFile(path.join(suitePath, decodeURIComponent(req.url)), function(err, data) {
                req.respond(err, { data: data });
                t.error(err);
            });
        };
        options.cancel = function() {};
        options.ratio = 1.0;

        var map = new mbgl.Map(options);
        map.load(style);

        function render() {
            map.render(info[key], function(err, image) {
                t.error(err);

                t.ok(true, 'render @ ' + ((+new Date) - start) + 'ms');
                if (++completed === remaining) {
                    map.release();
                    t.end();
                } else {
                    render();
                }
            });
        }

        render();
    };
}

function rewriteLocalSchema(uri) {
    return uri.replace(/^local:\/\//, '');
}

test('Consecutive', function(t) {
    var dir = 'line-join';
    var k = 'round';

    var style = require(path.join(suitePath, 'tests', dir, 'style.json')),
        info  = require(path.join(suitePath, 'tests', dir, 'info.json'));

    for (var k in style.sources) {
        var source = style.sources[k];

        if (source.tiles) {
            source.tiles = source.tiles.map(rewriteLocalSchema);
        }

        if (source.url) {
            source.url = rewriteLocalSchema(source.url);
        }
    }

    if (style.sprite) style.sprite = rewriteLocalSchema(style.sprite);
    if (style.glyphs) style.glyphs = rewriteLocalSchema(style.glyphs);

    style = JSON.stringify(style);

    for (k in info) {
        t.test(dir + ' ' + k, renderTest(style, info, dir, k));
    }

    t.end();
});