-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests to test typings and options
This part of the effort to create an official TypeScript compiler: Urigo/angular2-meteor#89 Urigo/angular2-meteor#90 Urigo/angular2-meteor#102
- Loading branch information
Showing
5 changed files
with
82 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,85 @@ | ||
var meteorTS = require("../index"); | ||
|
||
describe("meteor-typescript", function() { | ||
describe("meteor-typescript -> ", function() { | ||
|
||
var testCodeLine = "export const foo = 'foo'"; | ||
describe("testing exports and options -> ", function() { | ||
var testCodeLine = "export const foo = 'foo'"; | ||
|
||
it("should compile with defaults", function() { | ||
var result = meteorTS.compile(testCodeLine); | ||
expect(result.code.indexOf("exports.foo")).toEqual(0); | ||
}); | ||
it("should compile with defaults", function() { | ||
var result = meteorTS.compile(testCodeLine); | ||
expect(result.code.indexOf("exports.foo")).toEqual(0); | ||
}); | ||
|
||
it("should throw on wrong option", function() { | ||
var test = function() { | ||
meteorTS.compile(testCodeLine, { | ||
"wrong": true | ||
}); | ||
}; | ||
expect(test).toThrow(); | ||
}); | ||
it("should throw on wrong option", function() { | ||
var test = function() { | ||
meteorTS.compile(testCodeLine, { | ||
"wrong": true | ||
}); | ||
}; | ||
expect(test).toThrow(); | ||
}); | ||
|
||
it("should recognize preset options", function() { | ||
var result = meteorTS.compile(testCodeLine, { | ||
compilerOptions: { | ||
module: "system" | ||
} | ||
it("should allow null options", function() { | ||
var result = meteorTS.compile(testCodeLine, { | ||
compilerOptions: null, | ||
typings: undefined | ||
}); | ||
expect(result.code).not.toBeNull(); | ||
}); | ||
expect(result.code.indexOf("System.register")).toEqual(0); | ||
}); | ||
|
||
it("should add module with moduleName name when moduleName is set", | ||
function() { | ||
it("should recognize preset options", function() { | ||
var result = meteorTS.compile(testCodeLine, { | ||
compilerOptions: { | ||
module: "system" | ||
}, | ||
moduleName: "fooModule" | ||
} | ||
}); | ||
expect(result.code.indexOf("System.register(\"fooModule\"")) | ||
.toEqual(0); | ||
expect(result.code).toContain("System.register"); | ||
}); | ||
|
||
it("should throw on wrong compiler option", function() { | ||
var test = function() { | ||
meteorTS.compile(testCodeLine, { | ||
it("should add module with moduleName name when moduleName is set", | ||
function() { | ||
var result = meteorTS.compile(testCodeLine, { | ||
compilerOptions: { | ||
module: "wrong" | ||
} | ||
module: "system" | ||
}, | ||
moduleName: "fooModule" | ||
}); | ||
expect(result.code.indexOf("System.register(\"fooModule\"")) | ||
.toEqual(0); | ||
}); | ||
}; | ||
expect(test).toThrow(); | ||
|
||
it("should throw on wrong compiler option", function() { | ||
var test = function() { | ||
meteorTS.compile(testCodeLine, { | ||
compilerOptions: { | ||
module: "wrong" | ||
} | ||
}); | ||
}; | ||
expect(test).toThrow(); | ||
}); | ||
}); | ||
|
||
describe("testing diagnostics and typings -> ", function() { | ||
var codeLineWithImport = "import {api} from 'lib'; export const foo = 'foo'"; | ||
|
||
it("should contain a semantic error when some module undefined", function() { | ||
var result = meteorTS.compile(codeLineWithImport); | ||
|
||
expect(result.diagnostics.semanticErrors).not.toBeNull(); | ||
expect(result.diagnostics.semanticErrors.length).toEqual(1); | ||
var error = result.diagnostics.semanticErrors[0].message; | ||
expect(error).toContain("Cannot find module 'lib'"); | ||
}); | ||
|
||
it("declaration file with module declaration should remove an error", function() { | ||
var result = meteorTS.compile(codeLineWithImport, { | ||
typings: ["typings/lib.d.ts"] | ||
}); | ||
|
||
expect(result.diagnostics.semanticErrors).not.toBeNull(); | ||
expect(result.diagnostics.semanticErrors.length).toEqual(0); | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
declare module "lib" { | ||
export let api = {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters