Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DefinitelyTyped runner #19815

Merged
merged 9 commits into from
Nov 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ var harnessCoreSources = [
"projectsRunner.ts",
"loggedIO.ts",
"rwcRunner.ts",
"userRunner.ts",
"externalCompileRunner.ts",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jakefile, but not gulp?

The official TS homepage refers to gulp. Does it mean both gulp/jake need to be used, depending on area of the project?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If they don't behave the same it's a bug.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gulp uses the tsconfig edited below.

"test262Runner.ts",
"./parallel/shared.ts",
"./parallel/host.ts",
Expand Down
67 changes: 67 additions & 0 deletions src/harness/externalCompileRunner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/// <reference path="harness.ts"/>
/// <reference path="runnerbase.ts" />
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 && !result.stdout.length && !result.stderr.length ? 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";
}
}
8 changes: 4 additions & 4 deletions src/harness/parallel/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/harness/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/// <reference path="fourslashRunner.ts" />
/// <reference path="projectsRunner.ts" />
/// <reference path="rwcRunner.ts" />
/// <reference path="userRunner.ts" />
/// <reference path="externalCompileRunner.ts" />
/// <reference path="harness.ts" />
/// <reference path="./parallel/shared.ts" />

Expand Down Expand Up @@ -62,6 +62,8 @@ function createRunner(kind: TestRunnerKind): RunnerBase {
return new Test262BaselineRunner();
case "user":
return new UserCodeRunner();
case "dt":
return new DefinitelyTypedRunner();
}
ts.Debug.fail(`Unknown runner kind ${kind}`);
}
Expand Down Expand Up @@ -183,6 +185,9 @@ function handleTestConfig() {
case "user":
runners.push(new UserCodeRunner());
break;
case "dt":
runners.push(new DefinitelyTypedRunner());
break;
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/harness/runnerbase.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// <reference path="harness.ts" />


type TestRunnerKind = CompilerTestKind | FourslashTestKind | "project" | "rwc" | "test262" | "user";
type TestRunnerKind = CompilerTestKind | FourslashTestKind | "project" | "rwc" | "test262" | "user" | "dt";
type CompilerTestKind = "conformance" | "compiler";
type FourslashTestKind = "fourslash" | "fourslash-shims" | "fourslash-shims-pp" | "fourslash-server";

Expand All @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion src/harness/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"projectsRunner.ts",
"loggedIO.ts",
"rwcRunner.ts",
"userRunner.ts",
"externalCompileRunner.ts",
"test262Runner.ts",
"./parallel/shared.ts",
"./parallel/host.ts",
Expand Down
51 changes: 0 additions & 51 deletions src/harness/userRunner.ts

This file was deleted.

6 changes: 0 additions & 6 deletions tests/baselines/reference/user/ajv.log

This file was deleted.

6 changes: 0 additions & 6 deletions tests/baselines/reference/user/antd.log

This file was deleted.

6 changes: 0 additions & 6 deletions tests/baselines/reference/user/axios.log

This file was deleted.

6 changes: 0 additions & 6 deletions tests/baselines/reference/user/bignumber.js.log

This file was deleted.

6 changes: 0 additions & 6 deletions tests/baselines/reference/user/discord.js.log

This file was deleted.

6 changes: 0 additions & 6 deletions tests/baselines/reference/user/eventemitter2.log

This file was deleted.

6 changes: 0 additions & 6 deletions tests/baselines/reference/user/eventemitter3.log

This file was deleted.

6 changes: 0 additions & 6 deletions tests/baselines/reference/user/firebase.log

This file was deleted.

6 changes: 0 additions & 6 deletions tests/baselines/reference/user/github.log

This file was deleted.

6 changes: 0 additions & 6 deletions tests/baselines/reference/user/immutable.log

This file was deleted.

6 changes: 0 additions & 6 deletions tests/baselines/reference/user/isobject.log

This file was deleted.

6 changes: 0 additions & 6 deletions tests/baselines/reference/user/jimp.log

This file was deleted.

6 changes: 0 additions & 6 deletions tests/baselines/reference/user/jsonschema.log

This file was deleted.

6 changes: 0 additions & 6 deletions tests/baselines/reference/user/keycode.log

This file was deleted.

6 changes: 0 additions & 6 deletions tests/baselines/reference/user/localforage.log

This file was deleted.

6 changes: 0 additions & 6 deletions tests/baselines/reference/user/log4js.log

This file was deleted.

6 changes: 0 additions & 6 deletions tests/baselines/reference/user/mobx.log

This file was deleted.

6 changes: 0 additions & 6 deletions tests/baselines/reference/user/moment.log

This file was deleted.

6 changes: 0 additions & 6 deletions tests/baselines/reference/user/mqtt.log

This file was deleted.

6 changes: 0 additions & 6 deletions tests/baselines/reference/user/parse5.log

This file was deleted.

6 changes: 0 additions & 6 deletions tests/baselines/reference/user/portfinder.log

This file was deleted.

6 changes: 0 additions & 6 deletions tests/baselines/reference/user/postcss.log

This file was deleted.

6 changes: 0 additions & 6 deletions tests/baselines/reference/user/protobufjs.log

This file was deleted.

6 changes: 0 additions & 6 deletions tests/baselines/reference/user/redux.log

This file was deleted.

6 changes: 0 additions & 6 deletions tests/baselines/reference/user/reselect.log

This file was deleted.

6 changes: 0 additions & 6 deletions tests/baselines/reference/user/should.log

This file was deleted.

6 changes: 0 additions & 6 deletions tests/baselines/reference/user/sift.log

This file was deleted.

Loading