Skip to content
Permalink
Browse files

test: use spread object

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 BridgeAR committed Nov 12, 2019
1 parent d3a8088 commit bd6a29c60b2f82c1883b1ba4c38abd2c3d16b4d4
@@ -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
});
@@ -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
@@ -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'
});
@@ -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);
}

@@ -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) => {
@@ -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
});
@@ -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
});

@@ -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`;
@@ -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(
@@ -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) => {
@@ -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, '');
@@ -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 }
});
});
}
@@ -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));
}
}));
@@ -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));
}
@@ -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;

@@ -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))
@@ -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) => {
@@ -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);
@@ -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 = '';
@@ -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,
@@ -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 }),
@@ -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);
@@ -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

0 comments on commit bd6a29c

Please sign in to comment.
You can’t perform that action at this time.