Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

chore: use `ps-list` instead of `pidtree` to remove wmic (#5479)

Mark Wiemerb2985b3428b4
diff --git a/package-lock.json b/package-lock.json
index fdca48e8..1dfdc2f8 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -75,8 +75,8 @@
"needle": "^2.5.0",
"npm-run-all2": "^6.2.0",
"nyc": "^15.1.0",
- "pidtree": "^0.5.0",
"prettier": "^2.4.1",
+ "ps-list": "^9.0.0",
"remark": "^14.0.2",
"remark-github": "^11.2.2",
"remark-inline-links": "^6.0.1",
@@ -12563,18 +12563,6 @@
"url": "https://github.com/sponsors/jonschlinkert"
}
},
- "node_modules/pidtree": {
- "version": "0.5.0",
- "resolved": "https://registry.npmjs.org/pidtree/-/pidtree-0.5.0.tgz",
- "integrity": "sha512-9nxspIM7OpZuhBxPg73Zvyq7j1QMPMPsGKTqRc2XOaFQauDvoNz9fM1Wdkjmeo7l9GXOZiRs97sPkuayl39wjA==",
- "dev": true,
- "bin": {
- "pidtree": "bin/pidtree.js"
- },
- "engines": {
- "node": ">=0.10"
- }
- },
"node_modules/pify": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/pify/-/pify-4.0.1.tgz",
@@ -12795,6 +12783,19 @@
"integrity": "sha512-yPw4Sng1gWghHQWj0B3ZggWUm4qVbPwPFcRG8KyxiU7J2OHFSoEHKS+EZ3fv5l1t9CyCiop6l/ZYeWbrgoQejw==",
"dev": true
},
+ "node_modules/ps-list": {
+ "version": "9.0.0",
+ "resolved": "https://registry.npmjs.org/ps-list/-/ps-list-9.0.0.tgz",
+ "integrity": "sha512-lxMEoIL/BQlk2KunFzxwUPwMvjFH7x7cmvzSLsSHpyMXl9FFfLUlfKrYwFc4wx/ZaIxxuXC4n8rjQ1CX/tkXVQ==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=20"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/sindresorhus"
+ }
+ },
"node_modules/pseudomap": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz",
@@ -26464,12 +26465,6 @@
"integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==",
"dev": true
},
- "pidtree": {
- "version": "0.5.0",
- "resolved": "https://registry.npmjs.org/pidtree/-/pidtree-0.5.0.tgz",
- "integrity": "sha512-9nxspIM7OpZuhBxPg73Zvyq7j1QMPMPsGKTqRc2XOaFQauDvoNz9fM1Wdkjmeo7l9GXOZiRs97sPkuayl39wjA==",
- "dev": true
- },
"pify": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/pify/-/pify-4.0.1.tgz",
@@ -26637,6 +26632,12 @@
"integrity": "sha512-yPw4Sng1gWghHQWj0B3ZggWUm4qVbPwPFcRG8KyxiU7J2OHFSoEHKS+EZ3fv5l1t9CyCiop6l/ZYeWbrgoQejw==",
"dev": true
},
+ "ps-list": {
+ "version": "9.0.0",
+ "resolved": "https://registry.npmjs.org/ps-list/-/ps-list-9.0.0.tgz",
+ "integrity": "sha512-lxMEoIL/BQlk2KunFzxwUPwMvjFH7x7cmvzSLsSHpyMXl9FFfLUlfKrYwFc4wx/ZaIxxuXC4n8rjQ1CX/tkXVQ==",
+ "dev": true
+ },
"pseudomap": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz",
diff --git a/package.json b/package.json
index ddec7a42..819f7d50 100644
--- a/package.json
+++ b/package.json
@@ -130,9 +130,9 @@
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-multi-entry": "^4.0.1",
"@rollup/plugin-node-resolve": "^13.1.3",
+ "@test/esm-only-loader": "./test/compiler-fixtures/esm-only-loader",
"@types/node": "^22.15.3",
"@types/yargs": "^17.0.33",
- "@test/esm-only-loader": "./test/compiler-fixtures/esm-only-loader",
"chai": "^4.3.4",
"coffeescript": "^2.6.1",
"cross-env": "^7.0.2",
@@ -160,8 +160,8 @@
"needle": "^2.5.0",
"npm-run-all2": "^6.2.0",
"nyc": "^15.1.0",
- "pidtree": "^0.5.0",
"prettier": "^2.4.1",
+ "ps-list": "^9.0.0",
"remark": "^14.0.2",
"remark-github": "^11.2.2",
"remark-inline-links": "^6.0.1",
diff --git a/test/integration/options/parallel.spec.js b/test/integration/options/parallel.spec.js
index 825ef150..66cfaa70 100644
--- a/test/integration/options/parallel.spec.js
+++ b/test/integration/options/parallel.spec.js
@@ -6,10 +6,37 @@ const {
getSummary,
resolveFixturePath
} = require('../helpers');
-const pidtree = require('pidtree');
+const psList = require('ps-list').default;
const REPORTER_FIXTURE_PATH = resolveFixturePath('options/parallel/test-a');
+/**
+ * Get child processes of a given PID using ps-list
+ * @param {number} pid - Parent process ID
+ * @param {Object} options - Options object
+ * @param {boolean} options.root - Include the parent PID in results
+ * @returns {Promise<number[]>} Array of child process PIDs
+ */
+async function getChildPids(pid) {
+ return (
+ (await psList())
+ // ppid = parent process ID
+ .filter(proc => proc.ppid === pid)
+ .map(proc => proc.pid)
+ );
+}
+
+/**
+ * Check if a process exists using ps-list
+ * @param {number} pid - Process ID to check
+ * @param {Object} options - Options object
+ * @param {boolean} options.root - Include the PID itself in results
+ * @returns {Promise<boolean>} Array with the PID if exists, null otherwise
+ */
+async function checkProcessExists(pid) {
+ return (await psList()).some(proc => proc.pid === pid);
+}
+
/**
* Run a test fixture with the same reporter in both parallel and serial modes,
* returning both outputs for comparison
@@ -55,7 +82,7 @@ async function assertReporterOutputEquality(reporter) {
async function waitForChildPids(pid) {
let childPids = [];
while (!childPids.length) {
- childPids = await pidtree(pid);
+ childPids = await getChildPids(pid);
await new Promise(resolve => setTimeout(resolve, 100));
}
return childPids;
@@ -475,27 +502,12 @@ describe('--parallel', function () {
});
});
+ // - `waitForChildPids` polls for created children
+ // - `await promise` waits for `invokeMochaAsync` to complete, which should
+ // kill all children
+ // - `checkProcessExists` validates that each child was killed
+ // - if any weren't killed, the test fails
describe('pool shutdown', function () {
- // these are unusual and deserve some explanation. we start our mocha
- // subprocess, and in parallel mode, that subprocess spawns more
- // subprocesses. `invokeMochaAsync` returns a tuple of a `mocha`
- // `ChildProcess` object and a `Promise` (which will resolve/reject when the
- // subprocess finishes its test run). we use the `pid` from the `mocha`
- // `ChildProcess` to ask `pidtree` (https://npm.im/pidtree) for the
- // children, which are the worker processes. the `mocha` subprocess does
- // _not_ immediately spawn worker processes, so we need to _poll_ for child
- // processes. when we have them, we record them. once the `Promise`
- // resolves, we then attempt to get pid information for our `mocha` process
- // and _each_ worker process we retrieved earlier. if a process does not
- // exist, `pidtree` will reject--this is what we _want_ to happen. we check
- // each explicitly in case the child processes are somehow orphaned.
- //
- // we return `null` for each in the case of the expected rejection--if the
- // `Promise.all()` call results in an array containing anything _except_ a
- // bunch of `null`s, then this test fails, because one of the processes is
- // still running. this behavior is dependent on `[email protected]`, which
- // added a guarantee that terminating the pool will _wait_ until all child
- // processes have actually exited.
describe('during normal operation', function () {
it('should not leave orphaned processes around', async function () {
const [{pid}, promise] = invokeMochaAsync([
@@ -506,17 +518,13 @@ describe('--parallel', function () {
await promise;
return expect(
Promise.all(
- [pid, ...childPids].map(async childPid => {
- let pids = null;
- try {
- pids = await pidtree(childPid, {root: true});
- } catch (ignored) {}
- return pids;
- })
+ [pid, ...childPids].map(
+ async childPid => await checkProcessExists(childPid)
+ )
),
'when fulfilled',
'to have items satisfying',
- null
+ false
);
});
});
@@ -532,17 +540,13 @@ describe('--parallel', function () {
await promise;
return expect(
Promise.all(
- [pid, ...childPids].map(async childPid => {
- let pids = null;
- try {
- pids = await pidtree(childPid, {root: true});
- } catch (ignored) {}
- return pids;
- })
+ [pid, ...childPids].map(
+ async childPid => await checkProcessExists(childPid)
+ )
),
'when fulfilled',
'to have items satisfying',
- null
+ false
);
});
});