Skip to content

Commit 4dce39a

Browse files
richardlauMylesBorins
authored andcommitted
test: use fs.copyFileSync()
Use the potentially more efficient fs.copyFileSync() instead of reading the whole file in and writing the whole file out in JavaScript. PR-URL: #20340 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Khaidi Chu <i@2333.moe> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent b24ee07 commit 4dce39a

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

‎test/parallel/test-child-process-fork-exec-path.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
constcommon=require('../common');
2424
constassert=require('assert');
2525
constfs=require('fs');
26+
const{COPYFILE_FICLONE}=fs.constants;
2627
constpath=require('path');
2728
consttmpdir=require('../common/tmpdir');
2829
constmsg={test: 'this'};
@@ -44,7 +45,7 @@ if (process.env.FORK) {
4445
}catch(e){
4546
if(e.code!=='ENOENT')throwe;
4647
}
47-
fs.writeFileSync(copyPath,fs.readFileSync(nodePath));
48+
fs.copyFileSync(nodePath,copyPath,COPYFILE_FICLONE);
4849
fs.chmodSync(copyPath,'0755');
4950

5051
// slow but simple

‎test/parallel/test-module-loading-globalpaths.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const fixtures = require('../common/fixtures');
44
constassert=require('assert');
55
constpath=require('path');
66
constfs=require('fs');
7+
const{COPYFILE_FICLONE}=fs.constants;
78
constchild_process=require('child_process');
89
constpkgName='foo';
910
const{ addLibraryPath }=require('../common/shared-lib-util');
@@ -28,7 +29,7 @@ if (process.argv[2] === 'child') {
2829
testExecPath=path.join(prefixBinPath,path.basename(process.execPath));
2930
}
3031
constmode=fs.statSync(process.execPath).mode;
31-
fs.writeFileSync(testExecPath,fs.readFileSync(process.execPath));
32+
fs.copyFileSync(process.execPath,testExecPath,COPYFILE_FICLONE);
3233
fs.chmodSync(testExecPath,mode);
3334

3435
construnTest=(expectedString,env)=>{

0 commit comments

Comments
 (0)