|
1 | 1 | var meteorTS = require("../index");
|
2 | 2 |
|
3 |
| -describe("meteor-typescript", function() { |
| 3 | +describe("meteor-typescript -> ", function() { |
4 | 4 |
|
5 |
| - var testCodeLine = "export const foo = 'foo'"; |
| 5 | + describe("testing exports and options -> ", function() { |
| 6 | + var testCodeLine = "export const foo = 'foo'"; |
6 | 7 |
|
7 |
| - it("should compile with defaults", function() { |
8 |
| - var result = meteorTS.compile(testCodeLine); |
9 |
| - expect(result.code.indexOf("exports.foo")).toEqual(0); |
10 |
| - }); |
| 8 | + it("should compile with defaults", function() { |
| 9 | + var result = meteorTS.compile(testCodeLine); |
| 10 | + expect(result.code.indexOf("exports.foo")).toEqual(0); |
| 11 | + }); |
11 | 12 |
|
12 |
| - it("should throw on wrong option", function() { |
13 |
| - var test = function() { |
14 |
| - meteorTS.compile(testCodeLine, { |
15 |
| - "wrong": true |
16 |
| - }); |
17 |
| - }; |
18 |
| - expect(test).toThrow(); |
19 |
| - }); |
| 13 | + it("should throw on wrong option", function() { |
| 14 | + var test = function() { |
| 15 | + meteorTS.compile(testCodeLine, { |
| 16 | + "wrong": true |
| 17 | + }); |
| 18 | + }; |
| 19 | + expect(test).toThrow(); |
| 20 | + }); |
20 | 21 |
|
21 |
| - it("should recognize preset options", function() { |
22 |
| - var result = meteorTS.compile(testCodeLine, { |
23 |
| - compilerOptions: { |
24 |
| - module: "system" |
25 |
| - } |
| 22 | + it("should allow null options", function() { |
| 23 | + var result = meteorTS.compile(testCodeLine, { |
| 24 | + compilerOptions: null, |
| 25 | + typings: undefined |
| 26 | + }); |
| 27 | + expect(result.code).not.toBeNull(); |
26 | 28 | });
|
27 |
| - expect(result.code.indexOf("System.register")).toEqual(0); |
28 |
| - }); |
29 | 29 |
|
30 |
| - it("should add module with moduleName name when moduleName is set", |
31 |
| - function() { |
| 30 | + it("should recognize preset options", function() { |
32 | 31 | var result = meteorTS.compile(testCodeLine, {
|
33 | 32 | compilerOptions: {
|
34 | 33 | module: "system"
|
35 |
| - }, |
36 |
| - moduleName: "fooModule" |
| 34 | + } |
37 | 35 | });
|
38 |
| - expect(result.code.indexOf("System.register(\"fooModule\"")) |
39 |
| - .toEqual(0); |
| 36 | + expect(result.code).toContain("System.register"); |
40 | 37 | });
|
41 | 38 |
|
42 |
| - it("should throw on wrong compiler option", function() { |
43 |
| - var test = function() { |
44 |
| - meteorTS.compile(testCodeLine, { |
| 39 | + it("should add module with moduleName name when moduleName is set", |
| 40 | + function() { |
| 41 | + var result = meteorTS.compile(testCodeLine, { |
45 | 42 | compilerOptions: {
|
46 |
| - module: "wrong" |
47 |
| - } |
| 43 | + module: "system" |
| 44 | + }, |
| 45 | + moduleName: "fooModule" |
| 46 | + }); |
| 47 | + expect(result.code.indexOf("System.register(\"fooModule\"")) |
| 48 | + .toEqual(0); |
48 | 49 | });
|
49 |
| - }; |
50 |
| - expect(test).toThrow(); |
| 50 | + |
| 51 | + it("should throw on wrong compiler option", function() { |
| 52 | + var test = function() { |
| 53 | + meteorTS.compile(testCodeLine, { |
| 54 | + compilerOptions: { |
| 55 | + module: "wrong" |
| 56 | + } |
| 57 | + }); |
| 58 | + }; |
| 59 | + expect(test).toThrow(); |
| 60 | + }); |
| 61 | + }); |
| 62 | + |
| 63 | + describe("testing diagnostics and typings -> ", function() { |
| 64 | + var codeLineWithImport = "import {api} from 'lib'; export const foo = 'foo'"; |
| 65 | + |
| 66 | + it("should contain a semantic error when some module undefined", function() { |
| 67 | + var result = meteorTS.compile(codeLineWithImport); |
| 68 | + |
| 69 | + expect(result.diagnostics.semanticErrors).not.toBeNull(); |
| 70 | + expect(result.diagnostics.semanticErrors.length).toEqual(1); |
| 71 | + var error = result.diagnostics.semanticErrors[0].message; |
| 72 | + expect(error).toContain("Cannot find module 'lib'"); |
| 73 | + }); |
| 74 | + |
| 75 | + it("declaration file with module declaration should remove an error", function() { |
| 76 | + var result = meteorTS.compile(codeLineWithImport, { |
| 77 | + typings: ["typings/lib.d.ts"] |
| 78 | + }); |
| 79 | + |
| 80 | + expect(result.diagnostics.semanticErrors).not.toBeNull(); |
| 81 | + expect(result.diagnostics.semanticErrors.length).toEqual(0); |
| 82 | + }); |
51 | 83 | });
|
52 | 84 |
|
53 | 85 | });
|
0 commit comments