@@ -30,15 +30,15 @@ vi.mock('fs', async () => {
30
30
*/
31
31
describe ( 'launchNode' , ( ) => {
32
32
test ( 'using ephemeral port 0 is possible' , async ( ) => {
33
- const { cleanup, port, url } = await launchNode ( { port : '0' } ) ;
33
+ const { cleanup, port, url } = await launchNode ( { port : '0' , loggingEnabled : false } ) ;
34
34
expect ( await fetch ( url ) ) . toBeTruthy ( ) ;
35
35
expect ( port ) . not . toEqual ( '0' ) ;
36
36
37
37
cleanup ( ) ;
38
38
} ) ;
39
39
40
40
it ( 'cleanup kills the started node' , async ( ) => {
41
- const { cleanup, url } = await launchNode ( ) ;
41
+ const { cleanup, url } = await launchNode ( { loggingEnabled : false } ) ;
42
42
expect ( await fetch ( url ) ) . toBeTruthy ( ) ;
43
43
44
44
cleanup ( ) ;
@@ -57,7 +57,7 @@ describe('launchNode', () => {
57
57
const spawnSpy = vi . spyOn ( childProcessMod , 'spawn' ) ;
58
58
const killSpy = vi . spyOn ( process , 'kill' ) ;
59
59
60
- const { cleanup, pid } = await launchNode ( ) ;
60
+ const { cleanup, pid } = await launchNode ( { loggingEnabled : false } ) ;
61
61
62
62
const spawnOptions = spawnSpy . mock . calls [ 0 ] [ 2 ] ;
63
63
expect ( spawnOptions . detached ) . toBeTruthy ( ) ;
@@ -74,7 +74,7 @@ describe('launchNode', () => {
74
74
75
75
process . env . FUEL_CORE_PATH = '' ;
76
76
77
- const { result } = await safeExec ( async ( ) => launchNode ( ) ) ;
77
+ const { result } = await safeExec ( async ( ) => launchNode ( { loggingEnabled : false } ) ) ;
78
78
79
79
const command = spawnSpy . mock . calls [ 0 ] [ 0 ] ;
80
80
expect ( command ) . toEqual ( 'fuel-core' ) ;
@@ -95,7 +95,7 @@ describe('launchNode', () => {
95
95
96
96
const fuelCorePath = './my-fuel-core-binary-path' ;
97
97
const { error } = await safeExec ( async ( ) => {
98
- await launchNode ( { fuelCorePath, loggingEnabled : true } ) ;
98
+ await launchNode ( { fuelCorePath, loggingEnabled : false } ) ;
99
99
} ) ;
100
100
101
101
expect ( error ) . toBeTruthy ( ) ;
@@ -107,7 +107,7 @@ describe('launchNode', () => {
107
107
test ( 'reads FUEL_CORE_PATH environment variable for fuel-core binary' , async ( ) => {
108
108
const spawnSpy = vi . spyOn ( childProcessMod , 'spawn' ) ;
109
109
process . env . FUEL_CORE_PATH = 'fuels-core' ;
110
- const { cleanup, url } = await launchNode ( ) ;
110
+ const { cleanup, url } = await launchNode ( { loggingEnabled : false } ) ;
111
111
await Provider . create ( url ) ;
112
112
113
113
const command = spawnSpy . mock . calls [ 0 ] [ 0 ] ;
@@ -152,7 +152,7 @@ describe('launchNode', () => {
152
152
} ) ;
153
153
154
154
test ( 'logs fuel-core outputs via console.log' , async ( ) => {
155
- const logSpy = vi . spyOn ( console , 'log' ) ;
155
+ const logSpy = vi . spyOn ( console , 'log' ) . mockImplementation ( ( ) => { } ) ;
156
156
157
157
const { cleanup } = await launchNode ( { loggingEnabled : true } ) ;
158
158
const logs = logSpy . mock . calls . map ( ( call ) => call [ 0 ] ) ;
@@ -162,7 +162,7 @@ describe('launchNode', () => {
162
162
163
163
test ( 'cleanup removes temporary directory' , async ( ) => {
164
164
const mkdirSyncSpy = vi . spyOn ( fsMod , 'mkdirSync' ) ;
165
- const { cleanup } = await launchNode ( ) ;
165
+ const { cleanup } = await launchNode ( { loggingEnabled : false } ) ;
166
166
167
167
expect ( mkdirSyncSpy ) . toHaveBeenCalledTimes ( 1 ) ;
168
168
const tempDirPath = mkdirSyncSpy . mock . calls [ 0 ] [ 0 ] ;
@@ -252,4 +252,18 @@ describe('launchNode', () => {
252
252
`fuel-core node under pid ${ pid } does not exist. The node might have been killed before cleanup was called. Exiting cleanly.`
253
253
) ;
254
254
} ) ;
255
+
256
+ test ( 'should clean up when unable to kill process with "RangeError: pid must be a positive integer" error' , async ( ) => {
257
+ const killSpy = vi . spyOn ( process , 'kill' ) . mockImplementationOnce ( ( ) => {
258
+ throw new RangeError ( 'pid must be a positive integer' ) ;
259
+ } ) ;
260
+
261
+ const { pid, cleanup } = await launchNode ( { loggingEnabled : false } ) ;
262
+
263
+ cleanup ( ) ;
264
+
265
+ expect ( killSpy ) . toBeCalledTimes ( 2 ) ;
266
+ expect ( killSpy ) . toBeCalledWith ( - pid ) ;
267
+ expect ( killSpy ) . toBeCalledWith ( + pid ) ;
268
+ } ) ;
255
269
} ) ;
0 commit comments