From d64a8f62f28e0f77fb8b5b681494e76cb35b3373 Mon Sep 17 00:00:00 2001
From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
Date: Wed, 8 Nov 2017 13:28:35 -0800
Subject: [PATCH] Refactor user+dt runners into externalCompilerRunner
---
Jakefile.js | 3 +-
.../{dtRunner.ts => externalCompileRunner.ts} | 129 +++++++++---------
src/harness/runner.ts | 3 +-
src/harness/tsconfig.json | 3 +-
src/harness/userRunner.ts | 51 -------
5 files changed, 70 insertions(+), 119 deletions(-)
rename src/harness/{dtRunner.ts => externalCompileRunner.ts} (76%)
delete mode 100644 src/harness/userRunner.ts
diff --git a/Jakefile.js b/Jakefile.js
index a133d0dba32..147270e0a59 100644
--- a/Jakefile.js
+++ b/Jakefile.js
@@ -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",
diff --git a/src/harness/dtRunner.ts b/src/harness/externalCompileRunner.ts
similarity index 76%
rename from src/harness/dtRunner.ts
rename to src/harness/externalCompileRunner.ts
index 3b739b28f1c..8ca0be807bf 100644
--- a/src/harness/dtRunner.ts
+++ b/src/harness/externalCompileRunner.ts
@@ -1,62 +1,67 @@
-///
-///
-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
- });
- });
- });
- }
-}
+///
+///
+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";
+ }
+}
diff --git a/src/harness/runner.ts b/src/harness/runner.ts
index 0a9a7d3428d..a1210591090 100644
--- a/src/harness/runner.ts
+++ b/src/harness/runner.ts
@@ -18,8 +18,7 @@
///
///
///
-///
-///
+///
///
///
diff --git a/src/harness/tsconfig.json b/src/harness/tsconfig.json
index 96f1999e9e8..1ab2cb955c8 100644
--- a/src/harness/tsconfig.json
+++ b/src/harness/tsconfig.json
@@ -92,8 +92,7 @@
"projectsRunner.ts",
"loggedIO.ts",
"rwcRunner.ts",
- "userRunner.ts",
- "definitelyRunner.ts",
+ "externalCompileRunner.ts",
"test262Runner.ts",
"./parallel/shared.ts",
"./parallel/host.ts",
diff --git a/src/harness/userRunner.ts b/src/harness/userRunner.ts
deleted file mode 100644
index 61a46d7e84f..00000000000
--- a/src/harness/userRunner.ts
+++ /dev/null
@@ -1,51 +0,0 @@
-///
-///
-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")}`;
- });
- });
- });
- }
-}