1namespace Harness { 2 export type TestRunnerKind = CompilerTestKind | FourslashTestKind | "project" | "rwc" | "test262" | "user" | "dt" | "docker"; 3 export type CompilerTestKind = "conformance" | "compiler" | "compiler-oh"; 4 export type FourslashTestKind = "fourslash" | "fourslash-shims" | "fourslash-shims-pp" | "fourslash-server" | "fourslash-oh"; 5 6 /* eslint-disable prefer-const */ 7 export let shards = 1; 8 export let shardId = 1; 9 /* eslint-enable prefer-const */ 10 11 // The following have setters as while they're read here in the harness, they're only set in the runner 12 export function setShards(count: number) { 13 shards = count; 14 } 15 export function setShardId(id: number) { 16 shardId = id; 17 } 18 19 export abstract class RunnerBase { 20 // contains the tests to run 21 public tests: (string | FileBasedTest)[] = []; 22 23 /** Add a source file to the runner's list of tests that need to be initialized with initializeTests */ 24 public addTest(fileName: string) { 25 this.tests.push(fileName); 26 } 27 28 public enumerateFiles(folder: string, regex?: RegExp, options?: { recursive: boolean }): string[] { 29 return ts.map(IO.listFiles(userSpecifiedRoot + folder, regex, { recursive: (options ? options.recursive : false) }), ts.normalizeSlashes); 30 } 31 32 abstract kind(): TestRunnerKind; 33 34 abstract enumerateTestFiles(): (string | FileBasedTest)[]; 35 36 getTestFiles(): ReturnType<this["enumerateTestFiles"]> { 37 const all = this.enumerateTestFiles(); 38 if (shards === 1) { 39 return all as ReturnType<this["enumerateTestFiles"]>; 40 } 41 return all.filter((_val, idx) => idx % shards === (shardId - 1)) as ReturnType<this["enumerateTestFiles"]>; 42 } 43 44 /** The working directory where tests are found. Needed for batch testing where the input path will differ from the output path inside baselines */ 45 public workingDirectory = ""; 46 47 /** Setup the runner's tests so that they are ready to be executed by the harness 48 * The first test should be a describe/it block that sets up the harness's compiler instance appropriately 49 */ 50 public abstract initializeTests(): void; 51 52 /** Replaces instances of full paths with fileNames only */ 53 static removeFullPaths(path: string) { 54 // If its a full path (starts with "C:" or "/") replace with just the filename 55 let fixedPath = /^(\w:|\/)/.test(path) ? ts.getBaseFileName(path) : path; 56 57 // when running in the browser the 'full path' is the host name, shows up in error baselines 58 const localHost = /http:\/localhost:\d+/g; 59 fixedPath = fixedPath.replace(localHost, ""); 60 return fixedPath; 61 } 62 } 63}