Skip to content

Commit 3c630aa

Browse files
committed
added tests
1 parent 7c8a503 commit 3c630aa

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

tests/cases/unittests/transpile.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
module ts {
44
describe("Transpile", () => {
55

6-
function runTest(input: string, compilerOptions: ts.CompilerOptions = {}, expectedOutput?: string, expectedDiagnosticCodes: number[] = []): void {
6+
function runTest(input: string, compilerOptions: ts.CompilerOptions = {}, moduleName?: string, expectedOutput?: string, expectedDiagnosticCodes: number[] = []): void {
77
let diagnostics: Diagnostic[] = [];
8-
let result = transpile(input, compilerOptions, "file.ts", diagnostics);
8+
let result = transpile(input, compilerOptions, "file.ts", diagnostics, moduleName);
99

1010
for (let i = 0; i < expectedDiagnosticCodes.length; i++) {
1111
assert.equal(expectedDiagnosticCodes[i], diagnostics[i] && diagnostics[i].code, `Could not find expeced diagnostic.`);
@@ -19,41 +19,54 @@ module ts {
1919

2020
it("Generates correct compilerOptions diagnostics", () => {
2121
// Expecting 5047: "Option 'isolatedModules' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher."
22-
runTest(`var x = 0;`, {}, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ [5047]);
22+
runTest(`var x = 0;`, {}, /*moduleName*/undefined, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ [5047]);
2323
});
2424

2525
it("Generates no diagnostics with valid inputs", () => {
2626
// No errors
27-
runTest(`var x = 0;`, { module: ModuleKind.CommonJS }, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ []);
27+
runTest(`var x = 0;`, { module: ModuleKind.CommonJS }, /*moduleName*/undefined, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ []);
2828
});
2929

3030
it("Generates no diagnostics for missing file references", () => {
3131
runTest(`/// <reference path="file2.ts" />
3232
var x = 0;`,
33-
{ module: ModuleKind.CommonJS }, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ []);
33+
{ module: ModuleKind.CommonJS }, /*moduleName*/undefined, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ []);
3434
});
3535

3636
it("Generates no diagnostics for missing module imports", () => {
3737
runTest(`import {a} from "module2";`,
38-
{ module: ModuleKind.CommonJS }, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ []);
38+
{ module: ModuleKind.CommonJS }, /*moduleName*/undefined, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ []);
3939
});
4040

4141
it("Generates expected syntactic diagnostics", () => {
4242
runTest(`a b`,
43-
{ module: ModuleKind.CommonJS }, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ [1005]); /// 1005: ';' Expected
43+
{ module: ModuleKind.CommonJS }, /*moduleName*/undefined, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ [1005]); /// 1005: ';' Expected
4444
});
4545

4646
it("Does not generate semantic diagnostics", () => {
4747
runTest(`var x: string = 0;`,
48-
{ module: ModuleKind.CommonJS }, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ []);
48+
{ module: ModuleKind.CommonJS }, /*moduleName*/undefined, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ []);
4949
});
5050

5151
it("Generates module output", () => {
52-
runTest(`var x = 0;`, { module: ModuleKind.AMD }, `define(["require", "exports"], function (require, exports) {\r\n var x = 0;\r\n});\r\n`);
52+
runTest(`var x = 0;`, { module: ModuleKind.AMD }, /*moduleName*/undefined, `define(["require", "exports"], function (require, exports) {\r\n var x = 0;\r\n});\r\n`);
5353
});
5454

5555
it("Uses correct newLine character", () => {
56-
runTest(`var x = 0;`, { module: ModuleKind.CommonJS, newLine: NewLineKind.LineFeed }, `var x = 0;\n`, /*expectedDiagnosticCodes*/ []);
56+
runTest(`var x = 0;`, { module: ModuleKind.CommonJS, newLine: NewLineKind.LineFeed }, /*moduleName*/undefined, `var x = 0;\n`, /*expectedDiagnosticCodes*/ []);
57+
});
58+
59+
it("Sets module name", () => {
60+
let output =
61+
`System.register("NamedModule", [], function(exports_1) {\n var x;\n` +
62+
` return {\n` +
63+
` setters:[],\n` +
64+
` execute: function() {\n` +
65+
` var x = 1;\n` +
66+
` }\n` +
67+
` }\n` +
68+
`});\n`;
69+
runTest("var x = 1;", { module: ModuleKind.System, newLine: NewLineKind.LineFeed }, "NamedModule", output)
5770
});
5871
});
5972
}

0 commit comments

Comments
 (0)