11import * as path from "path" ;
22import * as ts from "typescript" ;
3- import { DiagnosticCategory } from "typescript" ;
43import { LuaLibImportKind } from "../../src" ;
5- import { couldNotFindBundleEntryPoint } from "../../src/transpilation/diagnostics" ;
64import * 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-
186test ( "import module -> main" , ( ) => {
197 util . testBundle `
208 export { value } from "./module";
@@ -24,14 +12,14 @@ test("import module -> main", () => {
2412} ) ;
2513
2614test ( "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
12197test ( "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+
139119test ( "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