Skip to content

Commit 11c3ee4

Browse files
committed
Make bundle tests check diagnostic snapshots
1 parent dc45631 commit 11c3ee4

File tree

2 files changed

+23
-36
lines changed

2 files changed

+23
-36
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`LuaLibImportKind.Inline generates a warning: diagnostics 1`] = `"warning TSTL: Using 'luaBundle' with 'luaLibImport: \\"inline\\"' might generate duplicate code. It is recommended to use 'luaLibImport: \\"require\\"'"`;
4+
5+
exports[`luaEntry doesn't exist: diagnostics 1`] = `"error TSTL: Could not find bundle entry point 'entry.ts'. It should be a file in the project."`;
6+
7+
exports[`no entry point: diagnostics 1`] = `"error TSTL: 'luaBundleEntry' is required when 'luaBundle' is enabled."`;

test/unit/bundle.spec.ts

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,8 @@
11
import * as path from "path";
22
import * as ts from "typescript";
3-
import { DiagnosticCategory } from "typescript";
43
import { LuaLibImportKind } from "../../src";
5-
import { couldNotFindBundleEntryPoint } from "../../src/transpilation/diagnostics";
64
import * as util from "../util";
75

8-
test("no entry point", () => {
9-
util.testBundle``
10-
.setOptions({ luaBundleEntry: undefined })
11-
.expectToHaveDiagnostic(
12-
d =>
13-
d.messageText === `'luaBundleEntry' is required when 'luaBundle' is enabled.` &&
14-
d.category === DiagnosticCategory.Error
15-
);
16-
});
17-
186
test("import module -> main", () => {
197
util.testBundle`
208
export { value } from "./module";
@@ -24,14 +12,14 @@ test("import module -> main", () => {
2412
});
2513

2614
test("bundle file name", () => {
27-
const { diagnostics, transpiledFiles } = util.testModule`
15+
const { transpiledFiles } = util.testModule`
2816
export { value } from "./module";
2917
`
3018
.addExtraFile("module.ts", "export const value = true")
3119
.setOptions({ luaBundle: "mybundle.lua", luaBundleEntry: "main.ts" })
20+
.expectToHaveNoDiagnostics()
3221
.getLuaResult();
3322

34-
expect(diagnostics.length).toBe(0);
3523
expect(transpiledFiles.length).toBe(1);
3624
expect(transpiledFiles[0].fileName).toBe(
3725
path.join(ts.sys.getCurrentDirectory(), "mybundle.lua").replace(/\\/g, "/")
@@ -87,35 +75,23 @@ test("entry point in directory", () => {
8775
.expectToEqual({ value: true });
8876
});
8977

90-
test.each([LuaLibImportKind.Inline, LuaLibImportKind.Require])("LuaLib %p", lualibOption => {
91-
const testBundle = util.testBundle`
78+
test("LuaLibImportKind.Require", () => {
79+
util.testBundle`
9280
export const result = [1, 2];
9381
result.push(3);
94-
`.setOptions({ luaLibImport: lualibOption });
95-
96-
if (lualibOption === LuaLibImportKind.Inline) {
97-
testBundle.expectToHaveDiagnostic(d => d.category === DiagnosticCategory.Warning);
98-
} else {
99-
expect(testBundle.getLuaResult().diagnostics).toEqual([]);
100-
}
101-
expect(testBundle.getLuaExecutionResult()).toEqual({ result: [1, 2, 3] });
82+
`
83+
.setOptions({ luaLibImport: LuaLibImportKind.Require })
84+
.expectToEqual({ result: [1, 2, 3] });
10285
});
10386

104-
test("LuaBundle and LuaLibImport.Inline generate warning", () => {
105-
const testBundle = util.testBundle`
87+
test("LuaLibImportKind.Inline generates a warning", () => {
88+
util.testBundle`
10689
export const result = [1, 2];
10790
result.push(3);
10891
`
10992
.setOptions({ luaLibImport: LuaLibImportKind.Inline })
110-
.expectToHaveDiagnostic(
111-
d =>
112-
d.category === DiagnosticCategory.Warning &&
113-
d.messageText ===
114-
`Using 'luaBundle' with 'luaLibImport: "inline"' might generate duplicate code. ` +
115-
`It is recommended to use 'luaLibImport: "require"'`
116-
);
117-
118-
expect(testBundle.getLuaExecutionResult()).toEqual({ result: [1, 2, 3] }); // Result should still be the same
93+
.expectDiagnosticsToMatchSnapshot(true)
94+
.expectToEqual({ result: [1, 2, 3] });
11995
});
12096

12197
test("cyclic imports", () => {
@@ -136,6 +112,10 @@ test("cyclic imports", () => {
136112
.expectToEqual(new util.ExecutionError("stack overflow"));
137113
});
138114

115+
test("no entry point", () => {
116+
util.testBundle``.setOptions({ luaBundleEntry: undefined }).expectDiagnosticsToMatchSnapshot(true);
117+
});
118+
139119
test("luaEntry doesn't exist", () => {
140-
util.testBundle``.setEntryPoint("entry.ts").expectToHaveExactDiagnostic(couldNotFindBundleEntryPoint("entry.ts"));
120+
util.testBundle``.setEntryPoint("entry.ts").expectDiagnosticsToMatchSnapshot(true);
141121
});

0 commit comments

Comments
 (0)