@@ -222,4 +222,46 @@ describe('node --run [command]', () => {
222
222
assert . strictEqual ( child . stdout , '' ) ;
223
223
assert . strictEqual ( child . code , 1 ) ;
224
224
} ) ;
225
+
226
+ it ( 'runs script in a custom working directory using --run-from' , async ( ) => {
227
+ const customDir = fixtures . path ( 'run-script' ) ;
228
+ const child = await common . spawnPromisified (
229
+ process . execPath ,
230
+ [ '--run-from' , customDir , '--run' , `pwd${ envSuffix } ` ] ,
231
+
232
+ { cwd : fixtures . path ( 'run-script/sub-directory' ) }
233
+ ) ;
234
+
235
+ assert . strictEqual ( child . stdout . trim ( ) , customDir ) ;
236
+ assert . strictEqual ( child . stderr , '' ) ;
237
+ assert . strictEqual ( child . code , 0 ) ;
238
+ } ) ;
239
+
240
+ it ( 'returns error on non-directory path for --run-from' , async ( ) => {
241
+ const nonDirPath = fixtures . path ( 'run-script/package.json' ) ;
242
+
243
+ const child = await common . spawnPromisified (
244
+ process . execPath ,
245
+ [ '--run-from' , nonDirPath , '--run' , 'pwd' ] ,
246
+ { cwd : fixtures . path ( 'run-script' ) }
247
+ ) ;
248
+
249
+ assert . match ( child . stderr , / n o t a d i r e c t o r y / ) ;
250
+ assert . strictEqual ( child . stdout , '' ) ;
251
+ assert . strictEqual ( child . code , 1 ) ;
252
+ } ) ;
253
+
254
+ it ( '--run-from should be no-op when used without --run' , async ( ) => {
255
+ const dirPath = fixtures . path ( 'run-script/package.json' ) ;
256
+
257
+ const child = await common . spawnPromisified (
258
+ process . execPath ,
259
+ [ '--run-from' , dirPath , '--print' , 'process.cwd()' ] ,
260
+ { cwd : process . cwd ( ) }
261
+ ) ;
262
+
263
+ assert . strictEqual ( child . stderr , '' ) ;
264
+ assert . strictEqual ( child . stdout , process . cwd ( ) + '\n' ) ;
265
+ assert . strictEqual ( child . code , 0 ) ;
266
+ } ) ;
225
267
} ) ;
0 commit comments