11"use strict" ;
2+ const childProcess = require ( "node:child_process" ) ;
3+ const assert = require ( "node:assert" ) ;
4+ const { getProcessList } = require ( "@vscode/windows-process-tree" ) ;
25const Mocha = require ( "../../../lib/mocha" ) ;
36const {
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 */
5962async 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
7775describe ( "--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