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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
aa18e22a23
commit
b457ec8437
@ -23,6 +23,7 @@
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const { COPYFILE_FICLONE } = fs.constants;
|
||||
const path = require('path');
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
const msg = { test: 'this' };
|
||||
@ -44,7 +45,7 @@ if (process.env.FORK) {
|
||||
} catch (e) {
|
||||
if (e.code !== 'ENOENT') throw e;
|
||||
}
|
||||
fs.writeFileSync(copyPath, fs.readFileSync(nodePath));
|
||||
fs.copyFileSync(nodePath, copyPath, COPYFILE_FICLONE);
|
||||
fs.chmodSync(copyPath, '0755');
|
||||
|
||||
// slow but simple
|
||||
|
@ -4,6 +4,7 @@ const fixtures = require('../common/fixtures');
|
||||
const assert = require('assert');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const { COPYFILE_FICLONE } = fs.constants;
|
||||
const child_process = require('child_process');
|
||||
const pkgName = 'foo';
|
||||
const { addLibraryPath } = require('../common/shared-lib-util');
|
||||
@ -28,7 +29,7 @@ if (process.argv[2] === 'child') {
|
||||
testExecPath = path.join(prefixBinPath, path.basename(process.execPath));
|
||||
}
|
||||
const mode = fs.statSync(process.execPath).mode;
|
||||
fs.writeFileSync(testExecPath, fs.readFileSync(process.execPath));
|
||||
fs.copyFileSync(process.execPath, testExecPath, COPYFILE_FICLONE);
|
||||
fs.chmodSync(testExecPath, mode);
|
||||
|
||||
const runTest = (expectedString, env) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user