"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 |