22/// <reference path="..\..\..\src\compiler\commandLineParser.ts" />
33
44namespace ts {
5- class MockParseConfigHost extends Utils . VirtualFileSystem implements ParseConfigHost {
6- constructor ( currentDirectory : string , ignoreCase : boolean , files : string [ ] ) {
7- super ( currentDirectory , ignoreCase ) ;
8- for ( const file of files ) {
9- this . addFile ( file ) ;
10- }
11- }
12-
13- readDirectory ( path : string , extensions : string [ ] , excludes : string [ ] , includes : string [ ] ) {
14- return matchFiles ( path , extensions , excludes , includes , this . useCaseSensitiveFileNames , this . currentDirectory , ( path : string ) => this . getAccessibleFileSystemEntries ( path ) ) ;
15- }
16-
17- getAccessibleFileSystemEntries ( path : string ) {
18- const entry = this . traversePath ( path ) ;
19- if ( entry && entry . isDirectory ( ) ) {
20- const directory = < Utils . VirtualDirectory > entry ;
21- return {
22- files : map ( directory . getFiles ( ) , f => f . name ) ,
23- directories : map ( directory . getDirectories ( ) , d => d . name )
24- } ;
25- }
26- return { files : [ ] , directories : [ ] } ;
27- }
28- }
29-
305 describe ( 'parseConfigFileTextToJson' , ( ) => {
316 function assertParseResult ( jsonText : string , expectedConfigObject : { config ?: any ; error ?: Diagnostic } ) {
327 let parsed = ts . parseConfigFileTextToJson ( "/apath/tsconfig.json" , jsonText ) ;
@@ -41,13 +16,14 @@ namespace ts {
4116
4217 function assertParseErrorWithExcludesKeyword ( jsonText : string ) {
4318 let parsed = ts . parseConfigFileTextToJson ( "/apath/tsconfig.json" , jsonText ) ;
44- let parsedCommand = ts . parseJsonConfigFileContent ( parsed , ts . sys , "tests/cases/unittests" ) ;
45- assert . isTrue ( undefined !== parsedCommand . errors ) ;
19+ let parsedCommand = ts . parseJsonConfigFileContent ( parsed . config , ts . sys , "tests/cases/unittests" ) ;
20+ assert . isTrue ( parsedCommand . errors && parsedCommand . errors . length === 1 &&
21+ parsedCommand . errors [ 0 ] . code === ts . Diagnostics . Unknown_option_excludes_Did_you_mean_exclude . code ) ;
4622 }
4723
4824 function assertParseFileList ( jsonText : string , configFileName : string , basePath : string , allFileList : string [ ] , expectedFileList : string [ ] ) {
4925 const json = JSON . parse ( jsonText ) ;
50- const host : ParseConfigHost = new MockParseConfigHost ( basePath , true , allFileList ) ;
26+ const host : ParseConfigHost = new Utils . MockParseConfigHost ( basePath , true , allFileList ) ;
5127 const parsed = ts . parseJsonConfigFileContent ( json , host , basePath , /*existingOptions*/ undefined , configFileName ) ;
5228 assert . isTrue ( arrayIsEqualTo ( parsed . fileNames . sort ( ) , expectedFileList . sort ( ) ) ) ;
5329 }
@@ -125,27 +101,27 @@ namespace ts {
125101 assertParseResult (
126102 `{
127103 "compilerOptions": {
128- "lib": "es5"
104+ "lib": [ "es5"]
129105 }
130106 }` , {
131- config : { compilerOptions : { lib : "es5" } }
107+ config : { compilerOptions : { lib : [ "es5" ] } }
132108 } ) ;
133109
134110 assertParseResult (
135111 `{
136112 "compilerOptions": {
137- "lib": "es5, es6"
113+ "lib": [ "es5", " es6"]
138114 }
139115 }` , {
140- config : { compilerOptions : { lib : "es5, es6" } }
116+ config : { compilerOptions : { lib : [ "es5" , " es6"] } }
141117 } ) ;
142118 } ) ;
143119
144120 it ( "returns error when tsconfig have excludes" , ( ) => {
145121 assertParseErrorWithExcludesKeyword (
146122 `{
147123 "compilerOptions": {
148- "lib": "es5"
124+ "lib": [ "es5"]
149125 },
150126 "excludes": [
151127 "foge.ts"
0 commit comments