Skip to content

Commit 14d9ea1

Browse files
committed
Add tests with subpath mapped to null
1 parent 51ef520 commit 14d9ea1

File tree

6 files changed

+35
-4
lines changed

6 files changed

+35
-4
lines changed

test/es-module/test-esm-exports.mjs

+8
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ import fromInside from '../fixtures/node_modules/pkgexports/lib/hole.js';
4545
['pkgexports/a//dir1/dir1', { default: 'main' }],
4646
// double slash target
4747
['pkgexports/doubleslash', { default: 'asdf' }],
48+
// Null target with several slashes
49+
['pkgexports/sub//internal/test.js', { default: 'internal only' }],
50+
['pkgexports/sub//internal//test.js', { default: 'internal only' }],
51+
['pkgexports/sub/////internal/////test.js', { default: 'internal only' }],
4852
// trailing slash
4953
['pkgexports/trailing-pattern-slash/',
5054
{ default: 'trailing-pattern-slash' }],
@@ -79,7 +83,11 @@ import fromInside from '../fixtures/node_modules/pkgexports/lib/hole.js';
7983
['pkgexports/invalid1', './invalid1'],
8084
['pkgexports/invalid4', './invalid4'],
8185
// Null mapping
86+
['pkgexports/sub/internal/test.js', './sub/internal/test.js'],
87+
['pkgexports/sub/internal//test.js', './sub/internal//test.js'],
8288
['pkgexports/null', './null'],
89+
['pkgexports//null', './/null'],
90+
['pkgexports/////null', './////null'],
8391
['pkgexports/null/subpath', './null/subpath'],
8492
// Empty fallback
8593
['pkgexports/nofallback1', './nofallback1'],

test/es-module/test-esm-imports.mjs

+18-4
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,14 @@ const { requireImport, importImport } = importer;
7979
'#missing',
8080
// Explicit null import
8181
'#null',
82+
'#subpath/null',
8283
// No condition match import
8384
'#nullcondition',
8485
// Null subpath shadowing
8586
'#subpath/nullshadow/x',
87+
// Null pattern
88+
'#subpath/internal/test',
89+
'#subpath/internal//test',
8690
]);
8791

8892
for (const specifier of undefinedImports) {
@@ -94,10 +98,20 @@ const { requireImport, importImport } = importer;
9498
}
9599

96100
// Handle not found for the defined imports target not existing
97-
loadFixture('#notfound').catch(mustCall((err) => {
98-
strictEqual(err.code,
99-
isRequire ? 'MODULE_NOT_FOUND' : 'ERR_MODULE_NOT_FOUND');
100-
}));
101+
const nonDefinedImports = new Set([
102+
'#notfound',
103+
'#subpath//null',
104+
'#subpath/////null',
105+
'#subpath//internal/test',
106+
'#subpath//internal//test',
107+
'#subpath/////internal/////test',
108+
]);
109+
for (const specifier of nonDefinedImports) {
110+
loadFixture(specifier).catch(mustCall((err) => {
111+
strictEqual(err.code,
112+
isRequire ? 'MODULE_NOT_FOUND' : 'ERR_MODULE_NOT_FOUND');
113+
}));
114+
}
101115
});
102116

103117
// CJS resolver must still support #package packages in node_modules

test/fixtures/es-modules/pkgimports/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"require": "./requirebranch.js"
77
},
88
"#subpath/*": "./sub/*",
9+
"#subpath/internal/*": null,
10+
"#subpath/null": null,
911
"#subpath/*.asdf": "./test.js",
1012
"#external": "pkgexports/valid-cjs",
1113
"#external/subpath/*": "pkgexports/sub/*",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
module.exports = 'internal only';

test/fixtures/node_modules/pkgexports/internal/test.js

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/node_modules/pkgexports/package.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)