From 9a415a2b23fa26e1f997580718ea41948b51f7ce Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 7 Nov 2017 09:50:17 -0800 Subject: [PATCH] DefinitelyRunner cleanup and speedup 1. Only `npm install` packages with a package.json 2. Add `workingDirectory` to runnerBase to differentiate input directory from output directory (which should be different for definitelyRunner). 3. Don't output anything on success. --- src/harness/definitelyRunner.ts | 20 +++++++++++++------- src/harness/parallel/host.ts | 8 ++++---- src/harness/runnerbase.ts | 3 +++ 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/harness/definitelyRunner.ts b/src/harness/definitelyRunner.ts index afd39b72424..c2f7a04d3e7 100644 --- a/src/harness/definitelyRunner.ts +++ b/src/harness/definitelyRunner.ts @@ -2,8 +2,11 @@ /// class DefinitelyTypedRunner extends RunnerBase { private static readonly testDir = "../DefinitelyTyped/types/"; + + public workingDirectory = DefinitelyTypedRunner.testDir; + public enumerateTestFiles() { - return Harness.IO.getDirectories(DefinitelyTypedRunner.testDir).map(dir => DefinitelyTypedRunner.testDir + dir); + return Harness.IO.getDirectories(DefinitelyTypedRunner.testDir); } public kind(): TestRunnerKind { @@ -28,16 +31,19 @@ class DefinitelyTypedRunner extends RunnerBase { describe(directoryName, () => { const cp = require("child_process"); const path = require("path"); + const fs = require("fs"); it("should build successfully", () => { - const cwd = path.join(__dirname, "../../", directoryName); + const cwd = path.join(__dirname, "../../", DefinitelyTypedRunner.testDir, directoryName); const timeout = 600000; // 600s = 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!`); + if (fs.existsSync(path.join(cwd, 'package.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"), "--lib dom,es6", "--strict"], { cwd, timeout, shell: true }); - return `Exit Code: ${result.status} + const result = cp.spawnSync(`node`, [path.join(__dirname, "tsc.js")], { cwd, timeout, shell: true }); + return result.status === 0 ? null : `Exit Code: ${result.status} Standard output: ${result.stdout.toString().replace(/\r\n/g, "\n")} diff --git a/src/harness/parallel/host.ts b/src/harness/parallel/host.ts index f37a3b1099e..e278d267e1f 100644 --- a/src/harness/parallel/host.ts +++ b/src/harness/parallel/host.ts @@ -77,18 +77,18 @@ namespace Harness.Parallel.Host { console.log("Discovering runner-based tests..."); const discoverStart = +(new Date()); const { statSync }: { statSync(path: string): { size: number }; } = require("fs"); + const path: { join: (...args: string[]) => string } = require("path"); for (const runner of runners) { - const files = runner.enumerateTestFiles(); - for (const file of files) { + for (const file of runner.enumerateTestFiles()) { let size: number; if (!perfData) { try { - size = statSync(file).size; + size = statSync(path.join(runner.workingDirectory, file)).size; } catch { // May be a directory try { - size = Harness.IO.listFiles(file, /.*/g, { recursive: true }).reduce((acc, elem) => acc + statSync(elem).size, 0); + size = Harness.IO.listFiles(path.join(runner.workingDirectory, file), /.*/g, { recursive: true }).reduce((acc, elem) => acc + statSync(elem).size, 0); } catch { // Unknown test kind, just return 0 and let the historical analysis take over after one run diff --git a/src/harness/runnerbase.ts b/src/harness/runnerbase.ts index 42e625a897d..1f5b31db2d6 100644 --- a/src/harness/runnerbase.ts +++ b/src/harness/runnerbase.ts @@ -24,6 +24,9 @@ abstract class RunnerBase { abstract enumerateTestFiles(): string[]; + /** The working directory where tests are found. Needed for batch testing where the input path will differ from the output path inside baselines */ + public workingDirectory = ""; + /** 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 */