all files / core/ test-set.js

78.57% Statements 44/56
63.64% Branches 14/22
69.23% Functions 9/13
80% Lines 44/55
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                                                      46×     46× 46× 46× 46× 46× 46×   46× 46× 46× 19×     27× 210×              
"use strict";
var Glob = require("glob");
var path = require("path");
var TestSet = (function () {
    function TestSet(testsFileLocations) {
        this._testFixtures = [];
        Iif (typeof testsFileLocations === "string") {
            testsFileLocations = [testsFileLocations];
        }
        this._loadTestFixtures(testsFileLocations);
        if (this._testsFocussed) {
            this._testFixtures = this._testFixtures.map(function (x) {
                x.tests = x.tests.filter(function (y) { return y.focussed; });
                return x;
            }).filter(function (testFixture) { return testFixture.tests.length !== 0; });
        }
    }
    Object.defineProperty(TestSet.prototype, "testFixtures", {
        get: function () {
            return this._testFixtures;
        },
        enumerable: true,
        configurable: true
    });
    TestSet.prototype._loadTestFixtures = function (testFileLocations) {
        var _this = this;
        testFileLocations.forEach(function (testFileLocation) {
            testFileLocation = path.join(process.cwd(), testFileLocation);
            Eif (Glob.hasMagic(testFileLocation)) {
                var physicalTestFileLocations = Glob.sync(testFileLocation);
                physicalTestFileLocations.forEach(function (physicalTestFileLocation) {
                    _this._loadTest(require(physicalTestFileLocation));
                });
            }
            else {
                _this._loadTest(require(testFileLocation));
            }
        });
    };
    TestSet.prototype._loadTest = function (Test) {
        var _this = this;
        var testFixtureKeys = Object.keys(Test);
        testFixtureKeys.forEach(function (testFixtureKey) {
            Iif (Reflect.getMetadata("alsatian:ignore", Test[testFixtureKey])) {
                return;
            }
            var testFixture = {};
            testFixture.fixture = new Test[testFixtureKey]();
            var tests = Reflect.getMetadata("alsatian:tests", testFixture.fixture);
            Iif (!tests || tests.length === 0) {
                return;
            }
            var focusFixture = Reflect.getMetadata("alsatian:focus", Test[testFixtureKey]);
            testFixture.tests = [];
            tests.forEach(function (test) {
                Iif (Reflect.getMetadata("alsatian:ignore", testFixture.fixture, test.key)) {
                    return;
                }
                var focusTest = Reflect.getMetadata("alsatian:focus", testFixture.fixture, test.key);
                test.focussed = focusFixture || focusTest;
                _this._testsFocussed = _this._testsFocussed || test.focussed;
                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([]);
                }
                else {
                    testCases.forEach(function (testCase) {
                        test.testCases.push(testCase);
                    });
                }
            });
            _this._testFixtures.push(testFixture);
        });
    };
    return TestSet;
}());
exports.TestSet = TestSet;
//# sourceMappingURL=test-set.js.map