forked from TypeScriptToLua/TypeScriptToLua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbundle.spec.ts
More file actions
122 lines (110 loc) · 3.81 KB
/
bundle.spec.ts
File metadata and controls
122 lines (110 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import { LuaLibImportKind } from "../../src";
import * as diagnosticFactories from "../../src/transpilation/diagnostics";
import * as util from "../util";
test("import module -> main", () => {
util.testBundle`
export { value } from "./module";
`
.addExtraFile("module.ts", "export const value = true")
.expectToEqual({ value: true });
});
test("import chain export -> reexport -> main", () => {
util.testBundle`
export { value } from "./reexport";
`
.addExtraFile("reexport.ts", "export { value } from './export'")
.addExtraFile("export.ts", "export const value = true")
.expectToEqual({ value: true });
});
test("diamond imports/exports -> reexport1 & reexport2 -> main", () => {
util.testBundle`
export { value as a } from "./reexport1";
export { value as b } from "./reexport2";
`
.addExtraFile("reexport1.ts", "export { value } from './export'")
.addExtraFile("reexport2.ts", "export { value } from './export'")
.addExtraFile("export.ts", "export const value = true")
.expectToEqual({ a: true, b: true });
});
test("module in directory", () => {
util.testBundle`
export { value } from "./module/module";
`
.addExtraFile("module/module.ts", "export const value = true")
.expectToEqual({ value: true });
});
test("modules aren't ordered by name", () => {
util.testBundle`
export { value } from "./a";
`
.addExtraFile("a.ts", "export const value = true")
.expectToEqual({ value: true });
});
test("entry point in directory", () => {
util.testBundle``
.addExtraFile(
"main/main.ts",
`
export { value } from "../module";
`
)
.addExtraFile("module.ts", "export const value = true")
.setEntryPoint("main/main.ts")
.expectToEqual({ value: true });
});
test("entry point in rootDir", () => {
util.testModule`
export { value } from "./module";
`
.setMainFileName("src/main.ts")
.addExtraFile("src/module.ts", "export const value = true")
.setOptions({ rootDir: "src", luaBundle: "bundle.lua", luaBundleEntry: "src/main.ts" })
.expectToEqual({ value: true });
});
test("LuaLibImportKind.Require", () => {
util.testBundle`
export const result = [1, 2];
result.push(3);
`
.setOptions({ luaLibImport: LuaLibImportKind.Require })
.expectToEqual({ result: [1, 2, 3] });
});
test("LuaLibImportKind.Inline generates a warning", () => {
util.testBundle`
export const result = [1, 2];
result.push(3);
`
.setOptions({ luaLibImport: LuaLibImportKind.Inline })
.expectDiagnosticsToMatchSnapshot(
[diagnosticFactories.usingLuaBundleWithInlineMightGenerateDuplicateCode.code],
true
)
.expectToEqual({ result: [1, 2, 3] });
});
test("cyclic imports", () => {
util.testBundle`
import * as b from "./b";
export const a = true;
export const valueResult = b.value;
export const lazyValueResult = b.lazyValue();
`
.addExtraFile(
"b.ts",
`
import * as a from "./main";
export const value = a.a;
export const lazyValue = () => a.a;
`
)
.expectToEqual(new util.ExecutionError("stack overflow"));
});
test("no entry point", () => {
util.testBundle``
.setOptions({ luaBundleEntry: undefined })
.expectDiagnosticsToMatchSnapshot([diagnosticFactories.luaBundleEntryIsRequired.code], true);
});
test("luaEntry doesn't exist", () => {
util.testBundle``
.setEntryPoint("entry.ts")
.expectDiagnosticsToMatchSnapshot([diagnosticFactories.couldNotFindBundleEntryPoint.code], true);
});