all files / core/ test-set.ts

100% Statements 23/23
100% Branches 4/4
100% Functions 7/7
100% Lines 19/19
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            57×                           53×              
import { GlobHelper, TestLoader } from "./_core";
import { ITestFixture } from "./_interfaces/test-fixture.i";
 
const path = require("path");
 
export class TestSet {
 
  private _testFixtures: Array<ITestFixture> = [];
 
  public get testFixtures(): Array<ITestFixture> {
    return this._testFixtures;
  }
 
  public constructor(private _testLoader: TestLoader, private _globHelper: GlobHelper) { }
 
  public addTestsFromFiles (testFileLocation: string): void
  public addTestsFromFiles (testFileLocations: Array<string>): void
  public addTestsFromFiles (testsFileLocations: string | Array<string>) {
 
    if (typeof testsFileLocations === "string") {
      testsFileLocations = [ <string>testsFileLocations ];
    }
 
    this._loadTestFixtures(<Array<string>>testsFileLocations);
  }
 
  private _loadTestFixtures(testFileLocations: Array<string>) {
     testFileLocations.forEach(testFileLocation => {
 
        testFileLocation = path.join(process.cwd(), testFileLocation);
 
        if (this._globHelper.isGlob(testFileLocation)) {
          let physicalTestFileLocations = this._globHelper.resolve(testFileLocation);
 
          physicalTestFileLocations.forEach(physicalTestFileLocation => {
             this._testFixtures = this.testFixtures.concat(this._testLoader.loadTestFixture(physicalTestFileLocation));
          });
        }
        else {
           this._testFixtures = this.testFixtures.concat(this._testLoader.loadTestFixture(testFileLocation));
        }
     });
  }
}