Skip to content

Commit 4022617

Browse files
franhertargos
authored andcommitted
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 <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 39dbc10 commit 4022617

23 files changed

+31
-31
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { spawnSync } = require('child_process');
2-
const env = Object.assign({}, process.env, { NODE_V8_COVERAGE: '' });
2+
const env = { ...process.env, NODE_V8_COVERAGE: '' };
33
spawnSync(process.execPath, [require.resolve('./subprocess')], {
44
env: env
55
});

test/fixtures/v8-coverage/spawn-subprocess.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { spawnSync } = require('child_process');
2-
const env = Object.assign({}, process.env);
2+
const env = { ...process.env };
33
delete env.NODE_V8_COVERAGE
44
spawnSync(process.execPath, [require.resolve('./subprocess')], {
55
env: env

test/parallel/test-child-process-env.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ const os = require('os');
2626

2727
const spawn = require('child_process').spawn;
2828

29-
const env = Object.assign({}, process.env, {
29+
const env = {
30+
...process.env,
3031
'HELLO': 'WORLD',
3132
'UNDEFINED': undefined,
3233
'NULL': null,
3334
'EMPTY': ''
34-
});
35+
};
3536
Object.setPrototypeOf(env, {
3637
'FOO': 'BAR'
3738
});

test/parallel/test-child-process-exec-env.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ if (!common.isWindows) {
4545
child = exec('/usr/bin/env', { env: { 'HELLO': 'WORLD' } }, after);
4646
} else {
4747
child = exec('set',
48-
{ env: Object.assign({}, process.env, { 'HELLO': 'WORLD' }) },
48+
{ env: { ...process.env, 'HELLO': 'WORLD' } },
4949
after);
5050
}
5151

test/parallel/test-child-process-fork-no-shell.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const expected = common.isWindows ? '%foo%' : '$foo';
88
if (process.argv[2] === undefined) {
99
const child = cp.fork(__filename, [expected], {
1010
shell: true,
11-
env: Object.assign({}, process.env, { foo: 'bar' })
11+
env: { ...process.env, foo: 'bar' }
1212
});
1313

1414
child.on('exit', common.mustCall((code, signal) => {

test/parallel/test-child-process-spawn-shell.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ command.on('close', common.mustCall((code, signal) => {
5050

5151
// Verify that the environment is properly inherited
5252
const env = cp.spawn(`"${process.execPath}" -pe process.env.BAZ`, {
53-
env: Object.assign({}, process.env, { BAZ: 'buzz' }),
53+
env: { ...process.env, BAZ: 'buzz' },
5454
encoding: 'utf8',
5555
shell: true
5656
});

test/parallel/test-child-process-spawnsync-shell.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ assert.strictEqual(command.stdout.toString().trim(), 'bar');
3737

3838
// Verify that the environment is properly inherited
3939
const env = cp.spawnSync(`"${process.execPath}" -pe process.env.BAZ`, {
40-
env: Object.assign({}, process.env, { BAZ: 'buzz' }),
40+
env: { ...process.env, BAZ: 'buzz' },
4141
shell: true
4242
});
4343

test/parallel/test-cli-node-options-disallowed.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ disallow('--v8-options');
2828
disallow('--');
2929

3030
function disallow(opt) {
31-
const env = Object.assign({}, process.env, { NODE_OPTIONS: opt });
31+
const env = { ...process.env, NODE_OPTIONS: opt };
3232
exec(process.execPath, { cwd: tmpdir.path, env }, common.mustCall((err) => {
3333
const message = err.message.split(/\r?\n/)[1];
3434
const expect = `${process.execPath}: ${opt} is not allowed in NODE_OPTIONS`;

test/parallel/test-crypto-fips.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ testHelper(
7171
[],
7272
FIPS_DISABLED,
7373
'require("crypto").getFips()',
74-
Object.assign({}, process.env, { 'OPENSSL_CONF': '' }));
74+
{ ...process.env, 'OPENSSL_CONF': '' });
7575

7676
// --enable-fips should turn FIPS mode on
7777
testHelper(

test/parallel/test-env-var-no-warnings.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if (process.argv[2] === 'child') {
77
process.emitWarning('foo');
88
} else {
99
function test(newEnv) {
10-
const env = Object.assign({}, process.env, newEnv);
10+
const env = { ...process.env, ...newEnv };
1111
const cmd = `"${process.execPath}" "${__filename}" child`;
1212

1313
cp.exec(cmd, { env }, common.mustCall((err, stdout, stderr) => {

test/parallel/test-fs-readfile-error.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const fixtures = require('../common/fixtures');
3737
function test(env, cb) {
3838
const filename = fixtures.path('test-fs-readfile-error.js');
3939
const execPath = `"${process.execPath}" "${filename}"`;
40-
const options = { env: Object.assign({}, process.env, env) };
40+
const options = { env: { ...process.env, ...env } };
4141
exec(execPath, options, (err, stdout, stderr) => {
4242
assert(err);
4343
assert.strictEqual(stdout, '');

test/parallel/test-http-server-stale-close.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ if (process.env.NODE_TEST_FORK_PORT) {
4444
});
4545
server.listen(0, function() {
4646
fork(__filename, {
47-
env: Object.assign({}, process.env, {
48-
NODE_TEST_FORK_PORT: this.address().port
49-
})
47+
env: { ...process.env, NODE_TEST_FORK_PORT: this.address().port }
5048
});
5149
});
5250
}

test/parallel/test-https-agent-additional-options.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function variations(iter, port, cb) {
6363
// Save `value` for check the next time.
6464
value = next.value.val;
6565
const [key, val] = next.value;
66-
https.get(Object.assign({}, getBaseOptions(port), { [key]: val }),
66+
https.get({ ...getBaseOptions(port), [key]: val },
6767
variations(iter, port, cb));
6868
}
6969
}));

test/parallel/test-icu-data-dir.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const expected =
2121
}
2222

2323
{
24-
const env = Object.assign({}, process.env, { NODE_ICU_DATA: '/' });
24+
const env = { ...process.env, NODE_ICU_DATA: '/' };
2525
const child = spawnSync(process.execPath, ['-e', '0'], { env });
2626
assert(child.stderr.toString().includes(expected));
2727
}

test/parallel/test-module-loading-globalpaths.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ if (process.argv[2] === 'child') {
4141

4242
const testFixturesDir = fixtures.path(path.basename(__filename, '.js'));
4343

44-
const env = Object.assign({}, process.env);
44+
const env = { ...process.env };
4545
// Unset NODE_PATH.
4646
delete env.NODE_PATH;
4747

test/parallel/test-net-connect-options-fd.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ tmpdir.refresh();
1515

1616
function testClients(getSocketOpt, getConnectOpt, getConnectCb) {
1717
const cloneOptions = (index) =>
18-
Object.assign({}, getSocketOpt(index), getConnectOpt(index));
18+
({ ...getSocketOpt(index), ...getConnectOpt(index) });
1919
return [
2020
net.connect(cloneOptions(0), getConnectCb(0)),
2121
net.connect(cloneOptions(1))

test/parallel/test-pending-deprecation.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ switch (process.argv[2]) {
5555

5656
// Test the NODE_PENDING_DEPRECATION environment var.
5757
fork(__filename, ['env'], {
58-
env: Object.assign({}, process.env, { NODE_PENDING_DEPRECATION: 1 }),
58+
env: { ...process.env, NODE_PENDING_DEPRECATION: 1 },
5959
execArgv: ['--expose-internals'],
6060
silent: true
6161
}).on('exit', common.mustCall((code) => {

test/parallel/test-process-redirect-warnings-env.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ tmpdir.refresh();
1818
const warnmod = require.resolve(fixtures.path('warnings.js'));
1919
const warnpath = path.join(tmpdir.path, 'warnings.txt');
2020

21-
fork(warnmod, { env: Object.assign({}, process.env,
22-
{ NODE_REDIRECT_WARNINGS: warnpath }) })
21+
fork(warnmod, { env: { ...process.env, NODE_REDIRECT_WARNINGS: warnpath } })
2322
.on('exit', common.mustCall(() => {
2423
fs.readFile(warnpath, 'utf8', common.mustCall((err, data) => {
2524
assert.ifError(err);

test/parallel/test-stdin-script-child.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ const assert = require('assert');
55
const { spawn } = require('child_process');
66
for (const args of [[], ['-']]) {
77
const child = spawn(process.execPath, args, {
8-
env: Object.assign({}, process.env, {
9-
NODE_DEBUG: process.argv[2]
10-
})
8+
env: { ...process.env,
9+
NODE_DEBUG: process.argv[2]
10+
}
1111
});
1212
const wanted = `${child.pid}\n`;
1313
let found = '';

test/parallel/test-tls-env-bad-extra-ca.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ if (process.env.CHILD) {
1616
return tls.createServer({});
1717
}
1818

19-
const env = Object.assign({}, process.env, {
19+
const env = {
20+
...process.env,
2021
CHILD: 'yes',
2122
NODE_EXTRA_CA_CERTS: `${fixtures.fixturesDir}/no-such-file-exists-🐢`,
22-
});
23+
};
2324

2425
const opts = {
2526
env: env,

test/parallel/test-tls-env-extra-ca-file-load.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if (process.argv[2] !== 'child') {
2525
}
2626
} else {
2727
const NODE_EXTRA_CA_CERTS = fixtures.path('keys', 'ca1-cert.pem');
28-
const extendsEnv = (obj) => Object.assign({}, process.env, obj);
28+
const extendsEnv = (obj) => ({ ...process.env, ...obj });
2929

3030
[
3131
extendsEnv({ CHILD_USE_EXTRA_CA_CERTS: 'yes', NODE_EXTRA_CA_CERTS }),

test/parallel/test-tls-env-extra-ca-no-crypto.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if (process.argv[2] === 'child') {
1414
fork(
1515
__filename,
1616
['child'],
17-
{ env: Object.assign({}, process.env, { NODE_EXTRA_CA_CERTS }) },
17+
{ env: { ...process.env, NODE_EXTRA_CA_CERTS } },
1818
).on('exit', common.mustCall(function(status) {
1919
// Client did not succeed in connecting
2020
assert.strictEqual(status, 0);

test/parallel/test-tls-env-extra-ca.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ const server = tls.createServer(options, common.mustCall(function(s) {
3232
s.end('bye');
3333
server.close();
3434
})).listen(0, common.mustCall(function() {
35-
const env = Object.assign({}, process.env, {
35+
const env = {
36+
...process.env,
3637
CHILD: 'yes',
3738
PORT: this.address().port,
3839
NODE_EXTRA_CA_CERTS: fixtures.path('keys', 'ca1-cert.pem')
39-
});
40+
};
4041

4142
fork(__filename, { env }).on('exit', common.mustCall(function(status) {
4243
// Client did not succeed in connecting

0 commit comments

Comments
 (0)