@@ -14,6 +14,7 @@ import {
1414} from 'node:fs/promises' ;
1515import { tmpdir } from 'node:os' ;
1616import { join } from 'node:path' ;
17+ import { fileURLToPath } from 'node:url' ;
1718import test from 'node:test' ;
1819
1920import { PluginError } from '../scripts/lib/errors.mjs' ;
@@ -38,27 +39,14 @@ const jobInput = {
3839} ;
3940
4041const fsModuleUrl = new URL ( '../scripts/lib/fs.mjs' , import . meta. url ) . href ;
42+ const lockHolder = fileURLToPath ( new URL ( './fixtures/lock-holder.mjs' , import . meta. url ) ) ;
4143
4244/** @param {string } lockPath */
4345function startLockHolder ( lockPath ) {
44- const source = `
45- import { withFileLock } from ${ JSON . stringify ( fsModuleUrl ) } ;
46- const lockPath = process.argv[1];
47- try {
48- await withFileLock(lockPath, async () => {
49- process.stdout.write('acquired\\n');
50- await new Promise((resolve) => process.stdin.once('data', resolve));
51- }, {
52- pollIntervalMs: 5,
53- timeoutMs: 1_000,
54- });
55- process.stdout.write('released\\n');
56- } catch (error) {
57- process.stdout.write(\`error:\${error.code}\\n\`);
58- }
59- ` ;
60- return spawn ( process . execPath , [ '--input-type=module' , '--eval' , source , lockPath ] , {
46+ return spawn ( process . execPath , [ lockHolder , lockPath ] , {
6147 stdio : [ 'pipe' , 'pipe' , 'pipe' ] ,
48+ shell : false ,
49+ windowsHide : true ,
6250 } ) ;
6351}
6452
@@ -95,11 +83,11 @@ function startTimedLockAttempt(lockPath) {
9583
9684/** @param {import('node:child_process').ChildProcess } child @param {string } expected */
9785async function waitForOutput ( child , expected ) {
98- let output = '' ;
86+ let output = '' ; let stderr = '' ;
9987 await new Promise ( ( resolve , reject ) => {
10088 const timeout = setTimeout ( ( ) => {
10189 cleanup ( ) ;
102- reject ( new Error ( `Timed out waiting for child output: ${ expected } ; received: ${ output } ` ) ) ;
90+ reject ( new Error ( `Timed out waiting for child output: ${ expected } ; received: ${ output } ; stderr: ${ stderr } ` ) ) ;
10391 } , 2_000 ) ;
10492 function cleanup ( ) {
10593 clearTimeout ( timeout ) ;
@@ -117,9 +105,10 @@ async function waitForOutput(child, expected) {
117105 /** @param {number | null } code */
118106 function onExit ( code ) {
119107 cleanup ( ) ;
120- reject ( new Error ( `Child exited with ${ code } ; output: ${ output } ` ) ) ;
108+ reject ( new Error ( `Child exited with ${ code } ; output: ${ output } ; stderr: ${ stderr } ` ) ) ;
121109 }
122110 child . stdout ?. on ( 'data' , onData ) ;
111+ child . stderr ?. on ( 'data' , ( chunk ) => { stderr += chunk . toString ( ) ; } ) ;
123112 child . once ( 'exit' , onExit ) ;
124113 } ) ;
125114}
0 commit comments