Refactor user+dt runners into externalCompilerRunner
This commit is contained in:
Родитель
5e5b5652ed
Коммит
d64a8f62f2
|
@ -105,8 +105,7 @@ var harnessCoreSources = [
|
|||
"projectsRunner.ts",
|
||||
"loggedIO.ts",
|
||||
"rwcRunner.ts",
|
||||
"userRunner.ts",
|
||||
"dtRunner.ts",
|
||||
"externalCompileRunner.ts",
|
||||
"test262Runner.ts",
|
||||
"./parallel/shared.ts",
|
||||
"./parallel/host.ts",
|
||||
|
|
|
@ -1,62 +1,67 @@
|
|||
/// <reference path="harness.ts"/>
|
||||
/// <reference path="runnerbase.ts" />
|
||||
class DefinitelyTypedRunner extends RunnerBase {
|
||||
private static readonly testDir = "../DefinitelyTyped/types/";
|
||||
|
||||
public workingDirectory = DefinitelyTypedRunner.testDir;
|
||||
|
||||
public enumerateTestFiles() {
|
||||
return Harness.IO.getDirectories(DefinitelyTypedRunner.testDir);
|
||||
}
|
||||
|
||||
public kind(): TestRunnerKind {
|
||||
return "dt";
|
||||
}
|
||||
|
||||
/** Setup the runner's tests so that they are ready to be executed by the harness
|
||||
* The first test should be a describe/it block that sets up the harness's compiler instance appropriately
|
||||
*/
|
||||
public initializeTests(): void {
|
||||
// Read in and evaluate the test list
|
||||
const testList = this.tests && this.tests.length ? this.tests : this.enumerateTestFiles();
|
||||
|
||||
describe(`${this.kind()} code samples`, () => {
|
||||
for (const test of testList) {
|
||||
this.runTest(test);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private runTest(directoryName: string) {
|
||||
describe(directoryName, () => {
|
||||
const cp = require("child_process");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
|
||||
it("should build successfully", () => {
|
||||
const cwd = path.join(__dirname, "../../", DefinitelyTypedRunner.testDir, directoryName);
|
||||
const timeout = 600000; // 600s = 10 minutes
|
||||
if (fs.existsSync(path.join(cwd, "package.json"))) {
|
||||
if (fs.existsSync(path.join(cwd, "package-lock.json"))) {
|
||||
fs.unlinkSync(path.join(cwd, "package-lock.json"));
|
||||
}
|
||||
const stdio = isWorker ? "pipe" : "inherit";
|
||||
const install = cp.spawnSync(`npm`, ["i"], { cwd, timeout, shell: true, stdio });
|
||||
if (install.status !== 0) throw new Error(`NPM Install for ${directoryName} failed!`);
|
||||
}
|
||||
Harness.Baseline.runBaseline(`${this.kind()}/${directoryName}.log`, () => {
|
||||
const result = cp.spawnSync(`node`, [path.join(__dirname, "tsc.js")], { cwd, timeout, shell: true });
|
||||
// tslint:disable:no-null-keyword
|
||||
return result.status === 0 ? null : `Exit Code: ${result.status}
|
||||
Standard output:
|
||||
${result.stdout.toString().replace(/\r\n/g, "\n")}
|
||||
|
||||
|
||||
Standard error:
|
||||
${result.stderr.toString().replace(/\r\n/g, "\n")}`;
|
||||
// tslint:enable:no-null-keyword
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
/// <reference path="harness.ts"/>
|
||||
/// <reference path="runnerbase.ts" />
|
||||
abstract class ExternalCompileRunnerBase extends RunnerBase {
|
||||
abstract testDir: string;
|
||||
public enumerateTestFiles() {
|
||||
return Harness.IO.getDirectories(this.testDir);
|
||||
}
|
||||
/** Setup the runner's tests so that they are ready to be executed by the harness
|
||||
* The first test should be a describe/it block that sets up the harness's compiler instance appropriately
|
||||
*/
|
||||
public initializeTests(): void {
|
||||
// Read in and evaluate the test list
|
||||
const testList = this.tests && this.tests.length ? this.tests : this.enumerateTestFiles();
|
||||
|
||||
describe(`${this.kind()} code samples`, () => {
|
||||
for (const test of testList) {
|
||||
this.runTest(test);
|
||||
}
|
||||
});
|
||||
}
|
||||
private runTest(directoryName: string) {
|
||||
describe(directoryName, () => {
|
||||
const cp = require("child_process");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
|
||||
it("should build successfully", () => {
|
||||
const cwd = path.join(__dirname, "../../", this.testDir, directoryName);
|
||||
const timeout = 600000; // 600s = 10 minutes
|
||||
if (fs.existsSync(path.join(cwd, "package.json"))) {
|
||||
if (fs.existsSync(path.join(cwd, "package-lock.json"))) {
|
||||
fs.unlinkSync(path.join(cwd, "package-lock.json"));
|
||||
}
|
||||
const stdio = isWorker ? "pipe" : "inherit";
|
||||
const install = cp.spawnSync(`npm`, ["i"], { cwd, timeout, shell: true, stdio });
|
||||
if (install.status !== 0) throw new Error(`NPM Install for ${directoryName} failed!`);
|
||||
}
|
||||
Harness.Baseline.runBaseline(`${this.kind()}/${directoryName}.log`, () => {
|
||||
const result = cp.spawnSync(`node`, [path.join(__dirname, "tsc.js")], { cwd, timeout, shell: true });
|
||||
// tslint:disable-next-line:no-null-keyword
|
||||
return result.status === 0 ? null : `Exit Code: ${result.status}
|
||||
Standard output:
|
||||
${result.stdout.toString().replace(/\r\n/g, "\n")}
|
||||
|
||||
|
||||
Standard error:
|
||||
${result.stderr.toString().replace(/\r\n/g, "\n")}`;
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class UserCodeRunner extends ExternalCompileRunnerBase {
|
||||
public readonly testDir = "tests/cases/user/";
|
||||
public kind(): TestRunnerKind {
|
||||
return "user";
|
||||
}
|
||||
}
|
||||
|
||||
class DefinitelyTypedRunner extends ExternalCompileRunnerBase {
|
||||
public readonly testDir = "../DefinitelyTyped/types/";
|
||||
public workingDirectory = this.testDir;
|
||||
public kind(): TestRunnerKind {
|
||||
return "dt";
|
||||
}
|
||||
}
|
|
@ -18,8 +18,7 @@
|
|||
/// <reference path="fourslashRunner.ts" />
|
||||
/// <reference path="projectsRunner.ts" />
|
||||
/// <reference path="rwcRunner.ts" />
|
||||
/// <reference path="userRunner.ts" />
|
||||
/// <reference path="dtRunner.ts" />
|
||||
/// <reference path="externalCompileRunner.ts" />
|
||||
/// <reference path="harness.ts" />
|
||||
/// <reference path="./parallel/shared.ts" />
|
||||
|
||||
|
|
|
@ -92,8 +92,7 @@
|
|||
"projectsRunner.ts",
|
||||
"loggedIO.ts",
|
||||
"rwcRunner.ts",
|
||||
"userRunner.ts",
|
||||
"definitelyRunner.ts",
|
||||
"externalCompileRunner.ts",
|
||||
"test262Runner.ts",
|
||||
"./parallel/shared.ts",
|
||||
"./parallel/host.ts",
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
/// <reference path="harness.ts"/>
|
||||
/// <reference path="runnerbase.ts" />
|
||||
class UserCodeRunner extends RunnerBase {
|
||||
private static readonly testDir = "tests/cases/user/";
|
||||
public enumerateTestFiles() {
|
||||
return Harness.IO.getDirectories(UserCodeRunner.testDir);
|
||||
}
|
||||
|
||||
public kind(): TestRunnerKind {
|
||||
return "user";
|
||||
}
|
||||
|
||||
/** Setup the runner's tests so that they are ready to be executed by the harness
|
||||
* The first test should be a describe/it block that sets up the harness's compiler instance appropriately
|
||||
*/
|
||||
public initializeTests(): void {
|
||||
// Read in and evaluate the test list
|
||||
const testList = this.tests && this.tests.length ? this.tests : this.enumerateTestFiles();
|
||||
|
||||
describe(`${this.kind()} code samples`, () => {
|
||||
for (const test of testList) {
|
||||
this.runTest(test);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private runTest(directoryName: string) {
|
||||
describe(directoryName, () => {
|
||||
const cp = require("child_process");
|
||||
const path = require("path");
|
||||
|
||||
it("should build successfully", () => {
|
||||
const cwd = path.join(__dirname, "../../", UserCodeRunner.testDir, directoryName);
|
||||
const timeout = 600000; // 10 minutes
|
||||
const stdio = isWorker ? "pipe" : "inherit";
|
||||
const install = cp.spawnSync(`npm`, ["i"], { cwd, timeout, shell: true, stdio });
|
||||
if (install.status !== 0) throw new Error(`NPM Install for ${directoryName} failed!`);
|
||||
Harness.Baseline.runBaseline(`${this.kind()}/${directoryName}.log`, () => {
|
||||
const result = cp.spawnSync(`node`, [path.join(__dirname, "tsc.js")], { cwd, timeout, shell: true });
|
||||
return `Exit Code: ${result.status}
|
||||
Standard output:
|
||||
${result.stdout.toString().replace(/\r\n/g, "\n")}
|
||||
|
||||
|
||||
Standard error:
|
||||
${result.stderr.toString().replace(/\r\n/g, "\n")}`;
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче