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.
This commit is contained in:
Nathan Shively-Sanders 2017-11-07 09:50:17 -08:00
parent f2d4b36a49
commit 9a415a2b23
3 changed files with 20 additions and 11 deletions

View file

@ -2,8 +2,11 @@
/// <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).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")}

View file

@ -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

View file

@ -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
*/