Skip to content

Commit e6c38bf

Browse files
committed
Add DefinitelyTyped test runner
Assumes that ../DefinitelyTyped holds the DefinitelyTyped repo.
1 parent c016f5b commit e6c38bf

5 files changed

Lines changed: 60 additions & 2 deletions

File tree

src/harness/definitelyRunner.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/// <reference path="harness.ts"/>
2+
/// <reference path="runnerbase.ts" />
3+
class DefinitelyTypedRunner extends RunnerBase {
4+
private static readonly testDir = "../DefinitelyTyped/types/";
5+
public enumerateTestFiles() {
6+
return Harness.IO.getDirectories(DefinitelyTypedRunner.testDir).map(dir => DefinitelyTypedRunner.testDir + dir);
7+
}
8+
9+
public kind(): TestRunnerKind {
10+
return "definitely";
11+
}
12+
13+
/** Setup the runner's tests so that they are ready to be executed by the harness
14+
* The first test should be a describe/it block that sets up the harness's compiler instance appropriately
15+
*/
16+
public initializeTests(): void {
17+
// Read in and evaluate the test list
18+
const testList = this.tests && this.tests.length ? this.tests : this.enumerateTestFiles();
19+
20+
describe(`${this.kind()} code samples`, () => {
21+
for (const test of testList) {
22+
this.runTest(test);
23+
}
24+
});
25+
}
26+
27+
private runTest(directoryName: string) {
28+
describe(directoryName, () => {
29+
const cp = require("child_process");
30+
const path = require("path");
31+
32+
it("should build successfully", () => {
33+
const cwd = path.join(__dirname, "../../", directoryName);
34+
const timeout = 600000; // 600s = 10 minutes
35+
const stdio = isWorker ? "pipe" : "inherit";
36+
const install = cp.spawnSync(`npm`, ["i"], { cwd, timeout, shell: true, stdio });
37+
if (install.status !== 0) throw new Error(`NPM Install for ${directoryName} failed!`);
38+
Harness.Baseline.runBaseline(`${this.kind()}/${directoryName}.log`, () => {
39+
const result = cp.spawnSync(`node`, [path.join(__dirname, "tsc.js"), "--lib dom,es6", "--strict"], { cwd, timeout, shell: true });
40+
return `Exit Code: ${result.status}
41+
Standard output:
42+
${result.stdout.toString().replace(/\r\n/g, "\n")}
43+
44+
45+
Standard error:
46+
${result.stderr.toString().replace(/\r\n/g, "\n")}`;
47+
});
48+
});
49+
});
50+
}
51+
}

src/harness/runner.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
/// <reference path="projectsRunner.ts" />
2020
/// <reference path="rwcRunner.ts" />
2121
/// <reference path="userRunner.ts" />
22+
/// <reference path="definitelyRunner.ts" />
2223
/// <reference path="harness.ts" />
2324
/// <reference path="./parallel/shared.ts" />
2425

@@ -62,6 +63,8 @@ function createRunner(kind: TestRunnerKind): RunnerBase {
6263
return new Test262BaselineRunner();
6364
case "user":
6465
return new UserCodeRunner();
66+
case "definitely":
67+
return new DefinitelyTypedRunner();
6568
}
6669
ts.Debug.fail(`Unknown runner kind ${kind}`);
6770
}
@@ -183,6 +186,9 @@ function handleTestConfig() {
183186
case "user":
184187
runners.push(new UserCodeRunner());
185188
break;
189+
case "definitely":
190+
runners.push(new DefinitelyTypedRunner());
191+
break;
186192
}
187193
}
188194
}

src/harness/runnerbase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// <reference path="harness.ts" />
22

33

4-
type TestRunnerKind = CompilerTestKind | FourslashTestKind | "project" | "rwc" | "test262" | "user";
4+
type TestRunnerKind = CompilerTestKind | FourslashTestKind | "project" | "rwc" | "test262" | "user" | "definitely";
55
type CompilerTestKind = "conformance" | "compiler";
66
type FourslashTestKind = "fourslash" | "fourslash-shims" | "fourslash-shims-pp" | "fourslash-server";
77

src/harness/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"loggedIO.ts",
9494
"rwcRunner.ts",
9595
"userRunner.ts",
96+
"definitelyRunner.ts",
9697
"test262Runner.ts",
9798
"./parallel/shared.ts",
9899
"./parallel/host.ts",

src/harness/userRunner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class UserCodeRunner extends RunnerBase {
3636
const install = cp.spawnSync(`npm`, ["i"], { cwd, timeout, shell: true, stdio });
3737
if (install.status !== 0) throw new Error(`NPM Install for ${directoryName} failed!`);
3838
Harness.Baseline.runBaseline(`${this.kind()}/${directoryName}.log`, () => {
39-
const result = cp.spawnSync(`node`, ["../../../../built/local/tsc.js"], { cwd, timeout, shell: true });
39+
const result = cp.spawnSync(`node`, [path.join(__dirname, "tsc.js")], { cwd, timeout, shell: true });
4040
return `Exit Code: ${result.status}
4141
Standard output:
4242
${result.stdout.toString().replace(/\r\n/g, "\n")}

0 commit comments

Comments
 (0)