|
| 1 | +/// <reference path="harness.ts"/> |
| 2 | +/// <reference path="runnerbase.ts" /> |
| 3 | +class UserCodeRunner extends RunnerBase { |
| 4 | + private static readonly testDir = "tests/cases/user/"; |
| 5 | + public enumerateTestFiles() { |
| 6 | + return Harness.IO.getDirectories(UserCodeRunner.testDir); |
| 7 | + } |
| 8 | + |
| 9 | + public kind(): TestRunnerKind { |
| 10 | + return "user"; |
| 11 | + } |
| 12 | + |
| 13 | + /** Setup the runner's tests so that they are ready to be executed by the harness |
| 14 | + * The first test should be a describe/it block that sets up the harness's compiler instance appropriately |
| 15 | + */ |
| 16 | + public initializeTests(): void { |
| 17 | + // Read in and evaluate the test list |
| 18 | + const testList = this.tests && this.tests.length ? this.tests : this.enumerateTestFiles(); |
| 19 | + |
| 20 | + describe(`${this.kind()} code samples`, () => { |
| 21 | + for (let i = 0; i < testList.length; i++) { |
| 22 | + this.runTest(testList[i]); |
| 23 | + } |
| 24 | + }); |
| 25 | + } |
| 26 | + |
| 27 | + private runTest(directoryName: string) { |
| 28 | + describe(directoryName, () => { |
| 29 | + const cp = require("child_process"); |
| 30 | + const path = require("path"); |
| 31 | + |
| 32 | + it("should build successfully", () => { |
| 33 | + const cwd = path.join(__dirname, "../../", UserCodeRunner.testDir, directoryName); |
| 34 | + const timeout = 600000; // 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!`); |
| 38 | + Harness.Baseline.runBaseline(`${this.kind()}/${directoryName}.log`, () => { |
| 39 | + const result = cp.spawnSync(`node`, ["../../../../built/local/tsc.js"], { cwd, timeout, shell: true }); |
| 40 | + return `Exit Code: ${result.status} |
| 41 | +Standard output: |
| 42 | +${result.stdout.toString().replace(/\r\n/g, "\n")} |
| 43 | +
|
| 44 | +
|
| 45 | +Standard error: |
| 46 | +${result.stderr.toString().replace(/\r\n/g, "\n")}`; |
| 47 | + }); |
| 48 | + }); |
| 49 | + }); |
| 50 | + } |
| 51 | +} |
0 commit comments