@@ -255,6 +255,14 @@ interface String { charAt: any; }
255
255
interface Array<T> {}`
256
256
} ;
257
257
258
+ const moduleFile : TestFSWithWatch . File = {
259
+ path : "/module.ts" ,
260
+ content :
261
+ `export function fn(res: any): any {
262
+ return res;
263
+ }`
264
+ } ;
265
+
258
266
type WithSkipAndOnly < T extends any [ ] > = ( ( ...args : T ) => void ) & {
259
267
skip : ( ...args : T ) => void ;
260
268
only : ( ...args : T ) => void ;
@@ -269,7 +277,7 @@ interface Array<T> {}`
269
277
}
270
278
}
271
279
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 ) {
273
281
const t = extractTest ( text ) ;
274
282
const selectionRange = t . ranges . get ( "selection" ) ! ;
275
283
if ( ! selectionRange ) {
@@ -283,7 +291,7 @@ interface Array<T> {}`
283
291
284
292
function runBaseline ( extension : Extension ) {
285
293
const path = "/a" + extension ;
286
- const languageService = makeLanguageService ( { path, content : t . source } , includeLib ) ;
294
+ const languageService = makeLanguageService ( { path, content : t . source } , includeLib , includeModule ) ;
287
295
const program = languageService . getProgram ( ) ! ;
288
296
289
297
if ( hasSyntacticDiagnostics ( program ) ) {
@@ -338,17 +346,23 @@ interface Array<T> {}`
338
346
const newText = textChanges . applyChanges ( sourceFile . text , changes [ 0 ] . textChanges ) ;
339
347
data . push ( newText ) ;
340
348
341
- const diagProgram = makeLanguageService ( { path, content : newText } , includeLib ) . getProgram ( ) ! ;
349
+ const diagProgram = makeLanguageService ( { path, content : newText } , includeLib , includeModule ) . getProgram ( ) ! ;
342
350
assert . isFalse ( hasSyntacticDiagnostics ( diagProgram ) ) ;
343
351
Harness . Baseline . runBaseline ( `${ baselineFolder } /${ caption } ${ extension } ` , data . join ( newLineCharacter ) ) ;
344
352
}
345
353
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 ) ;
349
363
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 ( ) ;
352
366
}
353
367
354
368
function hasSyntacticDiagnostics ( program : Program ) {
@@ -362,11 +376,15 @@ interface Array<T> {}`
362
376
} ) ;
363
377
364
378
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 ) ;
366
380
} ) ;
367
381
368
382
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 ) ;
370
388
} ) ;
371
389
372
390
describe ( "unittests:: services:: convertToAsyncFunction" , ( ) => {
@@ -1559,6 +1577,13 @@ const fn = (): Promise<(message: string) => void> =>
1559
1577
function [#|f|]() {
1560
1578
return fn().then(res => res("test"));
1561
1579
}
1580
+ ` ) ;
1581
+
1582
+ _testConvertToAsyncFunctionWithModule ( "convertToAsyncFunction_importedFunction" , `
1583
+ import { fn } from "./module";
1584
+ function [#|f|]() {
1585
+ return Promise.resolve(0).then(fn);
1586
+ }
1562
1587
` ) ;
1563
1588
1564
1589
} ) ;
0 commit comments