@@ -592,51 +592,36 @@ namespace ts.projectSystem {
592
592
} ) ;
593
593
594
594
describe ( "tsserverProjectSystem emit with outFile or out setting" , ( ) => {
595
- function test ( opts : CompilerOptions , expectedUsesOutFile : boolean ) {
596
- const f1 = {
597
- path : "/a/a.ts" ,
598
- content : "let x = 1"
599
- } ;
600
- const f2 = {
601
- path : "/a/b.ts" ,
602
- content : "let y = 1"
603
- } ;
604
- const config = {
605
- path : "/a/tsconfig.json" ,
606
- content : JSON . stringify ( {
607
- compilerOptions : opts ,
608
- compileOnSave : true
609
- } )
610
- } ;
611
- const host = createServerHost ( [ f1 , f2 , config ] ) ;
612
- const session = createSession ( host ) ;
613
- session . executeCommand ( {
614
- seq : 1 ,
615
- type : "request" ,
616
- command : "open" ,
617
- arguments : { file : f1 . path }
618
- } as protocol . OpenRequest ) ;
619
- checkNumberOfProjects ( session . getProjectService ( ) , { configuredProjects : 1 } ) ;
620
- const { response } = session . executeCommand ( {
621
- seq : 2 ,
622
- type : "request" ,
623
- command : "compileOnSaveAffectedFileList" ,
624
- arguments : { file : f1 . path }
625
- } as protocol . CompileOnSaveAffectedFileListRequest ) ;
626
- assert . equal ( ( response as protocol . CompileOnSaveAffectedFileListSingleProject [ ] ) . length , 1 , "expected output for 1 project" ) ;
627
- assert . equal ( ( response as protocol . CompileOnSaveAffectedFileListSingleProject [ ] ) [ 0 ] . fileNames . length , 2 , "expected output for 1 project" ) ;
628
- assert . equal ( ( response as protocol . CompileOnSaveAffectedFileListSingleProject [ ] ) [ 0 ] . projectUsesOutFile , expectedUsesOutFile , "usesOutFile" ) ;
595
+ function test ( subScenario : string , opts : CompilerOptions ) {
596
+ it ( subScenario , ( ) => {
597
+ const f1 = {
598
+ path : "/a/a.ts" ,
599
+ content : "let x = 1"
600
+ } ;
601
+ const f2 = {
602
+ path : "/a/b.ts" ,
603
+ content : "let y = 1"
604
+ } ;
605
+ const config = {
606
+ path : "/a/tsconfig.json" ,
607
+ content : JSON . stringify ( {
608
+ compilerOptions : opts ,
609
+ compileOnSave : true
610
+ } )
611
+ } ;
612
+ const host = createServerHost ( [ f1 , f2 , config ] ) ;
613
+ const session = createSession ( host , { logger : createLoggerWithInMemoryLogs ( host ) } ) ;
614
+ openFilesForSession ( [ f1 ] , session ) ;
615
+ session . executeCommandSeq < protocol . CompileOnSaveAffectedFileListRequest > ( {
616
+ command : protocol . CommandTypes . CompileOnSaveAffectedFileList ,
617
+ arguments : { file : f1 . path }
618
+ } ) ;
619
+ baselineTsserverLogs ( "compileOnSave" , subScenario , session ) ;
620
+ } ) ;
629
621
}
630
-
631
- it ( "projectUsesOutFile should not be returned if not set" , ( ) => {
632
- test ( { } , /*expectedUsesOutFile*/ false ) ;
633
- } ) ;
634
- it ( "projectUsesOutFile should be true if outFile is set" , ( ) => {
635
- test ( { outFile : "/a/out.js" } , /*expectedUsesOutFile*/ true ) ;
636
- } ) ;
637
- it ( "projectUsesOutFile should be true if out is set" , ( ) => {
638
- test ( { out : "/a/out.js" } , /*expectedUsesOutFile*/ true ) ;
639
- } ) ;
622
+ test ( "compileOnSaveAffectedFileList projectUsesOutFile should not be returned if not set" , { } ) ;
623
+ test ( "compileOnSaveAffectedFileList projectUsesOutFile should be true if outFile is set" , { outFile : "/a/out.js" } ) ;
624
+ test ( "compileOnSaveAffectedFileList projectUsesOutFile should be true if out is set" , { out : "/a/out.js" } ) ;
640
625
} ) ;
641
626
} ) ;
642
627
@@ -991,36 +976,6 @@ function bar() {
991
976
} ) ;
992
977
993
978
describe ( "unittests:: tsserver:: compileOnSave:: CompileOnSaveAffectedFileListRequest with and without projectFileName in request" , ( ) => {
994
- const core : File = {
995
- path : `${ tscWatch . projectRoot } /core/core.ts` ,
996
- content : "let z = 10;"
997
- } ;
998
- const app1 : File = {
999
- path : `${ tscWatch . projectRoot } /app1/app.ts` ,
1000
- content : "let x = 10;"
1001
- } ;
1002
- const app2 : File = {
1003
- path : `${ tscWatch . projectRoot } /app2/app.ts` ,
1004
- content : "let y = 10;"
1005
- } ;
1006
- const app1Config : File = {
1007
- path : `${ tscWatch . projectRoot } /app1/tsconfig.json` ,
1008
- content : JSON . stringify ( {
1009
- files : [ "app.ts" , "../core/core.ts" ] ,
1010
- compilerOptions : { outFile : "build/output.js" } ,
1011
- compileOnSave : true
1012
- } )
1013
- } ;
1014
- const app2Config : File = {
1015
- path : `${ tscWatch . projectRoot } /app2/tsconfig.json` ,
1016
- content : JSON . stringify ( {
1017
- files : [ "app.ts" , "../core/core.ts" ] ,
1018
- compilerOptions : { outFile : "build/output.js" } ,
1019
- compileOnSave : true
1020
- } )
1021
- } ;
1022
- const files = [ libFile , core , app1 , app2 , app1Config , app2Config ] ;
1023
-
1024
979
function insertString ( session : TestSession , file : File ) {
1025
980
session . executeCommandSeq < protocol . ChangeRequest > ( {
1026
981
command : protocol . CommandTypes . Change ,
@@ -1035,53 +990,62 @@ function bar() {
1035
990
} ) ;
1036
991
}
1037
992
1038
- function getSession ( ) {
1039
- const host = createServerHost ( files ) ;
1040
- const session = createSession ( host ) ;
1041
- openFilesForSession ( [ app1 , app2 , core ] , session ) ;
1042
- const service = session . getProjectService ( ) ;
1043
- checkNumberOfProjects ( session . getProjectService ( ) , { configuredProjects : 2 } ) ;
1044
- const project1 = service . configuredProjects . get ( app1Config . path ) ! ;
1045
- const project2 = service . configuredProjects . get ( app2Config . path ) ! ;
1046
- checkProjectActualFiles ( project1 , [ libFile . path , app1 . path , core . path , app1Config . path ] ) ;
1047
- checkProjectActualFiles ( project2 , [ libFile . path , app2 . path , core . path , app2Config . path ] ) ;
1048
- insertString ( session , app1 ) ;
1049
- insertString ( session , app2 ) ;
1050
- assert . equal ( project1 . dirty , true ) ;
1051
- assert . equal ( project2 . dirty , true ) ;
1052
- return session ;
993
+ function logDirtyOfProjects ( session : TestSession ) {
994
+ session . logger . logs . push ( `Project1 is dirty: ${ session . getProjectService ( ) . configuredProjects . get ( `${ tscWatch . projectRoot } /app1/tsconfig.json` ) ! . dirty } ` ) ;
995
+ session . logger . logs . push ( `Project2 is dirty: ${ session . getProjectService ( ) . configuredProjects . get ( `${ tscWatch . projectRoot } /app2/tsconfig.json` ) ! . dirty } ` ) ;
1053
996
}
1054
997
1055
- it ( "when projectFile is specified" , ( ) => {
1056
- const session = getSession ( ) ;
1057
- const response = session . executeCommandSeq < protocol . CompileOnSaveAffectedFileListRequest > ( {
1058
- command : protocol . CommandTypes . CompileOnSaveAffectedFileList ,
1059
- arguments : {
1060
- file : core . path ,
1061
- projectFileName : app1Config . path
1062
- }
1063
- } ) . response ;
1064
- assert . deepEqual ( response , [
1065
- { projectFileName : app1Config . path , fileNames : [ core . path , app1 . path ] , projectUsesOutFile : true }
1066
- ] ) ;
1067
- assert . equal ( session . getProjectService ( ) . configuredProjects . get ( app1Config . path ) ! . dirty , false ) ;
1068
- assert . equal ( session . getProjectService ( ) . configuredProjects . get ( app2Config . path ) ! . dirty , true ) ;
998
+ function verify ( subScenario : string , commandArgs : protocol . FileRequestArgs ) {
999
+ it ( subScenario , ( ) => {
1000
+ const core : File = {
1001
+ path : `${ tscWatch . projectRoot } /core/core.ts` ,
1002
+ content : "let z = 10;"
1003
+ } ;
1004
+ const app1 : File = {
1005
+ path : `${ tscWatch . projectRoot } /app1/app.ts` ,
1006
+ content : "let x = 10;"
1007
+ } ;
1008
+ const app2 : File = {
1009
+ path : `${ tscWatch . projectRoot } /app2/app.ts` ,
1010
+ content : "let y = 10;"
1011
+ } ;
1012
+ const app1Config : File = {
1013
+ path : `${ tscWatch . projectRoot } /app1/tsconfig.json` ,
1014
+ content : JSON . stringify ( {
1015
+ files : [ "app.ts" , "../core/core.ts" ] ,
1016
+ compilerOptions : { outFile : "build/output.js" } ,
1017
+ compileOnSave : true
1018
+ } )
1019
+ } ;
1020
+ const app2Config : File = {
1021
+ path : `${ tscWatch . projectRoot } /app2/tsconfig.json` ,
1022
+ content : JSON . stringify ( {
1023
+ files : [ "app.ts" , "../core/core.ts" ] ,
1024
+ compilerOptions : { outFile : "build/output.js" } ,
1025
+ compileOnSave : true
1026
+ } )
1027
+ } ;
1028
+ const files = [ libFile , core , app1 , app2 , app1Config , app2Config ] ;
1029
+ const host = createServerHost ( files ) ;
1030
+ const session = createSession ( host , { logger : createLoggerWithInMemoryLogs ( host ) } ) ;
1031
+ openFilesForSession ( [ app1 , app2 , core ] , session ) ;
1032
+ insertString ( session , app1 ) ;
1033
+ insertString ( session , app2 ) ;
1034
+ logDirtyOfProjects ( session ) ;
1035
+ session . executeCommandSeq < protocol . CompileOnSaveAffectedFileListRequest > ( {
1036
+ command : protocol . CommandTypes . CompileOnSaveAffectedFileList ,
1037
+ arguments : commandArgs
1038
+ } ) ;
1039
+ logDirtyOfProjects ( session ) ;
1040
+ baselineTsserverLogs ( "compileOnSave" , subScenario , session ) ;
1041
+ } ) ;
1042
+ }
1043
+ verify ( "CompileOnSaveAffectedFileListRequest when projectFile is specified" , {
1044
+ file : `${ tscWatch . projectRoot } /core/core.ts` ,
1045
+ projectFileName : `${ tscWatch . projectRoot } /app1/tsconfig.json`
1069
1046
} ) ;
1070
-
1071
- it ( "when projectFile is not specified" , ( ) => {
1072
- const session = getSession ( ) ;
1073
- const response = session . executeCommandSeq < protocol . CompileOnSaveAffectedFileListRequest > ( {
1074
- command : protocol . CommandTypes . CompileOnSaveAffectedFileList ,
1075
- arguments : {
1076
- file : core . path
1077
- }
1078
- } ) . response ;
1079
- assert . deepEqual ( response , [
1080
- { projectFileName : app1Config . path , fileNames : [ core . path , app1 . path ] , projectUsesOutFile : true } ,
1081
- { projectFileName : app2Config . path , fileNames : [ core . path , app2 . path ] , projectUsesOutFile : true }
1082
- ] ) ;
1083
- assert . equal ( session . getProjectService ( ) . configuredProjects . get ( app1Config . path ) ! . dirty , false ) ;
1084
- assert . equal ( session . getProjectService ( ) . configuredProjects . get ( app2Config . path ) ! . dirty , false ) ;
1047
+ verify ( "CompileOnSaveAffectedFileListRequest when projectFile is not specified" , {
1048
+ file : `${ tscWatch . projectRoot } /core/core.ts` ,
1085
1049
} ) ;
1086
1050
} ) ;
1087
1051
}
0 commit comments