From a588066518c831d6706a454caf34a0446a5bc492 Mon Sep 17 00:00:00 2001 From: Jacob Smith <3012099+JakobJingleheimer@users.noreply.github.com> Date: Thu, 13 Feb 2025 12:39:58 +0100 Subject: [PATCH] test: add case for unrecognised fields within pjson "exports" PR-URL: https://github.com/nodejs/node/pull/57026 Reviewed-By: Antoine du Hamel Reviewed-By: James M Snell --- .../packages/unrecognised-export-keys/index.js | 0 .../unrecognised-export-keys/package.json | 10 ++++++++++ test/parallel/test-find-package-json.js | 15 +++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 test/fixtures/packages/unrecognised-export-keys/index.js create mode 100644 test/fixtures/packages/unrecognised-export-keys/package.json diff --git a/test/fixtures/packages/unrecognised-export-keys/index.js b/test/fixtures/packages/unrecognised-export-keys/index.js new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/test/fixtures/packages/unrecognised-export-keys/package.json b/test/fixtures/packages/unrecognised-export-keys/package.json new file mode 100644 index 00000000000000..e3cef44544cc43 --- /dev/null +++ b/test/fixtures/packages/unrecognised-export-keys/package.json @@ -0,0 +1,10 @@ +{ + "name": "pkg-with-unrecognised-export-keys", + "exports": { + ".": { + "default": "./index.js", + "FtLcAG": "./whatever.ext", + "types": "./index.d.ts" + } + } +} diff --git a/test/parallel/test-find-package-json.js b/test/parallel/test-find-package-json.js index 5e55e81da1e7b8..fd9a1a85e77441 100644 --- a/test/parallel/test-find-package-json.js +++ b/test/parallel/test-find-package-json.js @@ -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); + }); });