|
| 1 | +/// <reference path="harness.ts"/> |
| 2 | +/// <reference path="runnerbase.ts" /> |
| 3 | +abstract class ExternalCompileRunnerBase extends RunnerBase { |
| 4 | + abstract testDir: string; |
| 5 | + public enumerateTestFiles() { |
| 6 | + return Harness.IO.getDirectories(this.testDir); |
| 7 | + } |
| 8 | + /** Setup the runner's tests so that they are ready to be executed by the harness |
| 9 | + * The first test should be a describe/it block that sets up the harness's compiler instance appropriately |
| 10 | + */ |
| 11 | + public initializeTests(): void { |
| 12 | + // Read in and evaluate the test list |
| 13 | + const testList = this.tests && this.tests.length ? this.tests : this.enumerateTestFiles(); |
| 14 | + |
| 15 | + describe(`${this.kind()} code samples`, () => { |
| 16 | + for (const test of testList) { |
| 17 | + this.runTest(test); |
| 18 | + } |
| 19 | + }); |
| 20 | + } |
| 21 | + private runTest(directoryName: string) { |
| 22 | + describe(directoryName, () => { |
| 23 | + const cp = require("child_process"); |
| 24 | + const path = require("path"); |
| 25 | + const fs = require("fs"); |
| 26 | + |
| 27 | + it("should build successfully", () => { |
| 28 | + const cwd = path.join(__dirname, "../../", this.testDir, directoryName); |
| 29 | + const timeout = 600000; // 600s = 10 minutes |
| 30 | + if (fs.existsSync(path.join(cwd, "package.json"))) { |
| 31 | + if (fs.existsSync(path.join(cwd, "package-lock.json"))) { |
| 32 | + fs.unlinkSync(path.join(cwd, "package-lock.json")); |
| 33 | + } |
| 34 | + const stdio = isWorker ? "pipe" : "inherit"; |
| 35 | + const install = cp.spawnSync(`npm`, ["i"], { cwd, timeout, shell: true, stdio }); |
| 36 | + if (install.status !== 0) throw new Error(`NPM Install for ${directoryName} failed!`); |
| 37 | + } |
| 38 | + Harness.Baseline.runBaseline(`${this.kind()}/${directoryName}.log`, () => { |
| 39 | + const result = cp.spawnSync(`node`, [path.join(__dirname, "tsc.js")], { cwd, timeout, shell: true }); |
| 40 | + // tslint:disable-next-line:no-null-keyword |
| 41 | + return result.status === 0 && !result.stdout.length && !result.stderr.length ? null : `Exit Code: ${result.status} |
| 42 | +Standard output: |
| 43 | +${result.stdout.toString().replace(/\r\n/g, "\n")} |
| 44 | +
|
| 45 | +
|
| 46 | +Standard error: |
| 47 | +${result.stderr.toString().replace(/\r\n/g, "\n")}`; |
| 48 | + }); |
| 49 | + }); |
| 50 | + }); |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +class UserCodeRunner extends ExternalCompileRunnerBase { |
| 55 | + public readonly testDir = "tests/cases/user/"; |
| 56 | + public kind(): TestRunnerKind { |
| 57 | + return "user"; |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +class DefinitelyTypedRunner extends ExternalCompileRunnerBase { |
| 62 | + public readonly testDir = "../DefinitelyTyped/types/"; |
| 63 | + public workingDirectory = this.testDir; |
| 64 | + public kind(): TestRunnerKind { |
| 65 | + return "dt"; |
| 66 | + } |
| 67 | +} |
0 commit comments