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: nodejs#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]>
  • Loading branch information
richardlau authored and trivikr committed May 3, 2018
1 parent aa18e22 commit b457ec8
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 b457ec8

Please sign in to comment.