2019-12-07 00:20:49 +01:00
|
|
|
namespace Harness {
|
|
|
|
export class FourSlashRunner extends RunnerBase {
|
|
|
|
protected basePath: string;
|
|
|
|
protected testSuiteName: TestRunnerKind;
|
2014-07-13 01:04:16 +02:00
|
|
|
|
2019-12-07 00:20:49 +01:00
|
|
|
constructor(private testType: FourSlash.FourSlashTestType) {
|
|
|
|
super();
|
|
|
|
switch (testType) {
|
|
|
|
case FourSlash.FourSlashTestType.Native:
|
|
|
|
this.basePath = "tests/cases/fourslash";
|
|
|
|
this.testSuiteName = "fourslash";
|
|
|
|
break;
|
|
|
|
case FourSlash.FourSlashTestType.Shims:
|
|
|
|
this.basePath = "tests/cases/fourslash/shims";
|
|
|
|
this.testSuiteName = "fourslash-shims";
|
|
|
|
break;
|
|
|
|
case FourSlash.FourSlashTestType.ShimsWithPreprocess:
|
|
|
|
this.basePath = "tests/cases/fourslash/shims-pp";
|
|
|
|
this.testSuiteName = "fourslash-shims-pp";
|
|
|
|
break;
|
|
|
|
case FourSlash.FourSlashTestType.Server:
|
|
|
|
this.basePath = "tests/cases/fourslash/server";
|
|
|
|
this.testSuiteName = "fourslash-server";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw ts.Debug.assertNever(testType);
|
|
|
|
}
|
2015-02-05 00:36:13 +01:00
|
|
|
}
|
2016-05-24 01:00:56 +02:00
|
|
|
|
2019-12-07 00:20:49 +01:00
|
|
|
public enumerateTestFiles() {
|
|
|
|
// see also: `enumerateTestFiles` in tests/webTestServer.ts
|
|
|
|
return this.enumerateFiles(this.basePath, /\.ts/i, { recursive: false });
|
|
|
|
}
|
2016-05-24 01:00:56 +02:00
|
|
|
|
2019-12-07 00:20:49 +01:00
|
|
|
public kind() {
|
|
|
|
return this.testSuiteName;
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
|
|
|
|
2019-12-07 00:20:49 +01:00
|
|
|
public initializeTests() {
|
|
|
|
if (this.tests.length === 0) {
|
|
|
|
this.tests = IO.enumerateTestFiles(this);
|
|
|
|
}
|
2015-07-15 02:47:07 +02:00
|
|
|
|
2019-12-07 00:20:49 +01:00
|
|
|
describe(this.testSuiteName + " tests", () => {
|
|
|
|
this.tests.forEach(test => {
|
|
|
|
const file = typeof test === "string" ? test : test.file;
|
|
|
|
describe(file, () => {
|
|
|
|
let fn = ts.normalizeSlashes(file);
|
|
|
|
const justName = fn.replace(/^.*[\\\/]/, "");
|
2014-07-13 01:04:16 +02:00
|
|
|
|
2019-12-07 00:20:49 +01:00
|
|
|
// Convert to relative path
|
|
|
|
const testIndex = fn.indexOf("tests/");
|
|
|
|
if (testIndex >= 0) fn = fn.substr(testIndex);
|
|
|
|
|
|
|
|
if (justName && !justName.match(/fourslash\.ts$/i) && !justName.match(/\.d\.ts$/i)) {
|
|
|
|
it(this.testSuiteName + " test " + justName + " runs correctly", () => {
|
|
|
|
FourSlash.runFourSlashTest(this.basePath, this.testType, fn);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2015-07-10 03:04:30 +02:00
|
|
|
});
|
2015-07-15 02:47:07 +02:00
|
|
|
});
|
2019-12-07 00:20:49 +01:00
|
|
|
}
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
|
|
|
|
2019-12-07 00:20:49 +01:00
|
|
|
export class GeneratedFourslashRunner extends FourSlashRunner {
|
|
|
|
constructor(testType: FourSlash.FourSlashTestType) {
|
|
|
|
super(testType);
|
|
|
|
this.basePath += "/generated/";
|
|
|
|
}
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
2015-07-10 03:04:30 +02:00
|
|
|
}
|