All files autotests.js

48.98% Statements 24/49
40% Branches 4/10
55.56% Functions 5/9
53.49% Lines 23/43

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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    1x 1x 1x   1x 1x 1x   1x   1x 1x 1x                   1x   1x                           1x                             1x 1x   1x 2x   2x 2x     2x   5x 5x 5x            
"use strict";
 
require("colors");
var prettyms = require("pretty-ms");
var U = require("glace-utils");
 
var CONF = require("./config");
var generate = require("./generator").generate;
var utils = require("./utils");
 
var tests = [], testSteps = [], unusedSteps;
 
Eif (CONF.gen.stepsFiles) {
    [tests, unusedSteps] = generate();
    Iif (unusedSteps.length) {
        var errmsg = "Unused steps detected!\n".red.bold;
        for (var s of unusedSteps) {
            errmsg += `  - ${s.name}\n`.red;
        };
        errmsg += "\nCheck steps income and outcome definitions".yellow;
        U.exit("Tests generator")(errmsg);
    }
}
 
var stepsString = t => t.steps.map(s => s.name).join(" ");
 
var merge = (bucket, tt) => {
    for (var [, steps] of Object.entries(tt)) {
        var ss = steps.join(" ");
        if (testSteps.includes(ss)) continue;
        testSteps.push(ss);
 
        var t = { steps: [] };
        for (var step of steps) {
            t.steps.push({ name: step });
        }
        bucket.push(t);
    }
};
 
Iif (CONF.gen.testsFiles) {
 
    var startTime = new Date();
    console.log("Loading pregenerated tests...".yellow);
 
    tests.forEach(t => testSteps.push(stepsString(t)));
 
    for (var testsFile of CONF.gen.testsFiles) {
        var tt = utils.loadFile(testsFile);
        merge(tests, tt);
    }
 
    console.log(`Pregenerated tests are loaded during ${prettyms(new Date() - startTime)}`.yellow);
}
 
suite(`${tests.length} generated tests`, () => {
    var n = 0;
 
    for (var t of tests) {
        test(`Test case #${++n}`, () => {
 
            before(() => {
                $.resetCtx();
            });
 
            t.steps.forEach(s => {
 
                chunk(s.name, async () => {
                    Iif (await $.isTestFailed()) return false;
                    await $[s.name]();
                });
            });
        });
    };
});