all files / core/ test-loader.js

100% Statements 50/50
95.45% Branches 21/22
100% Functions 7/7
100% Lines 50/50
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  20×   71× 71× 71× 71×   71× 13× 13× 12×       58× 58× 58× 57×       71×   71× 71× 71×       71×   71× 71× 71×   71× 71×     69× 230× 230×   230× 230×   230× 230× 230× 230×   230× 230× 230× 105×     125× 559×       69×      
"use strict";
var TestLoader = (function () {
    function TestLoader(_fileRequirer) {
        this._fileRequirer = _fileRequirer;
    }
    TestLoader.prototype.loadTestFixture = function (filePath) {
        var _this = this;
        var Test = this._fileRequirer.require(filePath);
        var testFixtureKeys = Object.keys(Test);
        var testFixtures = [];
        // if the default export is class constructor
        if (typeof Test === "function") {
            var testFixture = this._loadTestFixture(Test);
            if (testFixture !== null) {
                testFixtures.push(testFixture);
            }
        }
        else {
            testFixtureKeys.forEach(function (testFixtureKey) {
                var testFixture = _this._loadTestFixture(Test[testFixtureKey]);
                if (testFixture !== null) {
                    testFixtures.push(testFixture);
                }
            });
        }
        return testFixtures;
    };
    TestLoader.prototype._loadTestFixture = function (testFixtureConstructor) {
        var testFixture = {};
        testFixture.ignored = false;
        if (Reflect.getMetadata("alsatian:ignore", testFixtureConstructor)) {
            // fixture should be ignored
            testFixture.ignored = true;
        }
        // create an instance of the test fixture
        testFixture.fixture = new testFixtureConstructor();
        // find all the tests on this test fixture
        var tests = Reflect.getMetadata("alsatian:tests", testFixture.fixture);
        testFixture.focussed = false;
        if (Reflect.getMetadata("alsatian:focus", testFixtureConstructor)) {
            testFixture.focussed = true;
        }
        testFixture.tests = [];
        if (tests === undefined) {
            // no tests on the fixture
            return null;
        }
        tests.forEach(function (test) {
            test.ignored = false;
            if (Reflect.getMetadata("alsatian:ignore", testFixture.fixture, test.key)) {
                test.ignored = true;
            }
            test.focussed = false;
            if (Reflect.getMetadata("alsatian:focus", testFixture.fixture, test.key)) {
                test.focussed = true;
            }
            test.timeout = Reflect.getMetadata("alsatian:timeout", testFixture.fixture, test.key) || null;
            testFixture.tests.push(test);
            Eif (!test.description) {
                test.description = test.key;
            }
            var testCases = Reflect.getMetadata("alsatian:testcases", testFixture.fixture, test.key);
            test.testCases = [];
            if (!testCases) {
                test.testCases.push({ arguments: [] });
            }
            else {
                testCases.forEach(function (testCase) {
                    test.testCases.push(testCase);
                });
            }
        });
        return testFixture;
    };
    return TestLoader;
}());
exports.TestLoader = TestLoader;
//# sourceMappingURL=test-loader.js.map