Skip to content

Commit

Permalink
test: use spread object
Browse files Browse the repository at this point in the history
Object.assign() can be replaced by spread objects

PR-URL: #30423
Refs: https://eslint.org/docs/rules/prefer-object-spread
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
franher authored and BethGriggs committed Feb 6, 2020
1 parent deb1a59 commit 05ef4bd
Show file tree
Hide file tree
Showing 23 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion 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
});
2 changes: 1 addition & 1 deletion 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
Expand Down
5 changes: 3 additions & 2 deletions test/parallel/test-child-process-env.js
Expand Up @@ -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'
});
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-child-process-exec-env.js
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-child-process-fork-no-shell.js
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-child-process-spawn-shell.js
Expand Up @@ -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
});
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-child-process-spawnsync-shell.js
Expand Up @@ -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
});

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-cli-node-options-disallowed.js
Expand Up @@ -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`;
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-crypto-fips.js
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-env-var-no-warnings.js
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-readfile-error.js
Expand Up @@ -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, '');
Expand Down
4 changes: 1 addition & 3 deletions test/parallel/test-http-server-stale-close.js
Expand Up @@ -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 }
});
});
}
2 changes: 1 addition & 1 deletion test/parallel/test-https-agent-additional-options.js
Expand Up @@ -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));
}
}));
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-icu-data-dir.js
Expand Up @@ -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));
}
2 changes: 1 addition & 1 deletion test/parallel/test-module-loading-globalpaths.js
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-net-connect-options-fd.js
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-pending-deprecation.js
Expand Up @@ -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) => {
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-process-redirect-warnings-env.js
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-stdin-script-child.js
Expand Up @@ -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 = '';
Expand Down
5 changes: 3 additions & 2 deletions test/parallel/test-tls-env-bad-extra-ca.js
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-tls-env-extra-ca-file-load.js
Expand Up @@ -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 }),
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-tls-env-extra-ca-no-crypto.js
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions test/parallel/test-tls-env-extra-ca.js
Expand Up @@ -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
Expand Down

0 comments on commit 05ef4bd

Please sign in to comment.