Skip to content

Commit 73ebdfa

Browse files
authored
fix(test): replace wmic usage with native Windows API (#5694)
* feat(test): replace `wmic` usage with native Windows API in v11.x branch Signed-off-by: hainenber <dotronghai96@gmail.com> * fix: add missing `child_process` import Signed-off-by: hainenber <dotronghai96@gmail.com> * chore: add assert to ensure wmic-less pid listing working as expected Signed-off-by: hainenber <dotronghai96@gmail.com> --------- Signed-off-by: hainenber <dotronghai96@gmail.com>
1 parent aafe6fd commit 73ebdfa

3 files changed

Lines changed: 63 additions & 31 deletions

File tree

package-lock.json

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
"@test/esm-only-loader": "./test/compiler-fixtures/esm-only-loader",
135135
"@types/node": "^22.15.3",
136136
"@types/yargs": "^17.0.33",
137+
"@vscode/windows-process-tree": "^0.6.3",
137138
"chai": "^4.3.4",
138139
"coffeescript": "^2.6.1",
139140
"cross-env": "^7.0.2",

test/integration/options/parallel.spec.js

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
"use strict";
2+
const childProcess = require("node:child_process");
3+
const assert = require("node:assert");
4+
const { getProcessList } = require("@vscode/windows-process-tree");
25
const Mocha = require("../../../lib/mocha");
36
const {
47
runMochaAsync,
@@ -54,27 +57,26 @@ async function assertReporterOutputEquality(reporter) {
5457
/**
5558
* Polls a process for its list of children PIDs. Returns the first non-empty list found
5659
* @param {number} pid - Process PID
57-
* @returns {number[]} Child PIDs
60+
* @returns {Promise<number[]>} Child PIDs
5861
*/
5962
async function waitForChildPids(pid) {
6063
let childPids = [];
6164
while (!childPids.length) {
62-
try {
65+
if (process.platform === 'win32') {
66+
childPids = (await getProcessList.__promisify__(pid)).map(i => i.pid);
67+
} else {
6368
childPids = await pidtree(pid);
64-
} catch (err) {
65-
// On Windows, pidtree may fail if wmic is not available (deprecated/removed in newer Windows)
66-
// In this case, we can't reliably get child PIDs, so throw to skip the test
67-
if (process.platform === 'win32' && err.message && err.message.includes('wmic')) {
68-
throw new Error('pidtree requires wmic on Windows, which is not available');
69-
}
70-
throw err;
7169
}
7270
await new Promise((resolve) => setTimeout(resolve, 100));
7371
}
7472
return childPids;
7573
}
7674

7775
describe("--parallel", function () {
76+
if (process.platform === 'win32') {
77+
childProcess.spawn('cmd.exe');
78+
}
79+
7880
describe("when a test has a syntax error", function () {
7981
describe("when there is only a single test file", function () {
8082
it("should fail gracefully", async function () {
@@ -515,23 +517,19 @@ describe("--parallel", function () {
515517
resolveFixturePath("options/parallel/test-*"),
516518
"--parallel",
517519
]);
518-
let childPids;
519-
try {
520-
childPids = await waitForChildPids(pid);
521-
} catch (err) {
522-
if (err.message && err.message.includes('wmic')) {
523-
this.skip();
524-
return;
525-
}
526-
throw err;
527-
}
520+
const childPids = await waitForChildPids(pid);
521+
assert.ok(childPids.length > 0);
528522
await promise;
529523
return expect(
530524
Promise.all(
531525
[pid, ...childPids].map(async (childPid) => {
532526
let pids = null;
533527
try {
534-
pids = await pidtree(childPid, { root: true });
528+
if (process.platform === 'win32') {
529+
pids = (await getProcessList.__promisify__(childPid)).map(i => i.pid);
530+
} else {
531+
pids = await pidtree(childPid, { root: true });
532+
}
535533
} catch (ignored) {}
536534
return pids;
537535
}),
@@ -550,23 +548,19 @@ describe("--parallel", function () {
550548
"--bail",
551549
"--parallel",
552550
]);
553-
let childPids;
554-
try {
555-
childPids = await waitForChildPids(pid);
556-
} catch (err) {
557-
if (err.message && err.message.includes('wmic')) {
558-
this.skip();
559-
return;
560-
}
561-
throw err;
562-
}
551+
const childPids = await waitForChildPids(pid);
552+
assert.ok(childPids.length > 0);
563553
await promise;
564554
return expect(
565555
Promise.all(
566556
[pid, ...childPids].map(async (childPid) => {
567557
let pids = null;
568558
try {
569-
pids = await pidtree(childPid, { root: true });
559+
if (process.platform === 'win32') {
560+
pids = (await getProcessList.__promisify__(childPid)).map(i => i.pid);
561+
} else {
562+
pids = await pidtree(childPid, { root: true });
563+
}
570564
} catch (ignored) {}
571565
return pids;
572566
}),

0 commit comments

Comments
 (0)