@@ -60,7 +60,7 @@ export function testEachVersion<T extends TestBuilder>(
6060 test ( testName , ( ) => {
6161 const builder = common ( ) ;
6262 builder . setOptions ( { luaTarget : version } ) ;
63- if ( typeof specialBuilder === ' function' ) {
63+ if ( typeof specialBuilder === " function" ) {
6464 specialBuilder ( builder ) ;
6565 }
6666 } ) ;
@@ -151,7 +151,6 @@ export class ExecutionError extends Error {
151151
152152export type ExecutableTranspiledFile = tstl . TranspiledFile & { lua : string ; sourceMap : string } ;
153153export type TapCallback = ( builder : TestBuilder ) => void ;
154- export type DiagnosticMatcher = ( diagnostic : ts . Diagnostic ) => boolean ;
155154export abstract class TestBuilder {
156155 constructor ( protected _tsCode : string ) { }
157156
@@ -339,47 +338,21 @@ export abstract class TestBuilder {
339338 return this ;
340339 }
341340
342- public expectToHaveDiagnostic ( matcher : DiagnosticMatcher ) : this {
343- expect ( this . getLuaDiagnostics ( ) . find ( matcher ) ) . toBeDefined ( ) ;
344- return this ;
345- }
346-
347- public expectToHaveExactDiagnostic ( diagnostic : ts . Diagnostic ) : this {
348- expect ( this . getLuaDiagnostics ( ) ) . toContainEqual ( diagnostic ) ;
349- return this ;
350- }
341+ private diagnosticsChecked = false ;
351342
352343 public expectToHaveDiagnostics ( ) : this {
353- expect ( this . getLuaDiagnostics ( ) ) . toHaveDiagnostics ( ) ;
354- return this ;
355- }
344+ if ( this . diagnosticsChecked ) return this ;
345+ this . diagnosticsChecked = true ;
356346
357- public expectToHaveDiagnosticOfError ( error : Error ) : this {
358- this . expectToHaveDiagnostics ( ) ;
359- expect ( this . getLuaDiagnostics ( ) ) . toHaveLength ( 1 ) ;
360- const firstDiagnostic = this . getLuaDiagnostics ( ) [ 0 ] ;
361- expect ( firstDiagnostic ) . toMatchObject ( { messageText : error . message } ) ;
347+ expect ( this . getLuaDiagnostics ( ) ) . toHaveDiagnostics ( ) ;
362348 return this ;
363349 }
364350
365351 public expectToHaveNoDiagnostics ( ) : this {
366- expect ( this . getLuaDiagnostics ( ) ) . not . toHaveDiagnostics ( ) ;
367- return this ;
368- }
369-
370- public expectDiagnosticsToMatchSnapshot ( diagnosticsOnly = false ) : this {
371- this . expectToHaveDiagnostics ( ) ;
372-
373- const diagnosticMessages = ts . formatDiagnostics (
374- this . getLuaDiagnostics ( ) . map ( tstl . prepareDiagnosticForFormatting ) ,
375- { getCurrentDirectory : ( ) => "" , getCanonicalFileName : fileName => fileName , getNewLine : ( ) => "\n" }
376- ) ;
377-
378- expect ( diagnosticMessages . trim ( ) ) . toMatchSnapshot ( "diagnostics" ) ;
379- if ( ! diagnosticsOnly ) {
380- expect ( this . getMainLuaCodeChunk ( ) ) . toMatchSnapshot ( "code" ) ;
381- }
352+ if ( this . diagnosticsChecked ) return this ;
353+ this . diagnosticsChecked = true ;
382354
355+ expect ( this . getLuaDiagnostics ( ) ) . not . toHaveDiagnostics ( ) ;
383356 return this ;
384357 }
385358
@@ -416,9 +389,19 @@ export abstract class TestBuilder {
416389 return this ;
417390 }
418391
419- public expectResultToMatchSnapshot ( ) : this {
420- this . expectToHaveNoDiagnostics ( ) ;
421- expect ( this . getLuaExecutionResult ( ) ) . toMatchSnapshot ( ) ;
392+ public expectDiagnosticsToMatchSnapshot ( diagnosticsOnly = false ) : this {
393+ this . expectToHaveDiagnostics ( ) ;
394+
395+ const diagnosticMessages = ts . formatDiagnostics (
396+ this . getLuaDiagnostics ( ) . map ( tstl . prepareDiagnosticForFormatting ) ,
397+ { getCurrentDirectory : ( ) => "" , getCanonicalFileName : fileName => fileName , getNewLine : ( ) => "\n" }
398+ ) ;
399+
400+ expect ( diagnosticMessages . trim ( ) ) . toMatchSnapshot ( "diagnostics" ) ;
401+ if ( ! diagnosticsOnly ) {
402+ expect ( this . getMainLuaCodeChunk ( ) ) . toMatchSnapshot ( "code" ) ;
403+ }
404+
422405 return this ;
423406 }
424407
0 commit comments