☕️ Classic, reliable, trusted test framework for Node.js and the browser
fix: add package.json exports to avoid DEP0151 warning (#6168)
Mark Wiemer3031567913b5
diff --git a/package.json b/package.jsonindex f0b266ff..8f6d3ec5 100644--- a/package.json+++ b/package.json@@ -31,6 +31,10 @@"homepage": "https://mochajs.org/","logo": "https://cldup.com/S9uQ-cOLYz.svg","notifyLogo": "https://ibin.co/4QuRuGjXvl36.png",+ "exports": {+ ".": "./index.js",+ "./*": "./*"+ },"bin": {"mocha": "./bin/mocha.js"},diff --git a/test/integration/package-entrypoint.spec.cjs b/test/integration/package-entrypoint.spec.cjsnew file mode 100644index 00000000..fd9aa23a--- /dev/null+++ b/test/integration/package-entrypoint.spec.cjs@@ -0,0 +1,50 @@+"use strict";++const fs = require("node:fs");+const os = require("node:os");+const path = require("node:path");+const { invokeNode } = require("./helpers.cjs");++describe("package entrypoint", function () {+ it("should resolve the package root without DEP0151 warnings", async function () {+ const repoRoot = path.resolve(__dirname, "..", "..");+ const tempDir = fs.mkdtempSync(+ path.join(os.tmpdir(), "mocha-package-root-"),+ );+ const packageDir = path.join(tempDir, "node_modules", "mocha");++ fs.mkdirSync(path.dirname(packageDir), { recursive: true });++ try {+ if (process.platform === "win32") {+ fs.symlinkSync(repoRoot, packageDir, "junction");+ } else {+ fs.symlinkSync(repoRoot, packageDir);+ }++ const result = await new Promise((resolve, reject) => {+ invokeNode(+ [+ "--input-type=module",+ "-e",+ "import {describe, it} from 'mocha'; console.log(typeof describe, typeof it);",+ ],+ (err, res) => {+ if (err) {+ reject(err);+ return;+ }+ resolve(res);+ },+ { cwd: tempDir, stdio: ["ignore", "pipe", "pipe"] },+ );+ });++ expect(result.code, "to be", 0);+ expect(result.output, "to contain", "function function");+ expect(result.output, "not to contain", "DEP0151");+ } finally {+ fs.rmSync(tempDir, { recursive: true, force: true });+ }+ });+});