From 05ef4bdd35bb3e1ccaa6ba73b8a188be63a014e3 Mon Sep 17 00:00:00 2001 From: Fran Herrero Date: Tue, 12 Nov 2019 15:40:35 +0000 Subject: [PATCH] test: use spread object Object.assign() can be replaced by spread objects PR-URL: https://github.com/nodejs/node/pull/30423 Refs: https://eslint.org/docs/rules/prefer-object-spread Reviewed-By: Colin Ihrig Reviewed-By: Trivikram Kamat Reviewed-By: Ruben Bridgewater Reviewed-By: James M Snell Reviewed-By: Gireesh Punathil Reviewed-By: Rich Trott --- test/fixtures/v8-coverage/spawn-subprocess-no-cov.js | 2 +- test/fixtures/v8-coverage/spawn-subprocess.js | 2 +- test/parallel/test-child-process-env.js | 5 +++-- test/parallel/test-child-process-exec-env.js | 2 +- test/parallel/test-child-process-fork-no-shell.js | 2 +- test/parallel/test-child-process-spawn-shell.js | 2 +- test/parallel/test-child-process-spawnsync-shell.js | 2 +- test/parallel/test-cli-node-options-disallowed.js | 2 +- test/parallel/test-crypto-fips.js | 2 +- test/parallel/test-env-var-no-warnings.js | 2 +- test/parallel/test-fs-readfile-error.js | 2 +- test/parallel/test-http-server-stale-close.js | 4 +--- test/parallel/test-https-agent-additional-options.js | 2 +- test/parallel/test-icu-data-dir.js | 2 +- test/parallel/test-module-loading-globalpaths.js | 2 +- test/parallel/test-net-connect-options-fd.js | 2 +- test/parallel/test-pending-deprecation.js | 2 +- test/parallel/test-process-redirect-warnings-env.js | 3 +-- test/parallel/test-stdin-script-child.js | 6 +++--- test/parallel/test-tls-env-bad-extra-ca.js | 5 +++-- test/parallel/test-tls-env-extra-ca-file-load.js | 2 +- test/parallel/test-tls-env-extra-ca-no-crypto.js | 2 +- test/parallel/test-tls-env-extra-ca.js | 5 +++-- 23 files changed, 31 insertions(+), 31 deletions(-) diff --git a/test/fixtures/v8-coverage/spawn-subprocess-no-cov.js b/test/fixtures/v8-coverage/spawn-subprocess-no-cov.js index 5baf179e5f1cdf..2ee6e991f03986 100644 --- a/test/fixtures/v8-coverage/spawn-subprocess-no-cov.js +++ b/test/fixtures/v8-coverage/spawn-subprocess-no-cov.js @@ -1,5 +1,5 @@ const { spawnSync } = require('child_process'); -const env = Object.assign({}, process.env, { NODE_V8_COVERAGE: '' }); +const env = { ...process.env, NODE_V8_COVERAGE: '' }; spawnSync(process.execPath, [require.resolve('./subprocess')], { env: env }); diff --git a/test/fixtures/v8-coverage/spawn-subprocess.js b/test/fixtures/v8-coverage/spawn-subprocess.js index 53ef7b995506f9..b5da766991e75c 100644 --- a/test/fixtures/v8-coverage/spawn-subprocess.js +++ b/test/fixtures/v8-coverage/spawn-subprocess.js @@ -1,5 +1,5 @@ const { spawnSync } = require('child_process'); -const env = Object.assign({}, process.env); +const env = { ...process.env }; delete env.NODE_V8_COVERAGE spawnSync(process.execPath, [require.resolve('./subprocess')], { env: env diff --git a/test/parallel/test-child-process-env.js b/test/parallel/test-child-process-env.js index 1e398ff26afee9..0a20ee232f7c32 100644 --- a/test/parallel/test-child-process-env.js +++ b/test/parallel/test-child-process-env.js @@ -26,12 +26,13 @@ const os = require('os'); const spawn = require('child_process').spawn; -const env = Object.assign({}, process.env, { +const env = { + ...process.env, 'HELLO': 'WORLD', 'UNDEFINED': undefined, 'NULL': null, 'EMPTY': '' -}); +}; Object.setPrototypeOf(env, { 'FOO': 'BAR' }); diff --git a/test/parallel/test-child-process-exec-env.js b/test/parallel/test-child-process-exec-env.js index 41aaf992cfc8c9..eac07bce88b204 100644 --- a/test/parallel/test-child-process-exec-env.js +++ b/test/parallel/test-child-process-exec-env.js @@ -45,7 +45,7 @@ if (!common.isWindows) { child = exec('/usr/bin/env', { env: { 'HELLO': 'WORLD' } }, after); } else { child = exec('set', - { env: Object.assign({}, process.env, { 'HELLO': 'WORLD' }) }, + { env: { ...process.env, 'HELLO': 'WORLD' } }, after); } diff --git a/test/parallel/test-child-process-fork-no-shell.js b/test/parallel/test-child-process-fork-no-shell.js index 168f115b0cbcbf..81ceab61fd203f 100644 --- a/test/parallel/test-child-process-fork-no-shell.js +++ b/test/parallel/test-child-process-fork-no-shell.js @@ -8,7 +8,7 @@ const expected = common.isWindows ? '%foo%' : '$foo'; if (process.argv[2] === undefined) { const child = cp.fork(__filename, [expected], { shell: true, - env: Object.assign({}, process.env, { foo: 'bar' }) + env: { ...process.env, foo: 'bar' } }); child.on('exit', common.mustCall((code, signal) => { diff --git a/test/parallel/test-child-process-spawn-shell.js b/test/parallel/test-child-process-spawn-shell.js index e9a753e91a4e48..9b8de0507130d6 100644 --- a/test/parallel/test-child-process-spawn-shell.js +++ b/test/parallel/test-child-process-spawn-shell.js @@ -50,7 +50,7 @@ command.on('close', common.mustCall((code, signal) => { // Verify that the environment is properly inherited const env = cp.spawn(`"${process.execPath}" -pe process.env.BAZ`, { - env: Object.assign({}, process.env, { BAZ: 'buzz' }), + env: { ...process.env, BAZ: 'buzz' }, encoding: 'utf8', shell: true }); diff --git a/test/parallel/test-child-process-spawnsync-shell.js b/test/parallel/test-child-process-spawnsync-shell.js index 01c5aef9e8d919..f94a67a804b82d 100644 --- a/test/parallel/test-child-process-spawnsync-shell.js +++ b/test/parallel/test-child-process-spawnsync-shell.js @@ -37,7 +37,7 @@ assert.strictEqual(command.stdout.toString().trim(), 'bar'); // Verify that the environment is properly inherited const env = cp.spawnSync(`"${process.execPath}" -pe process.env.BAZ`, { - env: Object.assign({}, process.env, { BAZ: 'buzz' }), + env: { ...process.env, BAZ: 'buzz' }, shell: true }); diff --git a/test/parallel/test-cli-node-options-disallowed.js b/test/parallel/test-cli-node-options-disallowed.js index 867e829a1d9fba..70341fd97b93ce 100644 --- a/test/parallel/test-cli-node-options-disallowed.js +++ b/test/parallel/test-cli-node-options-disallowed.js @@ -28,7 +28,7 @@ disallow('--v8-options'); disallow('--'); function disallow(opt) { - const env = Object.assign({}, process.env, { NODE_OPTIONS: opt }); + const env = { ...process.env, NODE_OPTIONS: opt }; exec(process.execPath, { cwd: tmpdir.path, env }, common.mustCall((err) => { const message = err.message.split(/\r?\n/)[1]; const expect = `${process.execPath}: ${opt} is not allowed in NODE_OPTIONS`; diff --git a/test/parallel/test-crypto-fips.js b/test/parallel/test-crypto-fips.js index fa4b80968976c5..eae31344028c69 100644 --- a/test/parallel/test-crypto-fips.js +++ b/test/parallel/test-crypto-fips.js @@ -71,7 +71,7 @@ testHelper( [], FIPS_DISABLED, 'require("crypto").getFips()', - Object.assign({}, process.env, { 'OPENSSL_CONF': '' })); + { ...process.env, 'OPENSSL_CONF': '' }); // --enable-fips should turn FIPS mode on testHelper( diff --git a/test/parallel/test-env-var-no-warnings.js b/test/parallel/test-env-var-no-warnings.js index e2a11656f33df2..cf90c2759d9ad7 100644 --- a/test/parallel/test-env-var-no-warnings.js +++ b/test/parallel/test-env-var-no-warnings.js @@ -7,7 +7,7 @@ if (process.argv[2] === 'child') { process.emitWarning('foo'); } else { function test(newEnv) { - const env = Object.assign({}, process.env, newEnv); + const env = { ...process.env, ...newEnv }; const cmd = `"${process.execPath}" "${__filename}" child`; cp.exec(cmd, { env }, common.mustCall((err, stdout, stderr) => { diff --git a/test/parallel/test-fs-readfile-error.js b/test/parallel/test-fs-readfile-error.js index 3b245058ff6f38..992df71d216d30 100644 --- a/test/parallel/test-fs-readfile-error.js +++ b/test/parallel/test-fs-readfile-error.js @@ -37,7 +37,7 @@ const fixtures = require('../common/fixtures'); function test(env, cb) { const filename = fixtures.path('test-fs-readfile-error.js'); const execPath = `"${process.execPath}" "${filename}"`; - const options = { env: Object.assign({}, process.env, env) }; + const options = { env: { ...process.env, ...env } }; exec(execPath, options, (err, stdout, stderr) => { assert(err); assert.strictEqual(stdout, ''); diff --git a/test/parallel/test-http-server-stale-close.js b/test/parallel/test-http-server-stale-close.js index 9502d570942e41..d67c4d31c36e37 100644 --- a/test/parallel/test-http-server-stale-close.js +++ b/test/parallel/test-http-server-stale-close.js @@ -44,9 +44,7 @@ if (process.env.NODE_TEST_FORK_PORT) { }); server.listen(0, function() { fork(__filename, { - env: Object.assign({}, process.env, { - NODE_TEST_FORK_PORT: this.address().port - }) + env: { ...process.env, NODE_TEST_FORK_PORT: this.address().port } }); }); } diff --git a/test/parallel/test-https-agent-additional-options.js b/test/parallel/test-https-agent-additional-options.js index 99fcd0126ab1a0..2b5446b9e3d194 100644 --- a/test/parallel/test-https-agent-additional-options.js +++ b/test/parallel/test-https-agent-additional-options.js @@ -63,7 +63,7 @@ function variations(iter, port, cb) { // Save `value` for check the next time. value = next.value.val; const [key, val] = next.value; - https.get(Object.assign({}, getBaseOptions(port), { [key]: val }), + https.get({ ...getBaseOptions(port), [key]: val }, variations(iter, port, cb)); } })); diff --git a/test/parallel/test-icu-data-dir.js b/test/parallel/test-icu-data-dir.js index 5b37e27d32aa1f..f1da0dc685ae9d 100644 --- a/test/parallel/test-icu-data-dir.js +++ b/test/parallel/test-icu-data-dir.js @@ -21,7 +21,7 @@ const expected = } { - const env = Object.assign({}, process.env, { NODE_ICU_DATA: '/' }); + const env = { ...process.env, NODE_ICU_DATA: '/' }; const child = spawnSync(process.execPath, ['-e', '0'], { env }); assert(child.stderr.toString().includes(expected)); } diff --git a/test/parallel/test-module-loading-globalpaths.js b/test/parallel/test-module-loading-globalpaths.js index 284dbb0b3cd564..5d6a104f29c9d7 100644 --- a/test/parallel/test-module-loading-globalpaths.js +++ b/test/parallel/test-module-loading-globalpaths.js @@ -41,7 +41,7 @@ if (process.argv[2] === 'child') { const testFixturesDir = fixtures.path(path.basename(__filename, '.js')); - const env = Object.assign({}, process.env); + const env = { ...process.env }; // Unset NODE_PATH. delete env.NODE_PATH; diff --git a/test/parallel/test-net-connect-options-fd.js b/test/parallel/test-net-connect-options-fd.js index 94b831bf5d2ac3..62e1414421404a 100644 --- a/test/parallel/test-net-connect-options-fd.js +++ b/test/parallel/test-net-connect-options-fd.js @@ -15,7 +15,7 @@ tmpdir.refresh(); function testClients(getSocketOpt, getConnectOpt, getConnectCb) { const cloneOptions = (index) => - Object.assign({}, getSocketOpt(index), getConnectOpt(index)); + ({ ...getSocketOpt(index), ...getConnectOpt(index) }); return [ net.connect(cloneOptions(0), getConnectCb(0)), net.connect(cloneOptions(1)) diff --git a/test/parallel/test-pending-deprecation.js b/test/parallel/test-pending-deprecation.js index 6cabf9ddc693f7..c94c75560df695 100644 --- a/test/parallel/test-pending-deprecation.js +++ b/test/parallel/test-pending-deprecation.js @@ -55,7 +55,7 @@ switch (process.argv[2]) { // Test the NODE_PENDING_DEPRECATION environment var. fork(__filename, ['env'], { - env: Object.assign({}, process.env, { NODE_PENDING_DEPRECATION: 1 }), + env: { ...process.env, NODE_PENDING_DEPRECATION: 1 }, execArgv: ['--expose-internals'], silent: true }).on('exit', common.mustCall((code) => { diff --git a/test/parallel/test-process-redirect-warnings-env.js b/test/parallel/test-process-redirect-warnings-env.js index 5031152a48baf0..5afc5dbb302edb 100644 --- a/test/parallel/test-process-redirect-warnings-env.js +++ b/test/parallel/test-process-redirect-warnings-env.js @@ -18,8 +18,7 @@ tmpdir.refresh(); const warnmod = require.resolve(fixtures.path('warnings.js')); const warnpath = path.join(tmpdir.path, 'warnings.txt'); -fork(warnmod, { env: Object.assign({}, process.env, - { NODE_REDIRECT_WARNINGS: warnpath }) }) +fork(warnmod, { env: { ...process.env, NODE_REDIRECT_WARNINGS: warnpath } }) .on('exit', common.mustCall(() => { fs.readFile(warnpath, 'utf8', common.mustCall((err, data) => { assert.ifError(err); diff --git a/test/parallel/test-stdin-script-child.js b/test/parallel/test-stdin-script-child.js index 06adc9e113eda7..7e73d82bfb5ab9 100644 --- a/test/parallel/test-stdin-script-child.js +++ b/test/parallel/test-stdin-script-child.js @@ -5,9 +5,9 @@ const assert = require('assert'); const { spawn } = require('child_process'); for (const args of [[], ['-']]) { const child = spawn(process.execPath, args, { - env: Object.assign({}, process.env, { - NODE_DEBUG: process.argv[2] - }) + env: { ...process.env, + NODE_DEBUG: process.argv[2] + } }); const wanted = `${child.pid}\n`; let found = ''; diff --git a/test/parallel/test-tls-env-bad-extra-ca.js b/test/parallel/test-tls-env-bad-extra-ca.js index 5167f586079187..5ba1e227d29ac0 100644 --- a/test/parallel/test-tls-env-bad-extra-ca.js +++ b/test/parallel/test-tls-env-bad-extra-ca.js @@ -16,10 +16,11 @@ if (process.env.CHILD) { return tls.createServer({}); } -const env = Object.assign({}, process.env, { +const env = { + ...process.env, CHILD: 'yes', NODE_EXTRA_CA_CERTS: `${fixtures.fixturesDir}/no-such-file-exists-🐢`, -}); +}; const opts = { env: env, diff --git a/test/parallel/test-tls-env-extra-ca-file-load.js b/test/parallel/test-tls-env-extra-ca-file-load.js index 85ee22b570e35e..2c6119f0a53d32 100644 --- a/test/parallel/test-tls-env-extra-ca-file-load.js +++ b/test/parallel/test-tls-env-extra-ca-file-load.js @@ -25,7 +25,7 @@ if (process.argv[2] !== 'child') { } } else { const NODE_EXTRA_CA_CERTS = fixtures.path('keys', 'ca1-cert.pem'); - const extendsEnv = (obj) => Object.assign({}, process.env, obj); + const extendsEnv = (obj) => ({ ...process.env, ...obj }); [ extendsEnv({ CHILD_USE_EXTRA_CA_CERTS: 'yes', NODE_EXTRA_CA_CERTS }), diff --git a/test/parallel/test-tls-env-extra-ca-no-crypto.js b/test/parallel/test-tls-env-extra-ca-no-crypto.js index 53b5ed03ea4849..6f2aca505e37e0 100644 --- a/test/parallel/test-tls-env-extra-ca-no-crypto.js +++ b/test/parallel/test-tls-env-extra-ca-no-crypto.js @@ -14,7 +14,7 @@ if (process.argv[2] === 'child') { fork( __filename, ['child'], - { env: Object.assign({}, process.env, { NODE_EXTRA_CA_CERTS }) }, + { env: { ...process.env, NODE_EXTRA_CA_CERTS } }, ).on('exit', common.mustCall(function(status) { // Client did not succeed in connecting assert.strictEqual(status, 0); diff --git a/test/parallel/test-tls-env-extra-ca.js b/test/parallel/test-tls-env-extra-ca.js index c6587ae414e440..7ac5ca3c86e5b5 100644 --- a/test/parallel/test-tls-env-extra-ca.js +++ b/test/parallel/test-tls-env-extra-ca.js @@ -32,11 +32,12 @@ const server = tls.createServer(options, common.mustCall(function(s) { s.end('bye'); server.close(); })).listen(0, common.mustCall(function() { - const env = Object.assign({}, process.env, { + const env = { + ...process.env, CHILD: 'yes', PORT: this.address().port, NODE_EXTRA_CA_CERTS: fixtures.path('keys', 'ca1-cert.pem') - }); + }; fork(__filename, { env }).on('exit', common.mustCall(function(status) { // Client did not succeed in connecting