From d66e94d09e6e66574b06a8fe01d1db63eb7b6a74 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Fri, 10 Nov 2017 13:50:18 -0800 Subject: [PATCH] ExternalCompileRunner works with submodules If there is a test.json in the directory, it expects to find a submodule in the directory. The submodule should have the same name as the directory itself. test.json contains a list of global types that need to be available, or the empty list if none. --- .gitmodules | 6 +++++ src/harness/externalCompileRunner.ts | 26 ++++++++++++++++--- .../TypeScript-Node-Starter | 1 + .../TypeScript-React-Starter | 1 + 4 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 .gitmodules create mode 160000 tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter create mode 160000 tests/cases/user/TypeScript-React-Starter/TypeScript-React-Starter diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000000..1a1c6e193fd --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "tests/cases/user/TypeScript-React-Starter/TypeScript-React-Starter"] + path = tests/cases/user/TypeScript-React-Starter/TypeScript-React-Starter + url = https://github.com/Microsoft/TypeScript-React-Starter +[submodule "tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter"] + path = tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter + url = https://github.com/Microsoft/TypeScript-Node-Starter.git diff --git a/src/harness/externalCompileRunner.ts b/src/harness/externalCompileRunner.ts index 33803752f94..0f9386ddb0f 100644 --- a/src/harness/externalCompileRunner.ts +++ b/src/harness/externalCompileRunner.ts @@ -9,6 +9,10 @@ interface ExecResult { status: number; } +interface UserConfig { + types: string[]; +} + abstract class ExternalCompileRunnerBase extends RunnerBase { abstract testDir: string; abstract report(result: ExecResult, cwd: string): string; @@ -33,18 +37,34 @@ abstract class ExternalCompileRunnerBase extends RunnerBase { const cp = require("child_process"); it("should build successfully", () => { - const cwd = path.join(__dirname, "../../", this.testDir, directoryName); + let cwd = path.join(__dirname, "../../", this.testDir, directoryName); const timeout = 600000; // 600s = 10 minutes + const stdio = isWorker ? "pipe" : "inherit"; + let types: string[]; + if (fs.existsSync(path.join(cwd, "test.json"))) { + const update = cp.spawnSync('git', ["submodule", "update", "--remote"], { cwd, timeout, shell: true, stdio }) + if (update.status !== 0) throw new Error(`git submodule update for ${directoryName} failed!`); + + const config = JSON.parse(fs.readFileSync(path.join(cwd, "test.json"), { encoding: "utf8" })) as UserConfig; + ts.Debug.assert(!!config.types, "Git is the only reason for using test.json right now"); + types = config.types; + + cwd = path.join(cwd, directoryName); + } 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!`); } + const args = [path.join(__dirname, "tsc.js")]; + if (types) { + args.push("--types", types.join(",")); + } + args.push("--noEmit"); Harness.Baseline.runBaseline(`${this.kind()}/${directoryName}.log`, () => { - return this.report(cp.spawnSync(`node`, [path.join(__dirname, "tsc.js")], { cwd, timeout, shell: true }), cwd); + return this.report(cp.spawnSync(`node`, args, { cwd, timeout, shell: true }), cwd); }); }); }); diff --git a/tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter b/tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter new file mode 160000 index 00000000000..ed149eb0c78 --- /dev/null +++ b/tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter @@ -0,0 +1 @@ +Subproject commit ed149eb0c787b1195a95b44105822c64bb6eb636 diff --git a/tests/cases/user/TypeScript-React-Starter/TypeScript-React-Starter b/tests/cases/user/TypeScript-React-Starter/TypeScript-React-Starter new file mode 160000 index 00000000000..96fb6237a9d --- /dev/null +++ b/tests/cases/user/TypeScript-React-Starter/TypeScript-React-Starter @@ -0,0 +1 @@ +Subproject commit 96fb6237a9dda8d17059eea7fa7c22dd7db82c97