@@ -15,10 +15,14 @@ setTypescriptModule(ts);
1515} ;
1616
1717const defaultConfig = { fileNames : [ ] , errors : [ ] , options : { } } ;
18+ const defaultFilter = ( ) => true ;
1819
1920const unaryFunc = "const unary = (x: string): string => x.reverse()" ;
2021const unaryFuncSnap = { text : unaryFunc } ;
2122
23+ const binaryFunc = "const binary = (a: number, b: number): number => a - b" ;
24+ const binaryFuncSnap = { text : binaryFunc } ;
25+
2226// host.ts uses `/` normalized path, as does TS itself (https://github.com/microsoft/TypeScript/blob/7f022c58fb8b7253f23c49f0d9eee6fde82b477b/src/compiler/path.ts#L4)
2327const local = ( x : string ) => normalize ( path . resolve ( __dirname , x ) ) ;
2428const testDir = local ( "__temp/host" ) ;
@@ -37,14 +41,18 @@ test("LanguageServiceHost", async () => {
3741 const testOpts = { test : "this is a test" } ;
3842 const config = { ...defaultConfig , options : testOpts } ;
3943 const transformers = [ ( ) => ( { } ) ] ;
40- const host = new LanguageServiceHost ( config , transformers , testDir ) ;
44+ const host = new LanguageServiceHost ( config , transformers , testDir , defaultFilter ) ;
4145
4246 // test core snapshot functionality
4347 expect ( host . getScriptSnapshot ( testFile ) ) . toEqual ( unaryFuncSnap ) ;
4448 expect ( host . getScriptVersion ( testFile ) ) . toEqual ( "1" ) ;
4549
46- expect ( host . setSnapshot ( testFile , unaryFunc ) ) . toEqual ( unaryFuncSnap ) ; // version 2
50+ expect ( host . setSnapshot ( testFile , unaryFunc ) ) . toEqual ( unaryFuncSnap ) ; // unchanged
4751 expect ( host . getScriptSnapshot ( testFile ) ) . toEqual ( unaryFuncSnap ) ; // get from dict
52+ expect ( host . getScriptVersion ( testFile ) ) . toEqual ( "1" ) ;
53+
54+ expect ( host . setSnapshot ( testFile , binaryFunc ) ) . toEqual ( binaryFuncSnap ) ; // version 2
55+ expect ( host . getScriptSnapshot ( testFile ) ) . toEqual ( binaryFuncSnap ) ;
4856 expect ( host . getScriptVersion ( testFile ) ) . toEqual ( "2" ) ;
4957
5058 expect ( host . getScriptSnapshot ( nonExistent ) ) . toBeFalsy ( ) ;
@@ -89,7 +97,7 @@ test("LanguageServiceHost - getCustomTransformers", () => {
8997 after : ( ) => "testAfter" ,
9098 afterDeclarations : ( ) => "testAfterDeclarations" ,
9199 } ) ] ;
92- const host = new LanguageServiceHost ( config , transformers as any , testDir ) ;
100+ const host = new LanguageServiceHost ( config , transformers as any , testDir , defaultFilter ) ;
93101
94102 host . setLanguageService ( true as any ) ;
95103 const customTransformers = host . getCustomTransformers ( ) ;
@@ -107,13 +115,13 @@ test("LanguageServiceHost - getCustomTransformers -- undefined cases", () => {
107115 const config = { ...defaultConfig } ;
108116
109117 // no LS and no transformers cases
110- let host = new LanguageServiceHost ( config , undefined as any , testDir ) ;
118+ let host = new LanguageServiceHost ( config , undefined as any , testDir , defaultFilter ) ;
111119 expect ( host . getCustomTransformers ( ) ) . toBeFalsy ( ) ; // no LS
112120 host . setLanguageService ( true as any ) ;
113121 expect ( host . getCustomTransformers ( ) ) . toBeFalsy ( ) ; // no transformers
114122
115123 // empty transformers case
116- host = new LanguageServiceHost ( config , [ ] , testDir ) ;
124+ host = new LanguageServiceHost ( config , [ ] , testDir , defaultFilter ) ;
117125 host . setLanguageService ( true as any ) ;
118126 expect ( host . getCustomTransformers ( ) ) . toBeFalsy ( ) ; // empty transformers
119127} ) ;
0 commit comments