@@ -32,6 +32,40 @@ writeFileSync(fileUrlFixturePath, JSON.stringify({
3232describe ( 'CJS: --experimental-package-map' , { concurrency : ! process . env . TEST_PARALLEL } , ( ) => {
3333
3434 describe ( 'basic resolution' , ( ) => {
35+ it ( 'resolves dependencies from a parent directory URL' , ( ) => {
36+ const { status, stdout, stderr } = spawnSync ( process . execPath , [
37+ '--no-warnings' ,
38+ '--experimental-package-map' ,
39+ fixtures . path ( 'package-map/nested-project/map-dir/package-map-parent-url.json' ) ,
40+ '-e' ,
41+ `const dep = require('dep-a'); console.log(dep.default);` ,
42+ ] , {
43+ cwd : fixtures . path ( 'package-map/nested-project/src' ) ,
44+ encoding : 'utf8' ,
45+ } ) ;
46+
47+ assert . strictEqual ( stderr , '' ) ;
48+ assert . match ( stdout , / d e p - a - v a l u e / ) ;
49+ assert . strictEqual ( status , 0 , stderr ) ;
50+ } ) ;
51+
52+ it ( 'resolves packages with directory-form URLs' , ( ) => {
53+ const { status, stdout, stderr } = spawnSync ( process . execPath , [
54+ '--no-warnings' ,
55+ '--experimental-package-map' ,
56+ fixtures . path ( 'package-map/package-map-directory-urls.json' ) ,
57+ '-e' ,
58+ `const dep = require('dep-a'); console.log(dep.default);` ,
59+ ] , {
60+ cwd : fixtures . path ( 'package-map/root' ) ,
61+ encoding : 'utf8' ,
62+ } ) ;
63+
64+ assert . strictEqual ( stderr , '' ) ;
65+ assert . match ( stdout , / d e p - a - v a l u e / ) ;
66+ assert . strictEqual ( status , 0 , stderr ) ;
67+ } ) ;
68+
3569 it ( 'resolves require() through package map' , ( ) => {
3670 const { status, stdout, stderr } = spawnSync ( process . execPath , [
3771 '--no-warnings' ,
@@ -197,6 +231,23 @@ describe('CJS: --experimental-package-map', { concurrency: !process.env.TEST_PAR
197231 assert . match ( stderr , / p k g - b / ) ;
198232 assert . notStrictEqual ( status , 0 , stderr ) ;
199233 } ) ;
234+
235+ it ( 'throws for package URLs differing only by a trailing separator' , ( ) => {
236+ const { status, stderr } = spawnSync ( process . execPath , [
237+ '--no-warnings' ,
238+ '--experimental-package-map' ,
239+ fixtures . path ( 'package-map/package-map-duplicate-directory-path.json' ) ,
240+ '-e' ,
241+ `require('dep-a');` ,
242+ ] , {
243+ cwd : fixtures . path ( 'package-map/root' ) ,
244+ encoding : 'utf8' ,
245+ } ) ;
246+
247+ assert . match ( stderr , / E R R _ P A C K A G E _ M A P _ I N V A L I D / ) ;
248+ assert . match ( stderr , / d e p - a - d i r e c t o r y / ) ;
249+ assert . notStrictEqual ( status , 0 , stderr ) ;
250+ } ) ;
200251 } ) ;
201252
202253 describe ( 'conditional exports' , ( ) => {
0 commit comments