Skip to content

Commit d64a8f6

Browse files
committed
Refactor user+dt runners into externalCompilerRunner
1 parent 5e5b565 commit d64a8f6

File tree

5 files changed

+70
-119
lines changed

5 files changed

+70
-119
lines changed

Jakefile.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ var harnessCoreSources = [
105105
"projectsRunner.ts",
106106
"loggedIO.ts",
107107
"rwcRunner.ts",
108-
"userRunner.ts",
109-
"dtRunner.ts",
108+
"externalCompileRunner.ts",
110109
"test262Runner.ts",
111110
"./parallel/shared.ts",
112111
"./parallel/host.ts",
Lines changed: 67 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,67 @@
1-
/// <reference path="harness.ts"/>
2-
/// <reference path="runnerbase.ts" />
3-
class DefinitelyTypedRunner extends RunnerBase {
4-
private static readonly testDir = "../DefinitelyTyped/types/";
5-
6-
public workingDirectory = DefinitelyTypedRunner.testDir;
7-
8-
public enumerateTestFiles() {
9-
return Harness.IO.getDirectories(DefinitelyTypedRunner.testDir);
10-
}
11-
12-
public kind(): TestRunnerKind {
13-
return "dt";
14-
}
15-
16-
/** Setup the runner's tests so that they are ready to be executed by the harness
17-
* The first test should be a describe/it block that sets up the harness's compiler instance appropriately
18-
*/
19-
public initializeTests(): void {
20-
// Read in and evaluate the test list
21-
const testList = this.tests && this.tests.length ? this.tests : this.enumerateTestFiles();
22-
23-
describe(`${this.kind()} code samples`, () => {
24-
for (const test of testList) {
25-
this.runTest(test);
26-
}
27-
});
28-
}
29-
30-
private runTest(directoryName: string) {
31-
describe(directoryName, () => {
32-
const cp = require("child_process");
33-
const path = require("path");
34-
const fs = require("fs");
35-
36-
it("should build successfully", () => {
37-
const cwd = path.join(__dirname, "../../", DefinitelyTypedRunner.testDir, directoryName);
38-
const timeout = 600000; // 600s = 10 minutes
39-
if (fs.existsSync(path.join(cwd, "package.json"))) {
40-
if (fs.existsSync(path.join(cwd, "package-lock.json"))) {
41-
fs.unlinkSync(path.join(cwd, "package-lock.json"));
42-
}
43-
const stdio = isWorker ? "pipe" : "inherit";
44-
const install = cp.spawnSync(`npm`, ["i"], { cwd, timeout, shell: true, stdio });
45-
if (install.status !== 0) throw new Error(`NPM Install for ${directoryName} failed!`);
46-
}
47-
Harness.Baseline.runBaseline(`${this.kind()}/${directoryName}.log`, () => {
48-
const result = cp.spawnSync(`node`, [path.join(__dirname, "tsc.js")], { cwd, timeout, shell: true });
49-
// tslint:disable:no-null-keyword
50-
return result.status === 0 ? null : `Exit Code: ${result.status}
51-
Standard output:
52-
${result.stdout.toString().replace(/\r\n/g, "\n")}
53-
54-
55-
Standard error:
56-
${result.stderr.toString().replace(/\r\n/g, "\n")}`;
57-
// tslint:enable:no-null-keyword
58-
});
59-
});
60-
});
61-
}
62-
}
1+
/// <reference path="harness.ts"/>
2+
/// <reference path="runnerbase.ts" />
3+
abstract class ExternalCompileRunnerBase extends RunnerBase {
4+
abstract testDir: string;
5+
public enumerateTestFiles() {
6+
return Harness.IO.getDirectories(this.testDir);
7+
}
8+
/** Setup the runner's tests so that they are ready to be executed by the harness
9+
* The first test should be a describe/it block that sets up the harness's compiler instance appropriately
10+
*/
11+
public initializeTests(): void {
12+
// Read in and evaluate the test list
13+
const testList = this.tests && this.tests.length ? this.tests : this.enumerateTestFiles();
14+
15+
describe(`${this.kind()} code samples`, () => {
16+
for (const test of testList) {
17+
this.runTest(test);
18+
}
19+
});
20+
}
21+
private runTest(directoryName: string) {
22+
describe(directoryName, () => {
23+
const cp = require("child_process");
24+
const path = require("path");
25+
const fs = require("fs");
26+
27+
it("should build successfully", () => {
28+
const cwd = path.join(__dirname, "../../", this.testDir, directoryName);
29+
const timeout = 600000; // 600s = 10 minutes
30+
if (fs.existsSync(path.join(cwd, "package.json"))) {
31+
if (fs.existsSync(path.join(cwd, "package-lock.json"))) {
32+
fs.unlinkSync(path.join(cwd, "package-lock.json"));
33+
}
34+
const stdio = isWorker ? "pipe" : "inherit";
35+
const install = cp.spawnSync(`npm`, ["i"], { cwd, timeout, shell: true, stdio });
36+
if (install.status !== 0) throw new Error(`NPM Install for ${directoryName} failed!`);
37+
}
38+
Harness.Baseline.runBaseline(`${this.kind()}/${directoryName}.log`, () => {
39+
const result = cp.spawnSync(`node`, [path.join(__dirname, "tsc.js")], { cwd, timeout, shell: true });
40+
// tslint:disable-next-line:no-null-keyword
41+
return result.status === 0 ? null : `Exit Code: ${result.status}
42+
Standard output:
43+
${result.stdout.toString().replace(/\r\n/g, "\n")}
44+
45+
46+
Standard error:
47+
${result.stderr.toString().replace(/\r\n/g, "\n")}`;
48+
});
49+
});
50+
});
51+
}
52+
}
53+
54+
class UserCodeRunner extends ExternalCompileRunnerBase {
55+
public readonly testDir = "tests/cases/user/";
56+
public kind(): TestRunnerKind {
57+
return "user";
58+
}
59+
}
60+
61+
class DefinitelyTypedRunner extends ExternalCompileRunnerBase {
62+
public readonly testDir = "../DefinitelyTyped/types/";
63+
public workingDirectory = this.testDir;
64+
public kind(): TestRunnerKind {
65+
return "dt";
66+
}
67+
}

src/harness/runner.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
/// <reference path="fourslashRunner.ts" />
1919
/// <reference path="projectsRunner.ts" />
2020
/// <reference path="rwcRunner.ts" />
21-
/// <reference path="userRunner.ts" />
22-
/// <reference path="dtRunner.ts" />
21+
/// <reference path="externalCompileRunner.ts" />
2322
/// <reference path="harness.ts" />
2423
/// <reference path="./parallel/shared.ts" />
2524

src/harness/tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@
9292
"projectsRunner.ts",
9393
"loggedIO.ts",
9494
"rwcRunner.ts",
95-
"userRunner.ts",
96-
"definitelyRunner.ts",
95+
"externalCompileRunner.ts",
9796
"test262Runner.ts",
9897
"./parallel/shared.ts",
9998
"./parallel/host.ts",

src/harness/userRunner.ts

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)