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 <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Khaidi Chu <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent b24ee07 commit 4dce39a

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
const common = require('../common');
2424
const assert = require('assert');
2525
const fs = require('fs');
26+
const { COPYFILE_FICLONE } = fs.constants;
2627
const path = require('path');
2728
const tmpdir = require('../common/tmpdir');
2829
const msg = { test: 'this' };
@@ -44,7 +45,7 @@ if (process.env.FORK) {
4445
} catch (e) {
4546
if (e.code !== 'ENOENT') throw e;
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

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const fixtures = require('../common/fixtures');
44
const assert = require('assert');
55
const path = require('path');
66
const fs = require('fs');
7+
const { COPYFILE_FICLONE } = fs.constants;
78
const child_process = require('child_process');
89
const pkgName = '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
const mode = 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
const runTest = (expectedString, env) => {

0 commit comments

Comments
 (0)