@@ -222,4 +222,49 @@ 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 workingDir = fixtures . path ( 'run-script' ) ;
228
+
229
+ const child = await common . spawnPromisified (
230
+ process . execPath ,
231
+ [ '--run-from' , workingDir , '--run' , `pwd${ envSuffix } ` ] ,
232
+
233
+ { env : fixtures . path ( 'run-script/sub-directory' ) }
234
+ ) ;
235
+
236
+ assert . strictEqual ( child . stdout . trim ( ) , workingDir ) ;
237
+ assert . strictEqual ( child . stderr , '' ) ;
238
+ assert . strictEqual ( child . code , 0 ) ;
239
+ } ) ;
240
+
241
+ it ( 'runs script in a custom working directory using --run-from is given a package.json' , async ( ) => {
242
+ const packageJson = fixtures . path ( 'run-script/package.json' ) ;
243
+ const workingDir = fixtures . path ( 'run-script' ) ;
244
+
245
+ const child = await common . spawnPromisified (
246
+ process . execPath ,
247
+ [ '--run-from' , packageJson , '--run' , `pwd${ envSuffix } ` ] ,
248
+
249
+ { env : fixtures . path ( 'run-script/sub-directory' ) }
250
+ ) ;
251
+
252
+ assert . strictEqual ( child . stdout . trim ( ) , workingDir ) ;
253
+ assert . strictEqual ( child . stderr , '' ) ;
254
+ assert . strictEqual ( child . code , 0 ) ;
255
+ } )
256
+
257
+ it ( '--run-from should be no-op when used without --run' , async ( ) => {
258
+ const packageJson = fixtures . path ( 'run-script/package.json' ) ;
259
+
260
+ const child = await common . spawnPromisified (
261
+ process . execPath ,
262
+ [ '--run-from' , packageJson , '--print' , 'process.cwd()' ] ,
263
+ { cwd : process . cwd ( ) }
264
+ ) ;
265
+
266
+ assert . strictEqual ( child . stdout . trim ( ) , process . cwd ( ) ) ;
267
+ assert . strictEqual ( child . stderr , '' ) ;
268
+ assert . strictEqual ( child . code , 0 ) ;
269
+ } )
225
270
} ) ;
0 commit comments