|
21 | 21 |
|
22 | 22 | 'use strict'; |
23 | 23 | constcommon=require('../common'); |
| 24 | + |
| 25 | +// Test that `fork()` respects the `execPath` option. |
| 26 | + |
| 27 | +consttmpdir=require('../common/tmpdir'); |
| 28 | +const{ addLibraryPath }=require('../common/shared-lib-util'); |
24 | 29 | constassert=require('assert'); |
25 | | -constfs=require('fs'); |
26 | | -const{COPYFILE_FICLONE}=fs.constants; |
27 | 30 | constpath=require('path'); |
28 | | -consttmpdir=require('../common/tmpdir'); |
| 31 | +constfs=require('fs'); |
| 32 | +const{ fork }=require('child_process'); |
| 33 | + |
29 | 34 | constmsg={test: 'this'}; |
30 | 35 | constnodePath=process.execPath; |
31 | 36 | constcopyPath=path.join(tmpdir.path,'node-copy.exe'); |
32 | | -const{ addLibraryPath }=require('../common/shared-lib-util'); |
33 | 37 |
|
34 | 38 | addLibraryPath(process.env); |
35 | 39 |
|
| 40 | +// Child |
36 | 41 | if(process.env.FORK){ |
37 | | -assert(process.send); |
38 | | -assert.strictEqual(process.argv[0],copyPath); |
| 42 | +assert.strictEqual(process.execPath,copyPath); |
| 43 | +assert.ok(process.send); |
39 | 44 | process.send(msg); |
40 | | -process.exit(); |
41 | | -}else{ |
42 | | -tmpdir.refresh(); |
43 | | -try{ |
44 | | -fs.unlinkSync(copyPath); |
45 | | -}catch(e){ |
46 | | -if(e.code!=='ENOENT')throwe; |
47 | | -} |
48 | | -fs.copyFileSync(nodePath,copyPath,COPYFILE_FICLONE); |
49 | | -fs.chmodSync(copyPath,'0755'); |
50 | | - |
51 | | -// slow but simple |
52 | | -constenvCopy=JSON.parse(JSON.stringify(process.env)); |
53 | | -envCopy.FORK='true'; |
54 | | -constchild=require('child_process').fork(__filename,{ |
55 | | -execPath: copyPath, |
56 | | -env: envCopy |
57 | | -}); |
58 | | -child.on('message',common.mustCall(function(recv){ |
59 | | -assert.deepStrictEqual(msg,recv); |
60 | | -})); |
61 | | -child.on('exit',common.mustCall(function(code){ |
62 | | -fs.unlinkSync(copyPath); |
63 | | -assert.strictEqual(code,0); |
64 | | -})); |
| 45 | +returnprocess.exit(); |
65 | 46 | } |
| 47 | + |
| 48 | +// Parent |
| 49 | +tmpdir.refresh(); |
| 50 | +assert.strictEqual(fs.existsSync(copyPath),false); |
| 51 | +fs.copyFileSync(nodePath,copyPath,fs.constants.COPYFILE_FICLONE); |
| 52 | +fs.chmodSync(copyPath,'0755'); |
| 53 | + |
| 54 | +constenvCopy=Object.assign({},process.env,{'FORK': 'true'}); |
| 55 | +constchild=fork(__filename,{execPath: copyPath,env: envCopy}); |
| 56 | +child.on('message',common.mustCall(function(recv){ |
| 57 | +assert.deepStrictEqual(recv,msg); |
| 58 | +})); |
| 59 | +child.on('exit',common.mustCall(function(code){ |
| 60 | +assert.strictEqual(code,0); |
| 61 | +})); |
0 commit comments