all files / core/ test-set.js

83.93% Statements 47/56
72.73% Branches 16/22
76.92% Functions 10/13
85.45% Lines 47/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 84 85 86 87 88 89 90                      3368×         43×               43× 43×   43× 43×       43×   43×   43× 43×       43× 43× 43× 193×     192× 192× 192× 192× 192× 192×   192× 192× 192× 71×     121× 547×       43×        
"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);
        // Filter out unfocussed tests if any are focussed
        Iif (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);
        // CALCULATE TESTS TO RUN
        testFixtureKeys.forEach(function (testFixtureKey) {
            Iif (Reflect.getMetadata("alsatian:ignore", Test[testFixtureKey])) {
                // fixture should be ignored
                return;
            }
            var testFixture = {};
            // create an instance of the test fixture
            testFixture.fixture = new Test[testFixtureKey]();
            // find all the tests on this test fixture
            var tests = Reflect.getMetadata("alsatian:tests", testFixture.fixture);
            Iif (!tests || tests.length === 0) {
                // no tests on the fixture
                return;
            }
            var focusFixture = Reflect.getMetadata("alsatian:focus", Test[testFixtureKey]);
            testFixture.tests = [];
            tests.forEach(function (test) {
                if (Reflect.getMetadata("alsatian:ignore", testFixture.fixture, test.key)) {
                    // ignore this test
                    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