Skip to content

Commit 9a415a2

Browse files
committed
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.
1 parent f2d4b36 commit 9a415a2

3 files changed

Lines changed: 20 additions & 11 deletions

File tree

src/harness/definitelyRunner.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
/// <reference path="runnerbase.ts" />
33
class DefinitelyTypedRunner extends RunnerBase {
44
private static readonly testDir = "../DefinitelyTyped/types/";
5+
6+
public workingDirectory = DefinitelyTypedRunner.testDir;
7+
58
public enumerateTestFiles() {
6-
return Harness.IO.getDirectories(DefinitelyTypedRunner.testDir).map(dir => DefinitelyTypedRunner.testDir + dir);
9+
return Harness.IO.getDirectories(DefinitelyTypedRunner.testDir);
710
}
811

912
public kind(): TestRunnerKind {
@@ -28,16 +31,19 @@ class DefinitelyTypedRunner extends RunnerBase {
2831
describe(directoryName, () => {
2932
const cp = require("child_process");
3033
const path = require("path");
34+
const fs = require("fs");
3135

3236
it("should build successfully", () => {
33-
const cwd = path.join(__dirname, "../../", directoryName);
37+
const cwd = path.join(__dirname, "../../", DefinitelyTypedRunner.testDir, directoryName);
3438
const timeout = 600000; // 600s = 10 minutes
35-
const stdio = isWorker ? "pipe" : "inherit";
36-
const install = cp.spawnSync(`npm`, ["i"], { cwd, timeout, shell: true, stdio });
37-
if (install.status !== 0) throw new Error(`NPM Install for ${directoryName} failed!`);
39+
if (fs.existsSync(path.join(cwd, 'package.json'))) {
40+
const stdio = isWorker ? "pipe" : "inherit";
41+
const install = cp.spawnSync(`npm`, ["i"], { cwd, timeout, shell: true, stdio });
42+
if (install.status !== 0) throw new Error(`NPM Install for ${directoryName} failed!`);
43+
}
3844
Harness.Baseline.runBaseline(`${this.kind()}/${directoryName}.log`, () => {
39-
const result = cp.spawnSync(`node`, [path.join(__dirname, "tsc.js"), "--lib dom,es6", "--strict"], { cwd, timeout, shell: true });
40-
return `Exit Code: ${result.status}
45+
const result = cp.spawnSync(`node`, [path.join(__dirname, "tsc.js")], { cwd, timeout, shell: true });
46+
return result.status === 0 ? null : `Exit Code: ${result.status}
4147
Standard output:
4248
${result.stdout.toString().replace(/\r\n/g, "\n")}
4349

src/harness/parallel/host.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,18 @@ namespace Harness.Parallel.Host {
7777
console.log("Discovering runner-based tests...");
7878
const discoverStart = +(new Date());
7979
const { statSync }: { statSync(path: string): { size: number }; } = require("fs");
80+
const path: { join: (...args: string[]) => string } = require("path");
8081
for (const runner of runners) {
81-
const files = runner.enumerateTestFiles();
82-
for (const file of files) {
82+
for (const file of runner.enumerateTestFiles()) {
8383
let size: number;
8484
if (!perfData) {
8585
try {
86-
size = statSync(file).size;
86+
size = statSync(path.join(runner.workingDirectory, file)).size;
8787
}
8888
catch {
8989
// May be a directory
9090
try {
91-
size = Harness.IO.listFiles(file, /.*/g, { recursive: true }).reduce((acc, elem) => acc + statSync(elem).size, 0);
91+
size = Harness.IO.listFiles(path.join(runner.workingDirectory, file), /.*/g, { recursive: true }).reduce((acc, elem) => acc + statSync(elem).size, 0);
9292
}
9393
catch {
9494
// Unknown test kind, just return 0 and let the historical analysis take over after one run

src/harness/runnerbase.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ abstract class RunnerBase {
2424

2525
abstract enumerateTestFiles(): string[];
2626

27+
/** The working directory where tests are found. Needed for batch testing where the input path will differ from the output path inside baselines */
28+
public workingDirectory = "";
29+
2730
/** Setup the runner's tests so that they are ready to be executed by the harness
2831
* The first test should be a describe/it block that sets up the harness's compiler instance appropriately
2932
*/

0 commit comments

Comments
 (0)