Skip to content

Commit

Permalink
test: use fs.copyFileSync()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
richardlau authored and MylesBorins committed May 8, 2018
1 parent b24ee07 commit 4dce39a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion test/parallel/test-child-process-fork-exec-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' };
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-module-loading-globalpaths.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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) => {
Expand Down

0 comments on commit 4dce39a

Please sign in to comment.