summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Lau <riclau@uk.ibm.com>2018-04-26 20:11:56 +0100
committerTrivikram Kamat <16024985+trivikr@users.noreply.github.com>2018-05-02 23:44:47 -0700
commitb457ec8437e6f4960d7862fa5a81821bf967e698 (patch)
tree43a76db34c8f9e63f1802901d7aa659b0d07f447
parentaa18e22a235d75a28e8a25470b5f3b5f9be06a1f (diff)
downloadnode-new-b457ec8437e6f4960d7862fa5a81821bf967e698.tar.gz
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>
-rw-r--r--test/parallel/test-child-process-fork-exec-path.js3
-rw-r--r--test/parallel/test-module-loading-globalpaths.js3
2 files changed, 4 insertions, 2 deletions
diff --git a/test/parallel/test-child-process-fork-exec-path.js b/test/parallel/test-child-process-fork-exec-path.js
index 8b94ef62a9..cabd889347 100644
--- a/test/parallel/test-child-process-fork-exec-path.js
+++ b/test/parallel/test-child-process-fork-exec-path.js
@@ -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
diff --git a/test/parallel/test-module-loading-globalpaths.js b/test/parallel/test-module-loading-globalpaths.js
index 798b7765bb..284dbb0b3c 100644
--- a/test/parallel/test-module-loading-globalpaths.js
+++ b/test/parallel/test-module-loading-globalpaths.js
@@ -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) => {