@@ -1104,14 +1104,18 @@ import b = require("./moduleB");
1104
1104
} ) ;
1105
1105
1106
1106
describe ( "Type reference directive resolution: " , ( ) => {
1107
- function test ( typesRoot : string , typeDirective : string , primary : boolean , initialFile : File , targetFile : File , ...otherFiles : File [ ] ) {
1108
- const host = createModuleResolutionHost ( /* hasDirectoryExists*/ false , ...[ initialFile , targetFile ] . concat ( ...otherFiles ) ) ;
1109
- const result = resolveTypeReferenceDirective ( typeDirective , initialFile . name , { typeRoots : [ typesRoot ] } , host ) ;
1107
+ function testWorker ( hasDirectoryExists : boolean , typesRoot : string | undefined , typeDirective : string , primary : boolean , initialFile : File , targetFile : File , ...otherFiles : File [ ] ) {
1108
+ const host = createModuleResolutionHost ( hasDirectoryExists , ...[ initialFile , targetFile ] . concat ( ...otherFiles ) ) ;
1109
+ const result = resolveTypeReferenceDirective ( typeDirective , initialFile . name , typesRoot ? { typeRoots : [ typesRoot ] } : { } , host ) ;
1110
1110
assert ( result . resolvedTypeReferenceDirective ! . resolvedFileName !== undefined , "expected type directive to be resolved" ) ;
1111
1111
assert . equal ( result . resolvedTypeReferenceDirective ! . resolvedFileName , targetFile . name , "unexpected result of type reference resolution" ) ;
1112
1112
assert . equal ( result . resolvedTypeReferenceDirective ! . primary , primary , "unexpected 'primary' value" ) ;
1113
1113
}
1114
1114
1115
+ function test ( typesRoot : string , typeDirective : string , primary : boolean , initialFile : File , targetFile : File , ...otherFiles : File [ ] ) {
1116
+ testWorker ( /*hasDirectoryExists*/ false , typesRoot , typeDirective , primary , initialFile , targetFile , ...otherFiles ) ;
1117
+ }
1118
+
1115
1119
it ( "Can be resolved from primary location" , ( ) => {
1116
1120
{
1117
1121
const f1 = { name : "/root/src/app.ts" } ;
@@ -1194,7 +1198,7 @@ import b = require("./moduleB");
1194
1198
const names = map ( files , f => f . name ) ;
1195
1199
const sourceFiles = arrayToMap ( map ( files , f => createSourceFile ( f . name , f . content , ScriptTarget . ES2015 ) ) , f => f . fileName ) ;
1196
1200
const compilerHost : CompilerHost = {
1197
- fileExists : fileName => sourceFiles . has ( fileName ) ,
1201
+ fileExists : fileName => sourceFiles . has ( fileName ) ,
1198
1202
getSourceFile : fileName => sourceFiles . get ( fileName ) ,
1199
1203
getDefaultLibFileName : ( ) => "lib.d.ts" ,
1200
1204
writeFile : notImplemented ,
@@ -1219,7 +1223,7 @@ import b = require("./moduleB");
1219
1223
assert . equal ( diagnostics1 [ 0 ] . messageText , diagnostics2 [ 0 ] . messageText , "expected one diagnostic" ) ;
1220
1224
} ) ;
1221
1225
1222
- it ( "Modules in the same .d.ts file are preferred to external files" , ( ) => {
1226
+ it ( "Modules in the same .d.ts file are preferred to external files" , ( ) => {
1223
1227
const f = {
1224
1228
name : "/a/b/c/c/app.d.ts" ,
1225
1229
content : `
@@ -1233,7 +1237,7 @@ import b = require("./moduleB");
1233
1237
} ;
1234
1238
const file = createSourceFile ( f . name , f . content , ScriptTarget . ES2015 ) ;
1235
1239
const compilerHost : CompilerHost = {
1236
- fileExists : fileName => fileName === file . fileName ,
1240
+ fileExists : fileName => fileName === file . fileName ,
1237
1241
getSourceFile : fileName => fileName === file . fileName ? file : undefined ,
1238
1242
getDefaultLibFileName : ( ) => "lib.d.ts" ,
1239
1243
writeFile : notImplemented ,
@@ -1248,7 +1252,7 @@ import b = require("./moduleB");
1248
1252
createProgram ( [ f . name ] , { } , compilerHost ) ;
1249
1253
} ) ;
1250
1254
1251
- it ( "Modules in .ts file are not checked in the same file" , ( ) => {
1255
+ it ( "Modules in .ts file are not checked in the same file" , ( ) => {
1252
1256
const f = {
1253
1257
name : "/a/b/c/c/app.ts" ,
1254
1258
content : `
@@ -1262,7 +1266,7 @@ import b = require("./moduleB");
1262
1266
} ;
1263
1267
const file = createSourceFile ( f . name , f . content , ScriptTarget . ES2015 ) ;
1264
1268
const compilerHost : CompilerHost = {
1265
- fileExists : fileName => fileName === file . fileName ,
1269
+ fileExists : fileName => fileName === file . fileName ,
1266
1270
getSourceFile : fileName => fileName === file . fileName ? file : undefined ,
1267
1271
getDefaultLibFileName : ( ) => "lib.d.ts" ,
1268
1272
writeFile : notImplemented ,
@@ -1279,5 +1283,15 @@ import b = require("./moduleB");
1279
1283
} ;
1280
1284
createProgram ( [ f . name ] , { } , compilerHost ) ;
1281
1285
} ) ;
1286
+ describe ( "can be resolved when typeReferenceDirective is relative and in a sibling folder" , ( ) => {
1287
+ const initialFile = { name : "/root/src/background/app.ts" } ;
1288
+ const targetFile = { name : "/root/src/typedefs/filesystem.d.ts" } ;
1289
+ it ( "when host doesnt have directoryExists" , ( ) => {
1290
+ testWorker ( /*hasDirectoryExists*/ false , /*typesRoot*/ undefined , /*typeDirective*/ "../typedefs/filesystem" , /*primary*/ false , initialFile , targetFile ) ;
1291
+ } ) ;
1292
+ it ( "when host has directoryExists" , ( ) => {
1293
+ testWorker ( /*hasDirectoryExists*/ true , /*typesRoot*/ undefined , /*typeDirective*/ "../typedefs/filesystem" , /*primary*/ false , initialFile , targetFile ) ;
1294
+ } ) ;
1295
+ } ) ;
1282
1296
} ) ;
1283
1297
}
0 commit comments