Skip to content

Commit eef2b60

Browse files
fixup: add test-case for require() resolving via package.json
1 parent b531497 commit eef2b60

4 files changed

Lines changed: 17 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 42;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const answer = require('./');
2+
3+
module.exports = answer+1;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "main-no-index",
3+
"main": "./main.js",
4+
"type":"commonjs"
5+
}

test/parallel/test-get-package-json.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,11 @@ const pkgType = 'module'; // a non-default value
137137
const pathToParent = fixtures.path('packages/nested/package.json');
138138
assert.strictEqual(parentPkg.path, pathToParent);
139139
}
140+
141+
{ // Can require via package.json
142+
const pathToMod = fixtures.path('packages/cjs-main-no-index/other.js');
143+
// require() falls back to package.json values like "main" to resolve when there is no index
144+
const answer = require(pathToMod);
145+
146+
assert.strictEqual(answer, 43);
147+
}

0 commit comments

Comments
 (0)