@@ -255,6 +255,14 @@ interface String { charAt: any; }
255255interface Array<T> {}`
256256 } ;
257257
258+ const moduleFile : TestFSWithWatch . File = {
259+ path : "/module.ts" ,
260+ content :
261+ `export function fn(res: any): any {
262+ return res;
263+ }`
264+ } ;
265+
258266 type WithSkipAndOnly < T extends any [ ] > = ( ( ...args : T ) => void ) & {
259267 skip : ( ...args : T ) => void ;
260268 only : ( ...args : T ) => void ;
@@ -269,7 +277,7 @@ interface Array<T> {}`
269277 }
270278 }
271279
272- function testConvertToAsyncFunction ( it : Mocha . PendingTestFunction , caption : string , text : string , baselineFolder : string , includeLib ?: boolean , expectFailure = false , onlyProvideAction = false ) {
280+ function testConvertToAsyncFunction ( it : Mocha . PendingTestFunction , caption : string , text : string , baselineFolder : string , includeLib ?: boolean , includeModule ?: boolean , expectFailure = false , onlyProvideAction = false ) {
273281 const t = extractTest ( text ) ;
274282 const selectionRange = t . ranges . get ( "selection" ) ! ;
275283 if ( ! selectionRange ) {
@@ -283,7 +291,7 @@ interface Array<T> {}`
283291
284292 function runBaseline ( extension : Extension ) {
285293 const path = "/a" + extension ;
286- const languageService = makeLanguageService ( { path, content : t . source } , includeLib ) ;
294+ const languageService = makeLanguageService ( { path, content : t . source } , includeLib , includeModule ) ;
287295 const program = languageService . getProgram ( ) ! ;
288296
289297 if ( hasSyntacticDiagnostics ( program ) ) {
@@ -338,17 +346,23 @@ interface Array<T> {}`
338346 const newText = textChanges . applyChanges ( sourceFile . text , changes [ 0 ] . textChanges ) ;
339347 data . push ( newText ) ;
340348
341- const diagProgram = makeLanguageService ( { path, content : newText } , includeLib ) . getProgram ( ) ! ;
349+ const diagProgram = makeLanguageService ( { path, content : newText } , includeLib , includeModule ) . getProgram ( ) ! ;
342350 assert . isFalse ( hasSyntacticDiagnostics ( diagProgram ) ) ;
343351 Harness . Baseline . runBaseline ( `${ baselineFolder } /${ caption } ${ extension } ` , data . join ( newLineCharacter ) ) ;
344352 }
345353
346- function makeLanguageService ( f : { path : string , content : string } , includeLib ?: boolean ) {
347-
348- const host = projectSystem . createServerHost ( includeLib ? [ f , libFile ] : [ f ] ) ; // libFile is expensive to parse repeatedly - only test when required
354+ function makeLanguageService ( file : TestFSWithWatch . File , includeLib ?: boolean , includeModule ?: boolean ) {
355+ const files = [ file ] ;
356+ if ( includeLib ) {
357+ files . push ( libFile ) ; // libFile is expensive to parse repeatedly - only test when required
358+ }
359+ if ( includeModule ) {
360+ files . push ( moduleFile ) ;
361+ }
362+ const host = projectSystem . createServerHost ( files ) ;
349363 const projectService = projectSystem . createProjectService ( host ) ;
350- projectService . openClientFile ( f . path ) ;
351- return projectService . inferredProjects [ 0 ] . getLanguageService ( ) ;
364+ projectService . openClientFile ( file . path ) ;
365+ return first ( projectService . inferredProjects ) . getLanguageService ( ) ;
352366 }
353367
354368 function hasSyntacticDiagnostics ( program : Program ) {
@@ -362,11 +376,15 @@ interface Array<T> {}`
362376 } ) ;
363377
364378 const _testConvertToAsyncFunctionFailed = createTestWrapper ( ( it , caption : string , text : string ) => {
365- testConvertToAsyncFunction ( it , caption , text , "convertToAsyncFunction" , /*includeLib*/ true , /*expectFailure*/ true ) ;
379+ testConvertToAsyncFunction ( it , caption , text , "convertToAsyncFunction" , /*includeLib*/ true , /*includeModule*/ false , /* expectFailure*/ true ) ;
366380 } ) ;
367381
368382 const _testConvertToAsyncFunctionFailedSuggestion = createTestWrapper ( ( it , caption : string , text : string ) => {
369- testConvertToAsyncFunction ( it , caption , text , "convertToAsyncFunction" , /*includeLib*/ true , /*expectFailure*/ true , /*onlyProvideAction*/ true ) ;
383+ testConvertToAsyncFunction ( it , caption , text , "convertToAsyncFunction" , /*includeLib*/ true , /*includeModule*/ false , /*expectFailure*/ true , /*onlyProvideAction*/ true ) ;
384+ } ) ;
385+
386+ const _testConvertToAsyncFunctionWithModule = createTestWrapper ( ( it , caption : string , text : string ) => {
387+ testConvertToAsyncFunction ( it , caption , text , "convertToAsyncFunction" , /*includeLib*/ true , /*includeModule*/ true ) ;
370388 } ) ;
371389
372390 describe ( "unittests:: services:: convertToAsyncFunction" , ( ) => {
@@ -1453,6 +1471,13 @@ const fn = (): Promise<(message: string) => void> =>
14531471function [#|f|]() {
14541472 return fn().then(res => res("test"));
14551473}
1474+ ` ) ;
1475+
1476+ _testConvertToAsyncFunctionWithModule ( "convertToAsyncFunction_importedFunction" , `
1477+ import { fn } from "./module";
1478+ function [#|f|]() {
1479+ return Promise.resolve(0).then(fn);
1480+ }
14561481` ) ;
14571482
14581483 } ) ;
0 commit comments