1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const _1 = require("./");
|
4 | const alsatian_core_1 = require("./alsatian-core");
|
5 | class TestLoader {
|
6 | constructor(_fileRequirer) {
|
7 | this._fileRequirer = _fileRequirer;
|
8 | }
|
9 | loadTestFixture(filePath) {
|
10 | try {
|
11 | const testFixtureModule = this._fileRequirer.require(filePath);
|
12 | const testFixtures = [];
|
13 | const loadFixture = (constructor, description) => {
|
14 | const testFixture = this._loadTestFixture(constructor, description, filePath);
|
15 | if (testFixture !== null) {
|
16 | testFixtures.push(testFixture);
|
17 | }
|
18 | };
|
19 | if (typeof testFixtureModule === "function") {
|
20 | loadFixture(testFixtureModule, testFixtureModule.name);
|
21 | }
|
22 | else {
|
23 | Object.keys(testFixtureModule)
|
24 | .filter(key => typeof testFixtureModule[key] === "function")
|
25 | .forEach(key => loadFixture(testFixtureModule[key], key));
|
26 | }
|
27 | return testFixtures;
|
28 | }
|
29 | catch (e) {
|
30 | process.stderr.write(`ERROR LOADING FILE: ${filePath}\n${e.stack}`);
|
31 | process.exit(1);
|
32 | }
|
33 | }
|
34 | _loadTestFixture(testFixtureConstructor, defaultFixtureDescription, filePath) {
|
35 | const testFixture = Reflect.getMetadata(alsatian_core_1.METADATA_KEYS.TEST_FIXTURE, testFixtureConstructor) || new _1.TestFixture(defaultFixtureDescription);
|
36 | testFixture.ignored = false;
|
37 | testFixture.filePath = filePath;
|
38 | if (Reflect.getMetadata(alsatian_core_1.METADATA_KEYS.IGNORE, testFixtureConstructor)) {
|
39 | testFixture.ignored = true;
|
40 | testFixture.ignoreReason = Reflect.getMetadata(alsatian_core_1.METADATA_KEYS.IGNORE_REASON, testFixtureConstructor);
|
41 | }
|
42 | testFixture.fixture = new testFixtureConstructor();
|
43 | const tests = Reflect.getMetadata(alsatian_core_1.METADATA_KEYS.TESTS, testFixture.fixture);
|
44 | testFixture.focussed = false;
|
45 | if (Reflect.getMetadata(alsatian_core_1.METADATA_KEYS.FOCUS, testFixtureConstructor)) {
|
46 | testFixture.focussed = true;
|
47 | }
|
48 | if (tests === undefined) {
|
49 | return null;
|
50 | }
|
51 | tests.forEach((test) => {
|
52 | test.ignored = false;
|
53 | if (testFixture.ignored ||
|
54 | Reflect.getMetadata(alsatian_core_1.METADATA_KEYS.IGNORE, testFixture.fixture, test.key)) {
|
55 | test.ignored = true;
|
56 | test.ignoreReason =
|
57 | Reflect.getMetadata(alsatian_core_1.METADATA_KEYS.IGNORE_REASON, testFixture.fixture, test.key) || testFixture.ignoreReason;
|
58 | }
|
59 | test.focussed = false;
|
60 | if (Reflect.getMetadata(alsatian_core_1.METADATA_KEYS.FOCUS, testFixture.fixture, test.key)) {
|
61 | test.focussed = true;
|
62 | }
|
63 | test.timeout =
|
64 | Reflect.getMetadata(alsatian_core_1.METADATA_KEYS.TIMEOUT, testFixture.fixture, test.key) || null;
|
65 | testFixture.addTest(test);
|
66 | if (!test.description) {
|
67 | test.description = test.key;
|
68 | }
|
69 | const testCases = Reflect.getMetadata(alsatian_core_1.METADATA_KEYS.TEST_CASES, testFixture.fixture, test.key);
|
70 | test.testCases = [];
|
71 | if (!testCases) {
|
72 | test.testCases.push({ caseArguments: [] });
|
73 | }
|
74 | else {
|
75 | testCases.forEach((testCase) => {
|
76 | test.testCases.push(testCase);
|
77 | });
|
78 | }
|
79 | });
|
80 | return testFixture;
|
81 | }
|
82 | }
|
83 | exports.TestLoader = TestLoader;
|
84 |
|
\ | No newline at end of file |