2016-02-01 20:13:31 +01:00
|
|
|
'use strict';
|
2016-07-18 22:33:42 +02:00
|
|
|
const common = require('../common');
|
2016-02-01 20:13:31 +01:00
|
|
|
const path = require('path');
|
|
|
|
const spawn = require('child_process').spawn;
|
|
|
|
const assert = require('assert');
|
|
|
|
|
|
|
|
const fixture = path.join(
|
|
|
|
common.fixturesDir,
|
|
|
|
'debugger-util-regression-fixture.js'
|
|
|
|
);
|
|
|
|
|
|
|
|
const args = [
|
|
|
|
'debug',
|
2016-04-15 15:38:04 +02:00
|
|
|
`--port=${common.PORT}`,
|
2016-02-01 20:13:31 +01:00
|
|
|
fixture
|
|
|
|
];
|
|
|
|
|
|
|
|
const proc = spawn(process.execPath, args, { stdio: 'pipe' });
|
|
|
|
proc.stdout.setEncoding('utf8');
|
|
|
|
proc.stderr.setEncoding('utf8');
|
|
|
|
|
|
|
|
let stdout = '';
|
|
|
|
let stderr = '';
|
|
|
|
|
|
|
|
let nextCount = 0;
|
2016-11-06 13:50:52 +01:00
|
|
|
let exit = false;
|
2016-02-01 20:13:31 +01:00
|
|
|
|
|
|
|
proc.stdout.on('data', (data) => {
|
|
|
|
stdout += data;
|
|
|
|
if (stdout.includes('> 1') && nextCount < 1 ||
|
|
|
|
stdout.includes('> 2') && nextCount < 2 ||
|
|
|
|
stdout.includes('> 3') && nextCount < 3 ||
|
|
|
|
stdout.includes('> 4') && nextCount < 4) {
|
|
|
|
nextCount++;
|
|
|
|
proc.stdin.write('n\n');
|
2016-11-06 13:50:52 +01:00
|
|
|
} else if (!exit && (stdout.includes('< { a: \'b\' }'))) {
|
|
|
|
exit = true;
|
2016-02-01 20:13:31 +01:00
|
|
|
proc.stdin.write('.exit\n');
|
2016-07-09 02:17:47 +02:00
|
|
|
} else if (stdout.includes('program terminated')) {
|
2016-02-01 20:13:31 +01:00
|
|
|
// Catch edge case present in v4.x
|
|
|
|
// process will terminate after call to util.inspect
|
|
|
|
common.fail('the program should not terminate');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
proc.stderr.on('data', (data) => stderr += data);
|
|
|
|
|
|
|
|
process.on('exit', (code) => {
|
2016-12-01 17:19:10 +01:00
|
|
|
assert.strictEqual(code, 0, 'the program should exit cleanly');
|
|
|
|
assert.strictEqual(stdout.includes('{ a: \'b\' }'), true,
|
|
|
|
'the debugger should print the result of util.inspect');
|
|
|
|
assert.strictEqual(stderr, '', 'stderr should be empty');
|
2016-02-01 20:13:31 +01:00
|
|
|
});
|