@@ -7,13 +7,17 @@ namespace ts {
77 options ?: TranspileOptions ;
88 expectedOutput ?: string ;
99 expectedDiagnosticCodes ?: number [ ] ;
10+ expectedDiagnosticTexts ?: string [ ] ;
1011 }
1112
12- function checkDiagnostics ( diagnostics : Diagnostic [ ] , expectedDiagnosticCodes : number [ ] = [ ] ) {
13- for ( let i = 0 ; i < expectedDiagnosticCodes . length ; i ++ ) {
14- assert . equal ( expectedDiagnosticCodes [ i ] , diagnostics [ i ] && diagnostics [ i ] . code , `Could not find expeced diagnostic.` ) ;
13+ function checkDiagnostics ( diagnostics : Diagnostic [ ] , expectedDiagnosticCodes : number [ ] = [ ] , expectedDiagnosticTexts : string [ ] = [ ] ) {
14+ const n = expectedDiagnosticCodes . length ;
15+ assert . equal ( n , expectedDiagnosticTexts . length ) ;
16+ for ( let i = 0 ; i < n ; i ++ ) {
17+ assert . equal ( expectedDiagnosticCodes [ i ] , diagnostics [ i ] && diagnostics [ i ] . code , `Could not find expected diagnostic.` ) ;
18+ assert . equal ( expectedDiagnosticTexts [ i ] , diagnostics [ i ] && diagnostics [ i ] . messageText ) ;
1519 }
16- assert . equal ( diagnostics . length , expectedDiagnosticCodes . length , "Resuting diagnostics count does not match expected" ) ;
20+ assert . equal ( diagnostics . length , n , "Resuting diagnostics count does not match expected" ) ;
1721 }
1822
1923 function test ( input : string , testSettings : TranspileTestSettings ) : void {
@@ -32,7 +36,7 @@ namespace ts {
3236 transpileOptions . reportDiagnostics = true ;
3337 const transpileModuleResult = transpileModule ( input , transpileOptions ) ;
3438
35- checkDiagnostics ( transpileModuleResult . diagnostics , testSettings . expectedDiagnosticCodes ) ;
39+ checkDiagnostics ( transpileModuleResult . diagnostics , testSettings . expectedDiagnosticCodes , testSettings . expectedDiagnosticTexts ) ;
3640
3741 if ( testSettings . expectedOutput !== undefined ) {
3842 assert . equal ( transpileModuleResult . outputText , testSettings . expectedOutput ) ;
@@ -41,7 +45,7 @@ namespace ts {
4145 if ( canUseOldTranspile ) {
4246 const diagnostics : Diagnostic [ ] = [ ] ;
4347 const transpileResult = transpile ( input , transpileOptions . compilerOptions , transpileOptions . fileName , diagnostics , transpileOptions . moduleName ) ;
44- checkDiagnostics ( diagnostics , testSettings . expectedDiagnosticCodes ) ;
48+ checkDiagnostics ( diagnostics , testSettings . expectedDiagnosticCodes , testSettings . expectedDiagnosticTexts ) ;
4549 if ( testSettings . expectedOutput ) {
4650 assert . equal ( transpileResult , testSettings . expectedOutput ) ;
4751 }
@@ -313,7 +317,8 @@ var x = 0;`,
313317 it ( "Fails on bad value" , ( ) => {
314318 test ( `` , {
315319 options : { compilerOptions : { module : < ModuleKind > < any > { } } } ,
316- expectedDiagnosticCodes : [ 6046 ]
320+ expectedDiagnosticCodes : [ 6046 ] ,
321+ expectedDiagnosticTexts : [ "Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015'" ]
317322 } ) ;
318323 } ) ;
319324 } ) ;
0 commit comments