UNPKG

alsatian

Version:

TypeScript and JavaScript testing framework for beautiful and readable tests

84 lines 3.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const _1 = require("./"); const alsatian_core_1 = require("./alsatian-core"); class TestLoader { constructor(_fileRequirer) { this._fileRequirer = _fileRequirer; } loadTestFixture(filePath) { try { const testFixtureModule = this._fileRequirer.require(filePath); const testFixtures = []; const loadFixture = (constructor, description) => { const testFixture = this._loadTestFixture(constructor, description, filePath); if (testFixture !== null) { testFixtures.push(testFixture); } }; if (typeof testFixtureModule === "function") { loadFixture(testFixtureModule, testFixtureModule.name); } else { Object.keys(testFixtureModule) .filter(key => typeof testFixtureModule[key] === "function") .forEach(key => loadFixture(testFixtureModule[key], key)); } return testFixtures; } catch (e) { process.stderr.write(`ERROR LOADING FILE: ${filePath}\n${e.stack}`); process.exit(1); } } _loadTestFixture(testFixtureConstructor, defaultFixtureDescription, filePath) { const testFixture = Reflect.getMetadata(alsatian_core_1.METADATA_KEYS.TEST_FIXTURE, testFixtureConstructor) || new _1.TestFixture(defaultFixtureDescription); testFixture.ignored = false; testFixture.filePath = filePath; if (Reflect.getMetadata(alsatian_core_1.METADATA_KEYS.IGNORE, testFixtureConstructor)) { testFixture.ignored = true; testFixture.ignoreReason = Reflect.getMetadata(alsatian_core_1.METADATA_KEYS.IGNORE_REASON, testFixtureConstructor); } testFixture.fixture = new testFixtureConstructor(); const 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; } if (tests === undefined) { return null; } tests.forEach((test) => { test.ignored = false; if (testFixture.ignored || Reflect.getMetadata(alsatian_core_1.METADATA_KEYS.IGNORE, testFixture.fixture, test.key)) { test.ignored = true; 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; } const testCases = Reflect.getMetadata(alsatian_core_1.METADATA_KEYS.TEST_CASES, testFixture.fixture, test.key); test.testCases = []; if (!testCases) { test.testCases.push({ caseArguments: [] }); } else { testCases.forEach((testCase) => { test.testCases.push(testCase); }); } }); return testFixture; } } exports.TestLoader = TestLoader; //# sourceMappingURL=test-loader.js.map