@@ -923,6 +923,116 @@ declare var console: {
923
923
const service = createProjectService ( host ) ;
924
924
service . openClientFile ( file . path ) ;
925
925
} ) ;
926
+
927
+ describe ( "when creating new file" , ( ) => {
928
+ const foo : File = {
929
+ path : `${ tscWatch . projectRoot } /src/foo.ts` ,
930
+ content : "export function foo() { }"
931
+ } ;
932
+ const bar : File = {
933
+ path : `${ tscWatch . projectRoot } /src/bar.ts` ,
934
+ content : "export function bar() { }"
935
+ } ;
936
+ const config : File = {
937
+ path : `${ tscWatch . projectRoot } /tsconfig.json` ,
938
+ content : JSON . stringify ( {
939
+ include : [ "./src" ]
940
+ } )
941
+ } ;
942
+ const fooBar : File = {
943
+ path : `${ tscWatch . projectRoot } /src/fooBar.ts` ,
944
+ content : "export function fooBar() { }"
945
+ } ;
946
+ function verifySessionWorker ( { openFileBeforeCreating, checkProjectBeforeError, checkProjectAfterError, } : VerifySession , errorOnNewFileBeforeOldFile : boolean ) {
947
+ const host = createServerHost ( [ foo , bar , config , libFile ] ) ;
948
+ const session = createSession ( host , {
949
+ //logger: createLoggerWritingToConsole(),
950
+ canUseEvents : true
951
+ } ) ;
952
+ session . executeCommandSeq < protocol . OpenRequest > ( {
953
+ command : protocol . CommandTypes . Open ,
954
+ arguments : {
955
+ file : foo . path ,
956
+ fileContent : foo . content ,
957
+ projectRootPath : tscWatch . projectRoot
958
+ }
959
+ } ) ;
960
+ if ( ! openFileBeforeCreating ) {
961
+ host . writeFile ( fooBar . path , fooBar . content ) ;
962
+ }
963
+ session . executeCommandSeq < protocol . OpenRequest > ( {
964
+ command : protocol . CommandTypes . Open ,
965
+ arguments : {
966
+ file : fooBar . path ,
967
+ fileContent : fooBar . content ,
968
+ projectRootPath : tscWatch . projectRoot
969
+ }
970
+ } ) ;
971
+ if ( openFileBeforeCreating ) {
972
+ host . writeFile ( fooBar . path , fooBar . content ) ;
973
+ }
974
+ const service = session . getProjectService ( ) ;
975
+ checkProjectBeforeError ( service ) ;
976
+ verifyGetErrRequest ( {
977
+ session,
978
+ host,
979
+ expected : errorOnNewFileBeforeOldFile ?
980
+ [
981
+ { file : fooBar , syntax : [ ] , semantic : [ ] , suggestion : [ ] } ,
982
+ { file : foo , syntax : [ ] , semantic : [ ] , suggestion : [ ] } ,
983
+ ] :
984
+ [
985
+ { file : foo , syntax : [ ] , semantic : [ ] , suggestion : [ ] } ,
986
+ { file : fooBar , syntax : [ ] , semantic : [ ] , suggestion : [ ] } ,
987
+ ] ,
988
+ existingTimeouts : 2
989
+ } ) ;
990
+ checkProjectAfterError ( service ) ;
991
+ }
992
+ interface VerifySession {
993
+ openFileBeforeCreating : boolean ;
994
+ checkProjectBeforeError : ( service : server . ProjectService ) => void ;
995
+ checkProjectAfterError : ( service : server . ProjectService ) => void ;
996
+ }
997
+ function verifySession ( input : VerifySession ) {
998
+ it ( "when error on new file are asked before old one" , ( ) => {
999
+ verifySessionWorker ( input , /*errorOnNewFileBeforeOldFile*/ true ) ;
1000
+ } ) ;
1001
+
1002
+ it ( "when error on new file are asked after old one" , ( ) => {
1003
+ verifySessionWorker ( input , /*errorOnNewFileBeforeOldFile*/ false ) ;
1004
+ } ) ;
1005
+ }
1006
+ describe ( "when new file creation directory watcher is invoked before file is opened in editor" , ( ) => {
1007
+ verifySession ( {
1008
+ openFileBeforeCreating : false ,
1009
+ checkProjectBeforeError : service => {
1010
+ checkNumberOfProjects ( service , { configuredProjects : 1 } ) ;
1011
+ checkProjectActualFiles ( service . configuredProjects . get ( config . path ) ! , [ foo . path , bar . path , fooBar . path , libFile . path , config . path ] ) ;
1012
+ } ,
1013
+ checkProjectAfterError : service => {
1014
+ checkNumberOfProjects ( service , { configuredProjects : 1 } ) ;
1015
+ checkProjectActualFiles ( service . configuredProjects . get ( config . path ) ! , [ foo . path , bar . path , fooBar . path , libFile . path , config . path ] ) ;
1016
+ }
1017
+ } ) ;
1018
+ } ) ;
1019
+
1020
+ describe ( "when new file creation directory watcher is invoked after file is opened in editor" , ( ) => {
1021
+ verifySession ( {
1022
+ openFileBeforeCreating : true ,
1023
+ checkProjectBeforeError : service => {
1024
+ checkNumberOfProjects ( service , { configuredProjects : 1 , inferredProjects : 1 } ) ;
1025
+ checkProjectActualFiles ( service . configuredProjects . get ( config . path ) ! , [ foo . path , bar . path , libFile . path , config . path ] ) ;
1026
+ checkProjectActualFiles ( service . inferredProjects [ 0 ] , [ fooBar . path , libFile . path ] ) ;
1027
+ } ,
1028
+ checkProjectAfterError : service => {
1029
+ checkNumberOfProjects ( service , { configuredProjects : 1 , inferredProjects : 1 } ) ;
1030
+ checkProjectActualFiles ( service . configuredProjects . get ( config . path ) ! , [ foo . path , bar . path , fooBar . path , libFile . path , config . path ] ) ;
1031
+ checkProjectActualFiles ( service . inferredProjects [ 0 ] , [ fooBar . path , libFile . path ] ) ;
1032
+ }
1033
+ } ) ;
1034
+ } ) ;
1035
+ } ) ;
926
1036
} ) ;
927
1037
928
1038
describe ( "unittests:: tsserver:: ConfiguredProjects:: non-existing directories listed in config file input array" , ( ) => {
0 commit comments