@@ -1639,7 +1639,7 @@ Actual: ${stringify(fullActual)}`);
1639
1639
} ) ;
1640
1640
}
1641
1641
1642
- public baselineGetEmitOutput ( insertResultsIntoVfs ?: boolean ) {
1642
+ private getEmitFiles ( ) : ReadonlyArray < FourSlashFile > {
1643
1643
// Find file to be emitted
1644
1644
const emitFiles : FourSlashFile [ ] = [ ] ; // List of FourSlashFile that has emitThisFile flag on
1645
1645
@@ -1656,12 +1656,31 @@ Actual: ${stringify(fullActual)}`);
1656
1656
this . raiseError ( "No emitThisFile is specified in the test file" ) ;
1657
1657
}
1658
1658
1659
+ return emitFiles ;
1660
+ }
1661
+
1662
+ public verifyGetEmitOutput ( expectedOutputFiles : ReadonlyArray < string > ) : void {
1663
+ const outputFiles = ts . flatMap ( this . getEmitFiles ( ) , e => this . languageService . getEmitOutput ( e . fileName ) . outputFiles ) ;
1664
+
1665
+ assert . deepEqual ( outputFiles . map ( f => f . name ) , expectedOutputFiles ) ;
1666
+
1667
+ for ( const { name, text } of outputFiles ) {
1668
+ const fromTestFile = this . getFileContent ( name ) ;
1669
+ if ( fromTestFile !== text ) {
1670
+ this . raiseError ( "Emit output is not as expected: " + showTextDiff ( fromTestFile , text ) ) ;
1671
+ }
1672
+ }
1673
+ }
1674
+
1675
+ public baselineGetEmitOutput ( insertResultsIntoVfs ?: boolean ) {
1676
+ ts . Debug . assert ( this . testType !== FourSlashTestType . Server , "Use verifyGetEmitOutput -- insertResultIntoVfs doesn't work with server" ) ;
1677
+
1659
1678
Harness . Baseline . runBaseline (
1660
- this . testData . globalOptions [ MetadataOptionNames . baselineFile ] ,
1679
+ ts . Debug . assertDefined ( this . testData . globalOptions [ MetadataOptionNames . baselineFile ] ) ,
1661
1680
( ) => {
1662
1681
let resultString = "" ;
1663
1682
// Loop through all the emittedFiles and emit them one by one
1664
- emitFiles . forEach ( emitFile => {
1683
+ for ( const emitFile of this . getEmitFiles ( ) ) {
1665
1684
const emitOutput = this . languageService . getEmitOutput ( emitFile . fileName ) ;
1666
1685
// Print emitOutputStatus in readable format
1667
1686
resultString += "EmitSkipped: " + emitOutput . emitSkipped + Harness . IO . newLine ( ) ;
@@ -1687,13 +1706,13 @@ Actual: ${stringify(fullActual)}`);
1687
1706
1688
1707
for ( const outputFile of emitOutput . outputFiles ) {
1689
1708
const fileName = "FileName : " + outputFile . name + Harness . IO . newLine ( ) ;
1690
- resultString = resultString + fileName + outputFile . text ;
1709
+ resultString = resultString + Harness . IO . newLine ( ) + fileName + outputFile . text ;
1691
1710
if ( insertResultsIntoVfs ) {
1692
1711
this . languageServiceAdapterHost . addScript ( ts . getNormalizedAbsolutePath ( outputFile . name , "/" ) , outputFile . text , /*isRootFile*/ true ) ;
1693
1712
}
1694
1713
}
1695
1714
resultString += Harness . IO . newLine ( ) ;
1696
- } ) ;
1715
+ }
1697
1716
1698
1717
return resultString ;
1699
1718
} ) ;
@@ -3567,8 +3586,13 @@ ${code}
3567
3586
3568
3587
function getNonFileNameOptionInObject ( optionObject : { [ s : string ] : string } ) : string | undefined {
3569
3588
for ( const option in optionObject ) {
3570
- if ( option !== MetadataOptionNames . fileName ) {
3571
- return option ;
3589
+ switch ( option ) {
3590
+ case MetadataOptionNames . fileName :
3591
+ case MetadataOptionNames . baselineFile :
3592
+ case MetadataOptionNames . emitThisFile :
3593
+ break ;
3594
+ default :
3595
+ return option ;
3572
3596
}
3573
3597
}
3574
3598
return undefined ;
@@ -4278,6 +4302,10 @@ namespace FourSlashInterface {
4278
4302
this . state . baselineCurrentFileNameOrDottedNameSpans ( ) ;
4279
4303
}
4280
4304
4305
+ public getEmitOutput ( expectedOutputFiles : ReadonlyArray < string > ) : void {
4306
+ this . state . verifyGetEmitOutput ( expectedOutputFiles ) ;
4307
+ }
4308
+
4281
4309
public baselineGetEmitOutput ( insertResultsIntoVfs ?: boolean ) {
4282
4310
this . state . baselineGetEmitOutput ( insertResultsIntoVfs ) ;
4283
4311
}
0 commit comments