@@ -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 useDefaultLibFile : 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+ // useDefaultLibFile 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 or undefine, use the build/local/lib.d.ts
49+ // otherwise use the lib.d.ts from the json object.
50+ useDefaultLibFile = undefined ;
4651 } ) ;
4752
4853 it ( 'can compile' , ( ) => {
@@ -51,32 +56,52 @@ module RWC {
5156
5257 var ioLog : IOLog = JSON . parse ( Harness . IO . readFile ( jsonPath ) ) ;
5358 currentDirectory = ioLog . currentDirectory ;
59+ useDefaultLibFile = ioLog . useDefaultLibFile ;
60+ if ( useDefaultLibFile === undefined ) {
61+ useDefaultLibFile = true ;
62+ }
5463 runWithIOLog ( ioLog , ( ) => {
5564 opts = ts . parseCommandLine ( ioLog . arguments ) ;
5665 assert . equal ( opts . errors . length , 0 ) ;
66+
67+ // To provide test coverage of output javascript file,
68+ // we will set noEmitOnError flag to be false.
69+ opts . options . noEmitOnError = false ;
5770 } ) ;
5871
5972 runWithIOLog ( ioLog , ( ) => {
6073 harnessCompiler . reset ( ) ;
74+
6175 // Load the files
6276 ts . forEach ( opts . fileNames , fileName => {
6377 inputFiles . push ( getHarnessCompilerInputUnit ( fileName ) ) ;
6478 } ) ;
6579
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-
80+ // Add files to compilation
7481 ts . forEach ( ioLog . filesRead , fileRead => {
82+ // Check if the file is already added into the set of input files.
7583 var resolvedPath = ts . normalizeSlashes ( ts . sys . resolvePath ( fileRead . path ) ) ;
7684 var inInputList = ts . forEach ( inputFiles , inputFile => inputFile . unitName === resolvedPath ) ;
77- if ( ! inInputList ) {
78- // Add the file to other files
79- otherFiles . push ( getHarnessCompilerInputUnit ( fileRead . path ) ) ;
85+
86+ if ( ! Harness . isLibraryFile ( fileRead . path ) ) {
87+ if ( ! inInputList ) {
88+ otherFiles . push ( getHarnessCompilerInputUnit ( fileRead . path ) ) ;
89+ }
90+ }
91+ else if ( ! opts . options . noLib && Harness . isLibraryFile ( fileRead . path ) ) {
92+ if ( ! inInputList ) {
93+ // If useDefaultLibFile is true, we will use built/local/lib.d.ts
94+ // instead of the provided lib.d.ts from json object.
95+ // Majority of RWC code will be using built/local/lib.d.ts instead of
96+ // lib.d.ts inside json file. However, some RWC cases will still use
97+ // their own version of lib.d.ts because they have customized lib.d.ts
98+ if ( useDefaultLibFile ) {
99+ inputFiles . push ( Harness . getDefaultLibraryFile ( ) ) ;
100+ }
101+ else {
102+ inputFiles . push ( getHarnessCompilerInputUnit ( fileRead . path ) ) ;
103+ }
104+ }
80105 }
81106 } ) ;
82107
@@ -115,9 +140,7 @@ module RWC {
115140
116141 it ( 'has the expected declaration file content' , ( ) => {
117142 Harness . Baseline . runBaseline ( 'has the expected declaration file content' , baseName + '.d.ts' , ( ) => {
118- if ( compilerResult . errors . length || ! compilerResult . declFilesCode . length ) {
119- return null ;
120- }
143+ if ( ! compilerResult . declFilesCode . length ) { return null ; }
121144 return Harness . Compiler . collateOutputs ( compilerResult . declFilesCode ) ;
122145 } , false , baselineOpts ) ;
123146 } ) ;
0 commit comments