@@ -1314,6 +1314,13 @@ describe("ExportsFieldPlugin", () => {
1314
1314
const nodeFileSystem = new CachedInputFileSystem ( fs , 4000 ) ;
1315
1315
1316
1316
const resolver = ResolverFactory . createResolver ( {
1317
+ extensions : [ ".js" ] ,
1318
+ fileSystem : nodeFileSystem ,
1319
+ fullySpecified : true ,
1320
+ conditionNames : [ "webpack" ]
1321
+ } ) ;
1322
+
1323
+ const commonjsResolver = ResolverFactory . createResolver ( {
1317
1324
extensions : [ ".js" ] ,
1318
1325
fileSystem : nodeFileSystem ,
1319
1326
conditionNames : [ "webpack" ]
@@ -1354,7 +1361,7 @@ describe("ExportsFieldPlugin", () => {
1354
1361
) ;
1355
1362
} ) ;
1356
1363
1357
- it ( "resolve using exports field, not a browser field #2" , done => {
1364
+ it ( "resolve using exports field and a browser alias field #2" , done => {
1358
1365
const resolver = ResolverFactory . createResolver ( {
1359
1366
aliasFields : [ "browser" ] ,
1360
1367
extensions : [ ".js" ] ,
@@ -1371,7 +1378,7 @@ describe("ExportsFieldPlugin", () => {
1371
1378
if ( err ) return done ( err ) ;
1372
1379
if ( ! result ) throw new Error ( "No result" ) ;
1373
1380
result . should . equal (
1374
- path . resolve ( fixture2 , "node_modules/exports-field/lib/main .js" )
1381
+ path . resolve ( fixture2 , "node_modules/exports-field/lib/browser .js" )
1375
1382
) ;
1376
1383
done ( ) ;
1377
1384
}
@@ -1393,6 +1400,38 @@ describe("ExportsFieldPlugin", () => {
1393
1400
) ;
1394
1401
} ) ;
1395
1402
1403
+ it ( "throw error if extension not provided" , done => {
1404
+ resolver . resolve (
1405
+ { } ,
1406
+ fixture2 ,
1407
+ "exports-field/dist/main" ,
1408
+ { } ,
1409
+ ( err , result ) => {
1410
+ if ( ! err ) throw new Error ( `expect error, got ${ result } ` ) ;
1411
+ err . should . be . instanceof ( Error ) ;
1412
+ err . message . should . match ( / C a n ' t r e s o l v e / ) ;
1413
+ done ( ) ;
1414
+ }
1415
+ ) ;
1416
+ } ) ;
1417
+
1418
+ it ( "should resolve extension without fullySpecified" , done => {
1419
+ commonjsResolver . resolve (
1420
+ { } ,
1421
+ fixture2 ,
1422
+ "exports-field/dist/main" ,
1423
+ { } ,
1424
+ ( err , result ) => {
1425
+ if ( err ) return done ( err ) ;
1426
+ if ( ! result ) throw new Error ( "No result" ) ;
1427
+ result . should . equal (
1428
+ path . resolve ( fixture2 , "node_modules/exports-field/lib/lib2/main.js" )
1429
+ ) ;
1430
+ done ( ) ;
1431
+ }
1432
+ ) ;
1433
+ } ) ;
1434
+
1396
1435
it ( "resolver should respect condition names" , done => {
1397
1436
resolver . resolve (
1398
1437
{ } ,
@@ -1728,10 +1767,12 @@ describe("ExportsFieldPlugin", () => {
1728
1767
" existing directory .../node_modules/exports-field" ,
1729
1768
" using description file: .../node_modules/exports-field/package.json (relative path: .)" ,
1730
1769
" using exports field: ./lib/lib2/browser.js" ,
1731
- " .../node_modules/exports-field/lib/lib2/browser.js doesn't exist" ,
1770
+ " using description file: .../node_modules/exports-field/package.json (relative path: ./lib/lib2/browser.js)" ,
1771
+ " .../node_modules/exports-field/lib/lib2/browser.js doesn't exist" ,
1732
1772
" using exports field: ./lib/browser.js" ,
1733
- " existing file: .../node_modules/exports-field/lib/browser.js" ,
1734
- " reporting result .../node_modules/exports-field/lib/browser.js"
1773
+ " using description file: .../node_modules/exports-field/package.json (relative path: ./lib/browser.js)" ,
1774
+ " existing file: .../node_modules/exports-field/lib/browser.js" ,
1775
+ " reporting result .../node_modules/exports-field/lib/browser.js"
1735
1776
] ) ;
1736
1777
done ( ) ;
1737
1778
}
0 commit comments