all files / core/ test-loader.js

100% Statements 53/53
100% Branches 26/26
100% Functions 7/7
100% Lines 53/53
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 83  28×   91× 91× 91× 91×   91× 16× 16× 15×       75× 75× 75× 74×       91×   91× 91× 91×       91×   91× 91× 91×   91× 91×     89×   305× 305× 12×   12×   305× 305×   305× 305× 305× 299×   305× 305× 305× 138×     167× 686×       89×      
"use strict";
var alsatian_core_1 = require("./alsatian-core");
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 = new alsatian_core_1.TestFixture();
        testFixture.ignored = false;
        if (Reflect.getMetadata(alsatian_core_1.METADATA_KEYS.IGNORE, testFixtureConstructor)) {
            // fixture should be ignored
            testFixture.ignored = true;
            testFixture.ignoreReason = Reflect.getMetadata(alsatian_core_1.METADATA_KEYS.IGNORE_REASON, testFixtureConstructor);
        }
        // create an instance of the test fixture
        testFixture.fixture = new testFixtureConstructor();
        // find all the tests on this test fixture
        var tests = Reflect.getMetadata(alsatian_core_1.METADATA_KEYS.TESTS, testFixture.fixture);
        testFixture.focussed = false;
        if (Reflect.getMetadata(alsatian_core_1.METADATA_KEYS.FOCUS, testFixtureConstructor)) {
            testFixture.focussed = true;
        }
        testFixture.tests = [];
        if (tests === undefined) {
            // no tests on the fixture
            return null;
        }
        tests.forEach(function (test) {
            // the test is ignored if the fixture is, or if it's specifically ignored
            test.ignored = false;
            if (testFixture.ignored || Reflect.getMetadata(alsatian_core_1.METADATA_KEYS.IGNORE, testFixture.fixture, test.key)) {
                test.ignored = true;
                // individual test ignore reasons take precedence over test fixture ignore reasons
                test.ignoreReason = Reflect.getMetadata(alsatian_core_1.METADATA_KEYS.IGNORE_REASON, testFixture.fixture, test.key) || testFixture.ignoreReason;
            }
            test.focussed = false;
            if (Reflect.getMetadata(alsatian_core_1.METADATA_KEYS.FOCUS, testFixture.fixture, test.key)) {
                test.focussed = true;
            }
            test.timeout = Reflect.getMetadata(alsatian_core_1.METADATA_KEYS.TIMEOUT, testFixture.fixture, test.key) || null;
            testFixture.addTest(test);
            if (!test.description) {
                test.description = test.key;
            }
            var testCases = Reflect.getMetadata(alsatian_core_1.METADATA_KEYS.TEST_CASES, 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