1namespace Harness { 2 export class FourSlashRunner extends RunnerBase { 3 protected basePath: string; 4 protected testSuiteName: TestRunnerKind; 5 6 constructor(private testType: FourSlash.FourSlashTestType) { 7 super(); 8 switch (testType) { 9 case FourSlash.FourSlashTestType.Native: 10 this.basePath = "tests/cases/fourslash"; 11 this.testSuiteName = "fourslash"; 12 break; 13 case FourSlash.FourSlashTestType.Shims: 14 this.basePath = "tests/cases/fourslash/shims"; 15 this.testSuiteName = "fourslash-shims"; 16 break; 17 case FourSlash.FourSlashTestType.ShimsWithPreprocess: 18 this.basePath = "tests/cases/fourslash/shims-pp"; 19 this.testSuiteName = "fourslash-shims-pp"; 20 break; 21 case FourSlash.FourSlashTestType.Server: 22 this.basePath = "tests/cases/fourslash/server"; 23 this.testSuiteName = "fourslash-server"; 24 break; 25 default: 26 throw ts.Debug.assertNever(testType); 27 } 28 } 29 30 public enumerateTestFiles() { 31 // see also: `enumerateTestFiles` in tests/webTestServer.ts 32 return this.enumerateFiles(this.basePath, /\.ts/i, { recursive: false }); 33 } 34 35 public kind() { 36 return this.testSuiteName; 37 } 38 39 public initializeTests() { 40 if (this.tests.length === 0) { 41 this.tests = IO.enumerateTestFiles(this); 42 } 43 44 describe(this.testSuiteName + " tests", () => { 45 this.tests.forEach(test => { 46 const file = typeof test === "string" ? test : test.file; 47 describe(file, () => { 48 let fn = ts.normalizeSlashes(file); 49 const justName = fn.replace(/^.*[\\\/]/, ""); 50 51 // Convert to relative path 52 const testIndex = fn.indexOf("tests/"); 53 if (testIndex >= 0) fn = fn.substr(testIndex); 54 55 if (justName && !justName.match(/fourslash\.ts$/i) && !justName.match(/\.d\.ts$/i)) { 56 it(this.testSuiteName + " test " + justName + " runs correctly", () => { 57 FourSlash.runFourSlashTest(this.basePath, this.testType, fn); 58 }); 59 } 60 }); 61 }); 62 }); 63 } 64 } 65 66 export class GeneratedFourslashRunner extends FourSlashRunner { 67 constructor(testType: FourSlash.FourSlashTestType) { 68 super(testType); 69 this.basePath += "/generated/"; 70 } 71 } 72} 73