@@ -695,4 +695,99 @@ namespace ts.projectSystem {
695
695
} ) ;
696
696
} ) ;
697
697
698
+ describe ( "unittests:: tsserver:: compileOnSave:: CompileOnSaveAffectedFileListRequest with and without projectFileName in request" , ( ) => {
699
+ const projectRoot = "/user/username/projects/myproject" ;
700
+ const core : File = {
701
+ path : `${ projectRoot } /core/core.ts` ,
702
+ content : "let z = 10;"
703
+ } ;
704
+ const app1 : File = {
705
+ path : `${ projectRoot } /app1/app.ts` ,
706
+ content : "let x = 10;"
707
+ } ;
708
+ const app2 : File = {
709
+ path : `${ projectRoot } /app2/app.ts` ,
710
+ content : "let y = 10;"
711
+ } ;
712
+ const app1Config : File = {
713
+ path : `${ projectRoot } /app1/tsconfig.json` ,
714
+ content : JSON . stringify ( {
715
+ files : [ "app.ts" , "../core/core.ts" ] ,
716
+ compilerOptions : { outFile : "build/output.js" } ,
717
+ compileOnSave : true
718
+ } )
719
+ } ;
720
+ const app2Config : File = {
721
+ path : `${ projectRoot } /app2/tsconfig.json` ,
722
+ content : JSON . stringify ( {
723
+ files : [ "app.ts" , "../core/core.ts" ] ,
724
+ compilerOptions : { outFile : "build/output.js" } ,
725
+ compileOnSave : true
726
+ } )
727
+ } ;
728
+ const files = [ libFile , core , app1 , app2 , app1Config , app2Config ] ;
729
+
730
+ function insertString ( session : TestSession , file : File ) {
731
+ session . executeCommandSeq < protocol . ChangeRequest > ( {
732
+ command : protocol . CommandTypes . Change ,
733
+ arguments : {
734
+ file : file . path ,
735
+ line : 1 ,
736
+ offset : 1 ,
737
+ endLine : 1 ,
738
+ endOffset : 1 ,
739
+ insertString : "let k = 1"
740
+ }
741
+ } ) ;
742
+ }
743
+
744
+ function getSession ( ) {
745
+ const host = createServerHost ( files ) ;
746
+ const session = createSession ( host ) ;
747
+ openFilesForSession ( [ app1 , app2 , core ] , session ) ;
748
+ const service = session . getProjectService ( ) ;
749
+ checkNumberOfProjects ( session . getProjectService ( ) , { configuredProjects : 2 } ) ;
750
+ const project1 = service . configuredProjects . get ( app1Config . path ) ! ;
751
+ const project2 = service . configuredProjects . get ( app2Config . path ) ! ;
752
+ checkProjectActualFiles ( project1 , [ libFile . path , app1 . path , core . path , app1Config . path ] ) ;
753
+ checkProjectActualFiles ( project2 , [ libFile . path , app2 . path , core . path , app2Config . path ] ) ;
754
+ insertString ( session , app1 ) ;
755
+ insertString ( session , app2 ) ;
756
+ assert . equal ( project1 . dirty , true ) ;
757
+ assert . equal ( project2 . dirty , true ) ;
758
+ return session ;
759
+ }
760
+
761
+ it ( "when projectFile is specified" , ( ) => {
762
+ const session = getSession ( ) ;
763
+ const response = session . executeCommandSeq < protocol . CompileOnSaveAffectedFileListRequest > ( {
764
+ command : protocol . CommandTypes . CompileOnSaveAffectedFileList ,
765
+ arguments : {
766
+ file : core . path ,
767
+ projectFileName : app1Config . path
768
+ }
769
+ } ) . response ;
770
+ assert . deepEqual ( response , [
771
+ { projectFileName : app1Config . path , fileNames : [ core . path , app1 . path ] , projectUsesOutFile : true }
772
+ ] ) ;
773
+ assert . equal ( session . getProjectService ( ) . configuredProjects . get ( app1Config . path ) ! . dirty , false ) ;
774
+ assert . equal ( session . getProjectService ( ) . configuredProjects . get ( app2Config . path ) ! . dirty , true ) ;
775
+ } ) ;
776
+
777
+ it ( "when projectFile is not specified" , ( ) => {
778
+ const session = getSession ( ) ;
779
+ const response = session . executeCommandSeq < protocol . CompileOnSaveAffectedFileListRequest > ( {
780
+ command : protocol . CommandTypes . CompileOnSaveAffectedFileList ,
781
+ arguments : {
782
+ file : core . path
783
+ }
784
+ } ) . response ;
785
+ assert . deepEqual ( response , [
786
+ { projectFileName : app1Config . path , fileNames : [ core . path , app1 . path ] , projectUsesOutFile : true } ,
787
+ { projectFileName : app2Config . path , fileNames : [ core . path , app2 . path ] , projectUsesOutFile : true }
788
+ ] ) ;
789
+ assert . equal ( session . getProjectService ( ) . configuredProjects . get ( app1Config . path ) ! . dirty , false ) ;
790
+ assert . equal ( session . getProjectService ( ) . configuredProjects . get ( app2Config . path ) ! . dirty , false ) ;
791
+ } ) ;
792
+ } ) ;
698
793
}
0 commit comments