summaryrefslogtreecommitdiff
path: root/platform/node/test/render.test.js
blob: b4933ce59e9f96f2e6ec6fc0882521702649c4c2 (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
'use strict';

const suite = require('../../../mapbox-gl-js/test/integration').render;
const suiteImplementation = require('./suite_implementation');
const ignores = require('./ignores.json');

let tests;
let shuffle = false;
let recycleMap = false;
let seed;

// https://stackoverflow.com/a/1349426/229714
function makeHash() {
    const array = [];
    const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

    for (let i = 0; i < 10; ++i)
        array.push(possible.charAt(Math.floor(Math.random() * possible.length)));

    // join array elements without commas.
    return array.join('');
}

function checkParameter(param) {
    const index = tests.indexOf(param);
    if (index === -1)
        return false;
    tests.splice(index, 1);
    return true;
}

function checkValueParameter(defaultValue, param) {
    const index = tests.findIndex((elem) => { return String(elem).startsWith(param); });
    if (index === -1)
        return defaultValue;

    const split = String(tests.splice(index, 1)).split('=');
    if (split.length !== 2)
        return defaultValue;

    return split[1];
}

if (process.argv[1] === __filename && process.argv.length > 2) {
    tests = process.argv.slice(2).filter((value, index, self) => { return self.indexOf(value) === index; });
    shuffle = checkParameter('--shuffle');
    seed = checkValueParameter(makeHash(), '--seed');
    recycleMap = checkParameter('--recycle-map');
}

suite.run('native', { tests, ignores, shuffle, seed, recycleMap }, suiteImplementation);