Browse Source

test: improve child_process tests

Replaced var keyword with const and let in the tests for child process
stdin and stdio.

PR-URL: https://github.com/nodejs/node/pull/8617
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
v7.x
Dennis Schwartz 8 years ago
committed by Ilkka Myller
parent
commit
366495d4e2
  1. 10
      test/parallel/test-child-process-stdin.js
  2. 16
      test/parallel/test-child-process-stdio-big-write-end.js
  3. 8
      test/parallel/test-child-process-stdio.js

10
test/parallel/test-child-process-stdin.js

@ -1,10 +1,10 @@
'use strict'; 'use strict';
var common = require('../common'); const common = require('../common');
var assert = require('assert'); const assert = require('assert');
var spawn = require('child_process').spawn; const spawn = require('child_process').spawn;
var cat = spawn(common.isWindows ? 'more' : 'cat'); const cat = spawn(common.isWindows ? 'more' : 'cat');
cat.stdin.write('hello'); cat.stdin.write('hello');
cat.stdin.write(' '); cat.stdin.write(' ');
cat.stdin.write('world'); cat.stdin.write('world');
@ -14,7 +14,7 @@ assert.ok(!cat.stdin.readable);
cat.stdin.end(); cat.stdin.end();
var response = ''; let response = '';
cat.stdout.setEncoding('utf8'); cat.stdout.setEncoding('utf8');
cat.stdout.on('data', function(chunk) { cat.stdout.on('data', function(chunk) {

16
test/parallel/test-child-process-stdio-big-write-end.js

@ -1,7 +1,7 @@
'use strict'; 'use strict';
require('../common'); require('../common');
var assert = require('assert'); const assert = require('assert');
var BUFSIZE = 1024; const BUFSIZE = 1024;
switch (process.argv[2]) { switch (process.argv[2]) {
case undefined: case undefined:
@ -13,11 +13,11 @@ switch (process.argv[2]) {
} }
function parent() { function parent() {
var spawn = require('child_process').spawn; const spawn = require('child_process').spawn;
var child = spawn(process.execPath, [__filename, 'child']); const child = spawn(process.execPath, [__filename, 'child']);
var sent = 0; let sent = 0;
var n = ''; let n = '';
child.stdout.setEncoding('ascii'); child.stdout.setEncoding('ascii');
child.stdout.on('data', function(c) { child.stdout.on('data', function(c) {
n += c; n += c;
@ -34,7 +34,7 @@ function parent() {
} while (child.stdin.write(buf)); } while (child.stdin.write(buf));
// then write a bunch more times. // then write a bunch more times.
for (var i = 0; i < 100; i++) { for (let i = 0; i < 100; i++) {
const buf = Buffer.alloc(BUFSIZE, '.'); const buf = Buffer.alloc(BUFSIZE, '.');
sent += BUFSIZE; sent += BUFSIZE;
child.stdin.write(buf); child.stdin.write(buf);
@ -47,7 +47,7 @@ function parent() {
} }
function child() { function child() {
var received = 0; let received = 0;
process.stdin.on('data', function(c) { process.stdin.on('data', function(c) {
received += c.length; received += c.length;
}); });

8
test/parallel/test-child-process-stdio.js

@ -1,9 +1,9 @@
'use strict'; 'use strict';
var common = require('../common'); const common = require('../common');
var assert = require('assert'); const assert = require('assert');
var options = {stdio: ['pipe']}; let options = {stdio: ['pipe']};
var child = common.spawnPwd(options); let child = common.spawnPwd(options);
assert.notEqual(child.stdout, null); assert.notEqual(child.stdout, null);
assert.notEqual(child.stderr, null); assert.notEqual(child.stderr, null);

Loading…
Cancel
Save