UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

31 lines (29 loc) 1.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const chai_1 = require("chai"); const TsSimpleAst_1 = require("./../../../TsSimpleAst"); const testHelpers = require("./../../testHelpers"); describe("EmitResult", () => { it("should get the emit result when there are no errors", () => { const fileSystem = testHelpers.getFileSystemHostWithFiles([]); const ast = new TsSimpleAst_1.TsSimpleAst({ compilerOptions: { noLib: true, outDir: "dist" } }, fileSystem); ast.addSourceFileFromText("file1.ts", "const num1 = 1;"); ast.addSourceFileFromText("file2.ts", "const num2 = 2;"); const result = ast.emit(); chai_1.expect(result.compilerObject).to.not.be.undefined; chai_1.expect(result.getEmitSkipped()).to.be.false; chai_1.expect(result.getDiagnostics().length).to.equal(0); }); it("should get the emit result when there are errors", () => { const fileSystem = testHelpers.getFileSystemHostWithFiles([]); const ast = new TsSimpleAst_1.TsSimpleAst({ compilerOptions: { noLib: true, outDir: "dist", noEmitOnError: true } }, fileSystem); ast.addSourceFileFromText("file1.ts", "const num1;"); const result = ast.emit(); chai_1.expect(result.getEmitSkipped()).to.be.true; const diagnostics = result.getDiagnostics(); const filteredDiagnostics = diagnostics.map(d => d.getMessageText()).filter(d => d.indexOf("Cannot find global type")); chai_1.expect(filteredDiagnostics.length).to.equal(1); chai_1.expect(filteredDiagnostics[0]).to.equal("'const' declarations must be initialized."); }); }); //# sourceMappingURL=emitResultTests.js.map