@@ -863,7 +863,7 @@ declare module '@custom/plugin' {
863
863
} ) ;
864
864
865
865
describe ( "unittests:: tsserver:: Project Errors with resolveJsonModule" , ( ) => {
866
- it ( "should not report incorrect error when json is root file found by tsconfig" , ( ) => {
866
+ function createSessionForTest ( { include } : { include : readonly string [ ] ; } ) {
867
867
const test : File = {
868
868
path : `${ projectRoot } /src/test.ts` ,
869
869
content : `import * as blabla from "./blabla.json"`
@@ -879,20 +879,74 @@ declare module '@custom/plugin' {
879
879
resolveJsonModule : true ,
880
880
composite : true
881
881
} ,
882
- include : [ "./src/*.ts" , "./src/*.json" ]
882
+ include
883
883
} )
884
884
} ;
885
885
886
886
const host = createServerHost ( [ test , blabla , libFile , tsconfig ] ) ;
887
- const session = createSession ( host ) ;
887
+ const session = createSession ( host , { canUseEvents : true } ) ;
888
888
openFilesForSession ( [ test ] , session ) ;
889
+ return { host, session, test, blabla, tsconfig } ;
890
+ }
891
+
892
+ it ( "should not report incorrect error when json is root file found by tsconfig" , ( ) => {
893
+ const { host, session, test } = createSessionForTest ( {
894
+ include : [ "./src/*.ts" , "./src/*.json" ]
895
+ } ) ;
889
896
verifyGetErrRequest ( {
890
897
session,
891
898
host,
892
899
expected : [
893
- { file : test , syntax : [ ] , semantic : [ ] , suggestion : [ ] }
900
+ {
901
+ file : test ,
902
+ syntax : [ ] ,
903
+ semantic : [ ] ,
904
+ suggestion : [
905
+ createDiagnostic (
906
+ { line : 1 , offset : 1 } ,
907
+ { line : 1 , offset : test . content . length + 1 } ,
908
+ Diagnostics . _0_is_declared_but_its_value_is_never_read ,
909
+ [ "blabla" ] ,
910
+ "suggestion" ,
911
+ /*reportsUnnecessary*/ true
912
+ )
913
+ ]
914
+ }
894
915
]
895
916
} ) ;
896
917
} ) ;
918
+
919
+ it ( "should report error when json is not root file found by tsconfig" , ( ) => {
920
+ const { host, session, test, blabla, tsconfig } = createSessionForTest ( {
921
+ include : [ "./src/*.ts" ]
922
+ } ) ;
923
+ const span = protocolTextSpanFromSubstring ( test . content , `"./blabla.json"` ) ;
924
+ verifyGetErrRequest ( {
925
+ session,
926
+ host,
927
+ expected : [ {
928
+ file : test ,
929
+ syntax : [ ] ,
930
+ semantic : [
931
+ createDiagnostic (
932
+ span . start ,
933
+ span . end ,
934
+ Diagnostics . File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern ,
935
+ [ blabla . path , tsconfig . path ]
936
+ )
937
+ ] ,
938
+ suggestion : [
939
+ createDiagnostic (
940
+ { line : 1 , offset : 1 } ,
941
+ { line : 1 , offset : test . content . length + 1 } ,
942
+ Diagnostics . _0_is_declared_but_its_value_is_never_read ,
943
+ [ "blabla" ] ,
944
+ "suggestion" ,
945
+ /*reportsUnnecessary*/ true
946
+ )
947
+ ]
948
+ } ]
949
+ } ) ;
950
+ } ) ;
897
951
} ) ;
898
952
}
0 commit comments