0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/pummel/test-child-process-spawn-loop.js
sivaprasanna 41567ee9d8 test: refactor the code in test-child-process-spawn-loop.js
* use const and let instead of var
* use assert.strictEqual instead of assert.equal
* use arrow functions

PR-URL: https://github.com/nodejs/node/pull/10605
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-01-09 09:36:11 -08:00

40 lines
794 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const spawn = require('child_process').spawn;
const SIZE = 1000 * 1024;
const N = 40;
let finished = false;
function doSpawn(i) {
const child = spawn('python', ['-c', 'print ' + SIZE + ' * "C"']);
let count = 0;
child.stdout.setEncoding('ascii');
child.stdout.on('data', (chunk) => {
count += chunk.length;
});
child.stderr.on('data', (chunk) => {
console.log('stderr: ' + chunk);
});
child.on('close', () => {
// + 1 for \n or + 2 for \r\n on Windows
assert.strictEqual(SIZE + (common.isWindows ? 2 : 1), count);
if (i < N) {
doSpawn(i + 1);
} else {
finished = true;
}
});
}
doSpawn(0);
process.on('exit', () => {
assert.ok(finished);
});