11namespace ts {
2- describe ( "showTSConfig " , ( ) => {
3- function showTSConfigCorrectly ( name : string , commandLinesArgs : string [ ] ) {
2+ describe ( "showConfig " , ( ) => {
3+ function showTSConfigCorrectly ( name : string , commandLinesArgs : string [ ] , configJson ?: object ) {
44 describe ( name , ( ) => {
5- const commandLine = parseCommandLine ( commandLinesArgs ) ;
6- const initResult = convertToTSConfig ( commandLine , `/${ name } /tsconfig.json` , { getCurrentDirectory ( ) { return `/${ name } ` ; } , useCaseSensitiveFileNames : true } ) ;
7- const outputFileName = `showConfig/${ name . replace ( / [ ^ a - z 0 - 9 \- . ] / ig, "" ) } /tsconfig.json` ;
5+ const outputFileName = `showConfig/${ name . replace ( / [ ^ a - z 0 - 9 \- . / ] / ig, "" ) } /tsconfig.json` ;
86
97 it ( `Correct output for ${ outputFileName } ` , ( ) => {
8+ const cwd = `/${ name } ` ;
9+ const configPath = combinePaths ( cwd , "tsconfig.json" ) ;
10+ const configContents = configJson ? JSON . stringify ( configJson ) : undefined ;
11+ const configParseHost : ParseConfigFileHost = {
12+ fileExists : path =>
13+ comparePaths ( getNormalizedAbsolutePath ( path , cwd ) , configPath ) === Comparison . EqualTo ? true : false ,
14+ getCurrentDirectory ( ) { return cwd ; } ,
15+ useCaseSensitiveFileNames : true ,
16+ onUnRecoverableConfigFileDiagnostic : d => {
17+ throw new Error ( flattenDiagnosticMessageText ( d . messageText , "\n" ) ) ;
18+ } ,
19+ readDirectory ( ) { return [ ] ; } ,
20+ readFile : path =>
21+ comparePaths ( getNormalizedAbsolutePath ( path , cwd ) , configPath ) === Comparison . EqualTo ? configContents : undefined ,
22+ } ;
23+ let commandLine = parseCommandLine ( commandLinesArgs ) ;
24+ if ( commandLine . options . project ) {
25+ const result = getParsedCommandLineOfConfigFile ( commandLine . options . project , commandLine . options , configParseHost ) ;
26+ if ( result ) {
27+ commandLine = result ;
28+ }
29+ }
30+ const initResult = convertToTSConfig ( commandLine , configPath , configParseHost ) ;
31+
1032 // tslint:disable-next-line:no-null-keyword
1133 Harness . Baseline . runBaseline ( outputFileName , JSON . stringify ( initResult , null , 4 ) + "\n" ) ;
1234 } ) ;
@@ -30,5 +52,100 @@ namespace ts {
3052 showTSConfigCorrectly ( "Show TSConfig with incorrect compiler option value" , [ "--showConfig" , "--lib" , "nonExistLib,es5,es2015.promise" ] ) ;
3153
3254 showTSConfigCorrectly ( "Show TSConfig with advanced options" , [ "--showConfig" , "--declaration" , "--declarationDir" , "lib" , "--skipLibCheck" , "--noErrorTruncation" ] ) ;
55+
56+ // Regression test for https://github.com/Microsoft/TypeScript/issues/28836
57+ showTSConfigCorrectly ( "Show TSConfig with paths and more" , [ "-p" , "tsconfig.json" ] , {
58+ compilerOptions : {
59+ allowJs : true ,
60+ outDir : "./lib" ,
61+ esModuleInterop : true ,
62+ module : "commonjs" ,
63+ moduleResolution : "node" ,
64+ target : "ES2017" ,
65+ sourceMap : true ,
66+ baseUrl : "." ,
67+ paths : {
68+ "@root/*" : [ "./*" ] ,
69+ "@configs/*" : [ "src/configs/*" ] ,
70+ "@common/*" : [ "src/common/*" ] ,
71+ "*" : [
72+ "node_modules/*" ,
73+ "src/types/*"
74+ ]
75+ } ,
76+ experimentalDecorators : true ,
77+ emitDecoratorMetadata : true ,
78+ resolveJsonModule : true
79+ } ,
80+ include : [
81+ "./src/**/*"
82+ ]
83+ } ) ;
84+
85+ // Bulk validation of all option declarations
86+ for ( const option of optionDeclarations ) {
87+ if ( option . name === "project" ) continue ;
88+ let configObject : object | undefined ;
89+ let args : string [ ] ;
90+ switch ( option . type ) {
91+ case "boolean" : {
92+ if ( option . isTSConfigOnly ) {
93+ args = [ "-p" , "tsconfig.json" ] ;
94+ configObject = { compilerOptions : { [ option . name ] : true } } ;
95+ }
96+ else {
97+ args = [ `--${ option . name } ` ] ;
98+ }
99+ break ;
100+ }
101+ case "list" : {
102+ if ( option . isTSConfigOnly ) {
103+ args = [ "-p" , "tsconfig.json" ] ;
104+ configObject = { compilerOptions : { [ option . name ] : [ ] } } ;
105+ }
106+ else {
107+ args = [ `--${ option . name } ` ] ;
108+ }
109+ break ;
110+ }
111+ case "string" : {
112+ if ( option . isTSConfigOnly ) {
113+ args = [ "-p" , "tsconfig.json" ] ;
114+ configObject = { compilerOptions : { [ option . name ] : "someString" } } ;
115+ }
116+ else {
117+ args = [ `--${ option . name } ` , "someString" ] ;
118+ }
119+ break ;
120+ }
121+ case "number" : {
122+ if ( option . isTSConfigOnly ) {
123+ args = [ "-p" , "tsconfig.json" ] ;
124+ configObject = { compilerOptions : { [ option . name ] : 0 } } ;
125+ }
126+ else {
127+ args = [ `--${ option . name } ` , "0" ] ;
128+ }
129+ break ;
130+ }
131+ case "object" : {
132+ args = [ "-p" , "tsconfig.json" ] ;
133+ configObject = { compilerOptions : { [ option . name ] : { } } } ;
134+ break ;
135+ }
136+ default : {
137+ const val = option . type . keys ( ) . next ( ) . value ;
138+ if ( option . isTSConfigOnly ) {
139+ args = [ "-p" , "tsconfig.json" ] ;
140+ configObject = { compilerOptions : { [ option . name ] : val } } ;
141+ }
142+ else {
143+ args = [ `--${ option . name } ` , val ] ;
144+ }
145+ break ;
146+ }
147+ }
148+ showTSConfigCorrectly ( `Shows tsconfig for single option/${ option . name } ` , args , configObject ) ;
149+ }
33150 } ) ;
34- }
151+ }
0 commit comments