Skip to content

Commit 743564e

Browse files
committed
Server/CLI: Optimize console output
Only log screenshot URLs for failed tests, still always create them, can always be accessed on browserstack.com/automate. Degrade the "Exiting" logs to debug, not needed in normal operations. Update logs for finished workers to use less color, slightly more compact format. Fix bug in formatTraceback, where a falsy actual or expected value would cause nothing to be printed. Updates tests/test.rby to match the new finished console output.
1 parent 7514603 commit 743564e

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

bin/cli.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ function cleanUpAndExit(signal, status) {
9292
}
9393

9494
if (signal == 'SIGTERM') {
95-
logger.info("Exiting");
95+
logger.debug("Exiting");
9696
process.exit(status);
9797
} else {
9898
terminateAllWorkers(function() {
99-
logger.info("Exiting");
99+
logger.debug("Exiting");
100100
process.exit(1);
101101
});
102102
}

lib/server.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ exports.Server = function Server(bsClient, workers) {
144144
if (details.message) {
145145
output += ", " + details.message;
146146
}
147-
if (details.actual && details.expected) {
147+
if (details.actual != null && details.expected != null) {
148148
output += "\n" + chalk.blue("Expected: ") + details.expected +
149149
"\n" + chalk.blue(" Actual: ") + details.actual;
150150
}
@@ -187,7 +187,7 @@ exports.Server = function Server(bsClient, workers) {
187187
"_progress": function progressHandler(uri, body, request, response) {
188188
var uuid = request.headers['x-worker-uuid'];
189189
var worker = workers[uuid] || {};
190-
query = "";
190+
var query = null;
191191
try {
192192
query = parseBody(body);
193193
} catch(e) {
@@ -197,14 +197,14 @@ exports.Server = function Server(bsClient, workers) {
197197

198198
if (query.tracebacks) {
199199
query.tracebacks.forEach(function(traceback) {
200-
logger.info(chalk.red("[%s] Error:"), getTestBrowserInfo(worker), formatTraceback(traceback));
200+
logger.info("[%s] " + chalk.red("Error:"), getTestBrowserInfo(worker), formatTraceback(traceback));
201201
});
202202
}
203203
response.end();
204204
},
205205

206206
"_report": function reportHandler(uri, body, request, response) {
207-
query = null;
207+
var query = null;
208208
try {
209209
query = parseBody(body);
210210
} catch (e) {}
@@ -216,20 +216,21 @@ exports.Server = function Server(bsClient, workers) {
216216
logger.info("[%s] Null response from remote Browser", request.headers['x-browser-string']);
217217
} else {
218218
if (query.tracebacks && query.tracebacks.length > 0) {
219-
logger.info(chalk["red"]("[%s] Tracebacks:"), getTestBrowserInfo(worker));
219+
logger.info("[%s] " + chalk["red"]("Tracebacks:"), getTestBrowserInfo(worker));
220220
query.tracebacks.forEach(function(traceback) {
221221
logger.info(traceback);
222222
});
223223
}
224224
var color = query.failed ? "red" : "green";
225-
logger.info(chalk[color]("[%s] Completed in %d milliseconds. %d of %d passed, %d failed."), getTestBrowserInfo(worker), query.runtime, query.passed, query.total, query.failed);
225+
logger.info("[%s] " + chalk[color](query.failed ? "Failed:" : "Passed:") + " %d tests, %d passed, %d failed; ran for %dms", getTestBrowserInfo(worker), query.total, query.passed, query.failed, query.runtime);
226226
config.status += query.failed;
227227
}
228228

229+
// TODO remove this check, must always be true due to `worker` usage above
229230
if (worker) {
230231
bsClient.takeScreenshot(worker.id, function(error, screenshot) {
231-
if (!error && screenshot.url) {
232-
logger.info('[%s] ' + chalk['yellow']('Screenshot') + ': %s', getTestBrowserInfo(worker), screenshot.url);
232+
if (!error && screenshot.url && query && query.failed) {
233+
logger.info('[%s] ' + chalk.yellow('Screenshot:') + ' %s', getTestBrowserInfo(worker), screenshot.url);
233234
}
234235

235236
checkAndTerminateWorker(worker, function(reusedWorker) {

tests/test.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def runBg(cmd, linestomatch, genre, test_strings)
1212
matched_counter = 0
1313
IO.popen(cmd) {|io|
1414
io.each {|line|
15-
if line.match(/Completed in /)
15+
if line.match(/ran for/)
1616
counter += 1
1717
puts "[#{genre.upcase}] : " + line
1818
test_strings.each do |test_string|
@@ -45,27 +45,27 @@ def run_project(reponame, test_framework, passed_array, browser_url)
4545
sleep(1)
4646
execute("cd #{repo_path}#{reponame} && git clean -f -d && git reset --hard")
4747
end
48-
48+
4949
def qunit
50-
run_project("underscorejs", "qunit", ["631 of 631 passed"], "test/index.html")
51-
run_project("Modernizr", "qunit", ["20 of 41 passed"], "test/index.html")
50+
run_project("underscorejs", "qunit", ["631 passed"], "test/index.html")
51+
run_project("Modernizr", "qunit", ["20 passed"], "test/index.html")
5252
# https://github.com/bitovi/funcunit/
5353
# https://github.com/twbs/bootstrap
5454
end
5555

5656
def mocha
57-
run_project("url.js", "mocha", ["35 of 35 passed"], "test.html")
57+
run_project("url.js", "mocha", ["35 passed"], "test.html")
5858
# https://github.com/browserstack/microjungle
5959
# https://github.com/dhimil/mocha
6060
# https://github.com/auth0/auth0.js
6161
end
6262

6363
def jasmine
64-
run_project("mout", "jasmine", ["978 of 978 passed"], "tests/runner.html")
64+
run_project("mout", "jasmine", ["978 passed"], "tests/runner.html")
6565
end
6666

6767
def jasmine2
68-
run_project("Comparatorsjs", "jasmine2", ["6 of 6 passed"], "comparators.spec-runner.html")
68+
run_project("Comparatorsjs", "jasmine2", ["6 passed"], "comparators.spec-runner.html")
6969
end
7070

7171
def run

0 commit comments

Comments
 (0)