test: add case for unrecognised fields within pjson "exports"

PR-URL: https://github.com/nodejs/node/pull/57026
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Jacob Smith
2025-02-13 12:39:58 +01:00
committed by James M Snell
parent a613f2f312
commit 61a57f7761
3 changed files with 25 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
{
"name": "pkg-with-unrecognised-export-keys",
"exports": {
".": {
"default": "./index.js",
"FtLcAG": "./whatever.ext",
"types": "./index.d.ts"
}
}
}

View File

@@ -189,4 +189,19 @@ describe('findPackageJSON', () => { // Throws when no arguments are provided
assert.ok(stdout.includes(foundPjsonPath), stdout);
assert.strictEqual(code, 0);
});
it('should work when unrecognised keys are specified within the export', async () => {
const specifierBase = './packages/unrecognised-export-keys';
const target = fixtures.fileURL(specifierBase, 'index.js');
const foundPjsonPath = path.toNamespacedPath(fixtures.path(specifierBase, 'package.json'));
const { code, stderr, stdout } = await common.spawnPromisified(process.execPath, [
'--print',
`require("node:module").findPackageJSON(${JSON.stringify(target)})`,
]);
assert.strictEqual(stderr, '');
assert.ok(stdout.includes(foundPjsonPath), stdout);
assert.strictEqual(code, 0);
});
});