@@ -869,4 +869,172 @@ namespace ts {
869
869
createProgram ( [ ] , { } ) ;
870
870
} ) ;
871
871
} ) ;
872
+
873
+ import TestSystem = ts . TestFSWithWatch . TestServerHost ;
874
+ type FileOrFolder = ts . TestFSWithWatch . FileOrFolder ;
875
+ import createTestSystem = ts . TestFSWithWatch . createWatchedSystem ;
876
+ import libFile = ts . TestFSWithWatch . libFile ;
877
+
878
+ describe ( "isProgramUptoDate should return true when there is no change in compiler options and" , ( ) => {
879
+ function verifyProgramIsUptoDate (
880
+ program : Program ,
881
+ newRootFileNames : string [ ] ,
882
+ newOptions : CompilerOptions
883
+ ) {
884
+ const actual = isProgramUptoDate (
885
+ program , newRootFileNames , newOptions ,
886
+ path => program . getSourceFileByPath ( path ) . version , /*fileExists*/ returnFalse ,
887
+ /*hasInvalidatedResolution*/ returnFalse ,
888
+ /*hasChangedAutomaticTypeDirectiveNames*/ returnFalse
889
+ ) ;
890
+ assert . isTrue ( actual ) ;
891
+ }
892
+
893
+ function duplicate ( options : CompilerOptions ) : CompilerOptions ;
894
+ function duplicate ( fileNames : string [ ] ) : string [ ] ;
895
+ function duplicate ( filesOrOptions : CompilerOptions | string [ ] ) {
896
+ return JSON . parse ( JSON . stringify ( filesOrOptions ) ) ;
897
+ }
898
+
899
+ function createWatchingSystemHost ( host : TestSystem ) {
900
+ return ts . createWatchingSystemHost ( /*pretty*/ undefined , host ) ;
901
+ }
902
+
903
+ function verifyProgramWithoutConfigFile ( watchingSystemHost : WatchingSystemHost , rootFiles : string [ ] , options : CompilerOptions ) {
904
+ const program = createWatchModeWithoutConfigFile ( rootFiles , options , watchingSystemHost ) ( ) ;
905
+ verifyProgramIsUptoDate ( program , duplicate ( rootFiles ) , duplicate ( options ) ) ;
906
+ }
907
+
908
+ function getConfigParseResult ( watchingSystemHost : WatchingSystemHost , configFileName : string ) {
909
+ return parseConfigFile ( configFileName , { } , watchingSystemHost . system , watchingSystemHost . reportDiagnostic , watchingSystemHost . reportWatchDiagnostic ) ;
910
+ }
911
+
912
+ function verifyProgramWithConfigFile ( watchingSystemHost : WatchingSystemHost , configFile : string ) {
913
+ const result = getConfigParseResult ( watchingSystemHost , configFile ) ;
914
+ const program = createWatchModeWithConfigFile ( result , { } , watchingSystemHost ) ( ) ;
915
+ const { fileNames, options } = getConfigParseResult ( watchingSystemHost , configFile ) ;
916
+ verifyProgramIsUptoDate ( program , fileNames , options ) ;
917
+ }
918
+
919
+ function verifyProgram ( files : FileOrFolder [ ] , rootFiles : string [ ] , options : CompilerOptions , configFile : string ) {
920
+ const watchingSystemHost = createWatchingSystemHost ( createTestSystem ( files ) ) ;
921
+ verifyProgramWithoutConfigFile ( watchingSystemHost , rootFiles , options ) ;
922
+ verifyProgramWithConfigFile ( watchingSystemHost , configFile ) ;
923
+ }
924
+
925
+ it ( "has empty options" , ( ) => {
926
+ const file1 : FileOrFolder = {
927
+ path : "/a/b/file1.ts" ,
928
+ content : "let x = 1"
929
+ } ;
930
+ const file2 : FileOrFolder = {
931
+ path : "/a/b/file2.ts" ,
932
+ content : "let y = 1"
933
+ } ;
934
+ const configFile : FileOrFolder = {
935
+ path : "/a/b/tsconfig.json" ,
936
+ content : "{}"
937
+ } ;
938
+ verifyProgram ( [ file1 , file2 , libFile , configFile ] , [ file1 . path , file2 . path ] , { } , configFile . path ) ;
939
+ } ) ;
940
+
941
+ it ( "has lib specified in the options" , ( ) => {
942
+ const compilerOptions : CompilerOptions = { lib : [ "es5" , "es2015.promise" ] } ;
943
+ const app : FileOrFolder = {
944
+ path : "/src/app.ts" ,
945
+ content : "var x: Promise<string>;"
946
+ } ;
947
+ const configFile : FileOrFolder = {
948
+ path : "/src/tsconfig.json" ,
949
+ content : JSON . stringify ( { compilerOptions } )
950
+ } ;
951
+ const es5Lib : FileOrFolder = {
952
+ path : "/compiler/lib.es5.d.ts" ,
953
+ content : "declare const eval: any"
954
+ } ;
955
+ const es2015Promise : FileOrFolder = {
956
+ path : "/compiler/lib.es2015.promise.d.ts" ,
957
+ content : "declare class Promise<T> {}"
958
+ } ;
959
+
960
+ verifyProgram ( [ app , configFile , es5Lib , es2015Promise ] , [ app . path ] , compilerOptions , configFile . path ) ;
961
+ } ) ;
962
+
963
+ it ( "has paths specified in the options" , ( ) => {
964
+ const compilerOptions : CompilerOptions = {
965
+ baseUrl : "." ,
966
+ paths : {
967
+ "*" : [
968
+ "packages/mail/data/*" ,
969
+ "packages/styles/*" ,
970
+ "*"
971
+ ]
972
+ }
973
+ } ;
974
+ const app : FileOrFolder = {
975
+ path : "/src/packages/framework/app.ts" ,
976
+ content : 'import classc from "module1/lib/file1";\
977
+ import classD from "module3/file3";\
978
+ let x = new classc();\
979
+ let y = new classD();'
980
+ } ;
981
+ const module1 : FileOrFolder = {
982
+ path : "/src/packages/mail/data/module1/lib/file1.ts" ,
983
+ content : 'import classc from "module2/file2";export default classc;' ,
984
+ } ;
985
+ const module2 : FileOrFolder = {
986
+ path : "/src/packages/mail/data/module1/lib/module2/file2.ts" ,
987
+ content : 'class classc { method2() { return "hello"; } }\nexport default classc' ,
988
+ } ;
989
+ const module3 : FileOrFolder = {
990
+ path : "/src/packages/styles/module3/file3.ts" ,
991
+ content : "class classD { method() { return 10; } }\nexport default classD;"
992
+ } ;
993
+ const configFile : FileOrFolder = {
994
+ path : "/src/tsconfig.json" ,
995
+ content : JSON . stringify ( { compilerOptions } )
996
+ } ;
997
+
998
+ verifyProgram ( [ app , module1 , module2 , module3 , libFile , configFile ] , [ app . path ] , compilerOptions , configFile . path ) ;
999
+ } ) ;
1000
+
1001
+ it ( "has include paths specified in tsconfig file" , ( ) => {
1002
+ const compilerOptions : CompilerOptions = {
1003
+ baseUrl : "." ,
1004
+ paths : {
1005
+ "*" : [
1006
+ "packages/mail/data/*" ,
1007
+ "packages/styles/*" ,
1008
+ "*"
1009
+ ]
1010
+ }
1011
+ } ;
1012
+ const app : FileOrFolder = {
1013
+ path : "/src/packages/framework/app.ts" ,
1014
+ content : 'import classc from "module1/lib/file1";\
1015
+ import classD from "module3/file3";\
1016
+ let x = new classc();\
1017
+ let y = new classD();'
1018
+ } ;
1019
+ const module1 : FileOrFolder = {
1020
+ path : "/src/packages/mail/data/module1/lib/file1.ts" ,
1021
+ content : 'import classc from "module2/file2";export default classc;' ,
1022
+ } ;
1023
+ const module2 : FileOrFolder = {
1024
+ path : "/src/packages/mail/data/module1/lib/module2/file2.ts" ,
1025
+ content : 'class classc { method2() { return "hello"; } }\nexport default classc' ,
1026
+ } ;
1027
+ const module3 : FileOrFolder = {
1028
+ path : "/src/packages/styles/module3/file3.ts" ,
1029
+ content : "class classD { method() { return 10; } }\nexport default classD;"
1030
+ } ;
1031
+ const configFile : FileOrFolder = {
1032
+ path : "/src/tsconfig.json" ,
1033
+ content : JSON . stringify ( { compilerOptions, include : [ "packages/**/ *.ts" ] } )
1034
+ } ;
1035
+
1036
+ const watchingSystemHost = createWatchingSystemHost ( createTestSystem ( [ app , module1 , module2 , module3 , libFile , configFile ] ) ) ;
1037
+ verifyProgramWithConfigFile ( watchingSystemHost , configFile . path ) ;
1038
+ } ) ;
1039
+ } ) ;
872
1040
}
0 commit comments