@@ -32,6 +32,7 @@ module RWC {
3232 } ;
3333 var baseName = / ( .* ) \/ ( .* ) .j s o n / . exec ( ts . normalizeSlashes ( jsonPath ) ) [ 2 ] ;
3434 var currentDirectory : string ;
35+ var useCustomLibraryFile : boolean ;
3536
3637 after ( ( ) => {
3738 // Mocha holds onto the closure environment of the describe callback even after the test is done.
@@ -43,6 +44,10 @@ module RWC {
4344 baselineOpts = undefined ;
4445 baseName = undefined ;
4546 currentDirectory = undefined ;
47+ // useCustomLibraryFile is a flag specified in the json object to indicate whether to use built/local/lib.d.ts
48+ // or to use lib.d.ts inside the json object. If the flag is true, use the lib.d.ts inside json file
49+ // otherwise use the lib.d.ts from built/local
50+ useCustomLibraryFile = undefined ;
4651 } ) ;
4752
4853 it ( 'can compile' , ( ) => {
@@ -51,34 +56,52 @@ module RWC {
5156
5257 var ioLog : IOLog = JSON . parse ( Harness . IO . readFile ( jsonPath ) ) ;
5358 currentDirectory = ioLog . currentDirectory ;
59+ useCustomLibraryFile = ioLog . useCustomLibraryFile ;
5460 runWithIOLog ( ioLog , ( ) => {
5561 opts = ts . parseCommandLine ( ioLog . arguments ) ;
5662 assert . equal ( opts . errors . length , 0 ) ;
63+
64+ // To provide test coverage of output javascript file,
65+ // we will set noEmitOnError flag to be false.
66+ opts . options . noEmitOnError = false ;
5767 } ) ;
5868
5969 runWithIOLog ( ioLog , ( ) => {
6070 harnessCompiler . reset ( ) ;
71+
6172 // Load the files
6273 ts . forEach ( opts . fileNames , fileName => {
6374 inputFiles . push ( getHarnessCompilerInputUnit ( fileName ) ) ;
6475 } ) ;
6576
66- if ( ! opts . options . noLib ) {
67- // Find the lib.d.ts file in the input file and add it to the input files list
68- var libFile = ts . forEach ( ioLog . filesRead , fileRead => Harness . isLibraryFile ( fileRead . path ) ? fileRead . path : undefined ) ;
69- if ( libFile ) {
70- inputFiles . push ( getHarnessCompilerInputUnit ( libFile ) ) ;
71- }
72- }
73-
74- ts . forEach ( ioLog . filesRead , fileRead => {
77+ // Add files to compilation
78+ for ( let fileRead of ioLog . filesRead ) {
79+ // Check if the file is already added into the set of input files.
7580 var resolvedPath = ts . normalizeSlashes ( ts . sys . resolvePath ( fileRead . path ) ) ;
76- var inInputList = ts . forEach ( inputFiles , inputFile => inputFile . unitName === resolvedPath ) ;
77- if ( ! inInputList ) {
78- // Add the file to other files
81+ var inInputList = ts . forEach ( inputFiles , inputFile => inputFile . unitName === resolvedPath ) ;
82+
83+ if ( ! Harness . isLibraryFile ( fileRead . path ) ) {
84+ if ( inInputList ) {
85+ continue ;
86+ }
7987 otherFiles . push ( getHarnessCompilerInputUnit ( fileRead . path ) ) ;
8088 }
81- } ) ;
89+ else if ( ! opts . options . noLib && Harness . isLibraryFile ( fileRead . path ) ) {
90+ if ( ! inInputList ) {
91+ // If useCustomLibraryFile is true, we will use lib.d.ts from json object
92+ // otherwise use the lib.d.ts from built/local
93+ // Majority of RWC code will be using built/local/lib.d.ts instead of
94+ // lib.d.ts inside json file. However, some RWC cases will still use
95+ // their own version of lib.d.ts because they have customized lib.d.ts
96+ if ( useCustomLibraryFile ) {
97+ inputFiles . push ( getHarnessCompilerInputUnit ( fileRead . path ) ) ;
98+ }
99+ else {
100+ inputFiles . push ( Harness . getDefaultLibraryFile ( ) ) ;
101+ }
102+ }
103+ }
104+ }
82105
83106 // do not use lib since we already read it in above
84107 opts . options . noLib = true ;
@@ -115,9 +138,10 @@ module RWC {
115138
116139 it ( 'has the expected declaration file content' , ( ) => {
117140 Harness . Baseline . runBaseline ( 'has the expected declaration file content' , baseName + '.d.ts' , ( ) => {
118- if ( compilerResult . errors . length || ! compilerResult . declFilesCode . length ) {
141+ if ( ! compilerResult . declFilesCode . length ) {
119142 return null ;
120143 }
144+
121145 return Harness . Compiler . collateOutputs ( compilerResult . declFilesCode ) ;
122146 } , false , baselineOpts ) ;
123147 } ) ;
0 commit comments