|
| 1 | +import { Any, Expect, Setup, SpyOn, Teardown, Test, TestCase } from "alsatian"; |
| 2 | +import * as fs from "fs"; |
| 3 | +import * as path from "path"; |
| 4 | +import * as ts from "typescript"; |
| 5 | +import { compile } from "../../src/Compiler"; |
| 6 | + |
| 7 | +export class CompilerErrorReportTests { |
| 8 | + private originalStdErr: any; |
| 9 | + private originalStdOut: any; |
| 10 | + private originalProcessExit: any; |
| 11 | + |
| 12 | + @TestCase("Encountered error parsing file: Default Imports are not supported, please use named imports instead!\n", |
| 13 | + "default_import.ts") |
| 14 | + @TestCase("Encountered error parsing file: Unsupported expression kind: Block\n", "invalid_syntax.ts") |
| 15 | + @Test("Compile project") |
| 16 | + public compileProject(errorMsg: string, ...fileNames: string[]) { |
| 17 | + fileNames = fileNames.map((file) => path.resolve(__dirname, "testfiles", file)); |
| 18 | + compile(fileNames, {outDir: ".", rootDir: "."}); |
| 19 | + |
| 20 | + Expect(process.stderr.write).toHaveBeenCalledWith(errorMsg, Any); |
| 21 | + |
| 22 | + Expect(process.exit).toHaveBeenCalledWith(1); |
| 23 | + } |
| 24 | + |
| 25 | + @Setup |
| 26 | + private _spyProcess() { |
| 27 | + this.originalProcessExit = process.exit; |
| 28 | + this.originalStdOut = process.stdout.write; |
| 29 | + this.originalStdErr = process.stderr.write; |
| 30 | + |
| 31 | + SpyOn(process, "exit").andStub(); |
| 32 | + SpyOn(process.stderr, "write").andStub(); |
| 33 | + SpyOn(process.stdout, "write").andStub(); |
| 34 | + } |
| 35 | + |
| 36 | + @Teardown |
| 37 | + private _resetProcess() { |
| 38 | + process.exit = this.originalProcessExit; |
| 39 | + process.stdout.write = this.originalStdOut; |
| 40 | + process.stderr.write = this.originalStdErr; |
| 41 | + } |
| 42 | + |
| 43 | +} |
0 commit comments