From 4dce39a91949e88ca9f033019fe9a9db1f17f390 Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Thu, 26 Apr 2018 20:11:56 +0100 Subject: [PATCH] test: use fs.copyFileSync() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-By: Colin Ihrig Reviewed-By: Tobias Nießen Reviewed-By: Daniel Bevenius Reviewed-By: Khaidi Chu Reviewed-By: Trivikram Kamat Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater --- test/parallel/test-child-process-fork-exec-path.js | 3 ++- test/parallel/test-module-loading-globalpaths.js | 3 ++- 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 8b94ef62a93bc8..cabd8893475630 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 798b7765bb6d5b..284dbb0b3cd564 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) => {