Skip to content
This repository was archived by the owner on Jan 27, 2026. It is now read-only.

Commit 40c6454

Browse files
committed
verbose test runner; don't exit until debug server stopped and output received
1 parent 011d2c6 commit 40c6454

6 files changed

Lines changed: 69 additions & 16 deletions

File tree

test/_helper.js

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,12 @@ var CLI = require("cli"),
6262
ASSERT = require("assert"),
6363
SOCKET_IO_CLIENT = require("socket.io-client"),
6464
XML2JS = require("xml2js"),
65-
NET = require("net"),
66-
EXEC = require("child_process").exec;
65+
NET = require("net");
6766

6867

6968
var serverInfo = {},
70-
ourServer = false, // if we started the debug proxy server
71-
verboseServerLog = false;
69+
serverChildInstance = null,
70+
ourServer = false; // if we started the debug proxy server
7271

7372

7473
exports.getTestTimeout = function(extra)
@@ -116,7 +115,8 @@ exports.debugScript = function(name, sessionName)
116115
'export XDEBUG_CONFIG="' + 'idekey=' + ((serverInfo.idekey)?serverInfo.idekey:'') + ',session=' + sessionName + '";',
117116
"php " + PATH.dirname(PATH.dirname(module.id)) + "/php/scripts/" + name + ".php"
118117
].join(" "), function (error, stdout, stderr) {
119-
// console.log("[debugScript][stdout] " + stdout);
118+
if (serverInfo.verbose)
119+
console.log("[debugScript][stdout] " + stdout);
120120
if (stderr)
121121
console.log("[debugScript][stderr] " + stderr);
122122
});
@@ -126,6 +126,7 @@ exports.ready = function(callback)
126126
{
127127
// See: https://github.com/chriso/cli/blob/master/examples/static.js
128128
CLI.parse({
129+
verbose: ["v", 'Log major events to console', 'boolean', false],
129130
port: [false, 'Listen on this port', 'number', PROXY_PORT],
130131
php: [false, 'Hostname for `../php/`', 'string', PHP_VHOST],
131132
'skip-browser-tests': [false, 'Skip browser tests?', 'boolean', false],
@@ -148,6 +149,11 @@ exports.ready = function(callback)
148149
});
149150
}
150151

152+
exports.done = function(callback)
153+
{
154+
stopServer(callback);
155+
}
156+
151157
exports.fatalExit = function fatalExit(message)
152158
{
153159
UTIL.debug("Error: " + message + "\n");
@@ -194,6 +200,17 @@ function testConnection()
194200
return result.promise;
195201
}
196202

203+
function stopServer(callback)
204+
{
205+
if (serverChildInstance===null)
206+
return;
207+
serverChildInstance.on("exit", function()
208+
{
209+
callback();
210+
});
211+
serverChildInstance.kill();
212+
}
213+
197214
function startServer()
198215
{
199216
var result = Q.defer();
@@ -204,14 +221,12 @@ function startServer()
204221

205222
console.log("Starting proxy server: " + command);
206223

207-
EXEC(command, function (error, stdout, stderr)
224+
serverChildInstance = EXEC(command, function (error, stdout, stderr)
208225
{
209-
// Ignore (server has stopped after stopServer() was called)
210-
// NOTE: The following will only print if there was an error and the server stopped prematurely
211-
if (verboseServerLog)
226+
if (serverInfo.verbose)
212227
console.error("[proxyServer] " + stdout.split("\n").join("\n[proxyServer] ") + "\n");
213228
});
214-
229+
215230
// Give server 500ms to start up
216231
var counter = 0;
217232
var intervalID = setInterval(function()
@@ -241,10 +256,18 @@ function startServer()
241256
}
242257

243258
// Ping server for as long as the test script runs
259+
var pingIntervalID = null;
244260
Q.when(result.promise, function()
245261
{
246262
ping();
247-
setInterval(ping, 300);
263+
pingIntervalID = setInterval(ping, 300);
264+
});
265+
266+
serverChildInstance.on("exit", function()
267+
{
268+
if (pingIntervalID!==null)
269+
clearInterval(pingIntervalID);
270+
serverChildInstance = null;
248271
});
249272

250273
return result.promise;

test/all.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,11 @@ HELPER.ready(function()
4545
require("./session"),
4646
require("./stepping"),
4747
require("./breakpoints")
48-
).exec()
48+
).run().report().summary(function(err, passed)
49+
{
50+
HELPER.done(function()
51+
{
52+
process.exit(!err && passed ? 0 : 1);
53+
});
54+
});
4955
});

test/breakpoints.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,5 +183,11 @@ module.exports = require("../support/asyncjs/lib/test").testcase(Test);
183183

184184
if (module === require.main)
185185
HELPER.ready(function() {
186-
module.exports.exec();
186+
module.exports.run().report().summary(function(err, passed)
187+
{
188+
HELPER.done(function()
189+
{
190+
process.exit(!err && passed ? 0 : 1);
191+
});
192+
});
187193
});

test/connection.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,11 @@ module.exports = require("../support/asyncjs/lib/test").testcase(Test);
6868

6969
if (module === require.main)
7070
HELPER.ready(function() {
71-
module.exports.exec();
71+
module.exports.run().report().summary(function(err, passed)
72+
{
73+
HELPER.done(function()
74+
{
75+
process.exit(!err && passed ? 0 : 1);
76+
});
77+
});
7278
});

test/session.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,11 @@ module.exports = require("../support/asyncjs/lib/test").testcase(Test);
128128

129129
if (module === require.main)
130130
HELPER.ready(function() {
131-
module.exports.exec();
131+
module.exports.run().report().summary(function(err, passed)
132+
{
133+
HELPER.done(function()
134+
{
135+
process.exit(!err && passed ? 0 : 1);
136+
});
137+
});
132138
});

test/stepping.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,5 +321,11 @@ module.exports = require("../support/asyncjs/lib/test").testcase(Test);
321321

322322
if (module === require.main)
323323
HELPER.ready(function() {
324-
module.exports.exec();
324+
module.exports.run().report().summary(function(err, passed)
325+
{
326+
HELPER.done(function()
327+
{
328+
process.exit(!err && passed ? 0 : 1);
329+
});
330+
});
325331
});

0 commit comments

Comments
 (0)