From 47e6608683e0ac708d87efc3da19718c59184d1c Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Wed, 25 Aug 2021 10:53:06 -0700 Subject: [PATCH] browser_reporting.js: report stderr and stdout back to server This means that anything send to stdout or stderr during browser testing is reports back to server which is especially useful in headless testing which is used in our CI. --- tests/browser_reporting.js | 24 ++++++++++++++++++++++-- tests/common.py | 9 --------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/tests/browser_reporting.js b/tests/browser_reporting.js index eb04d5b5d9135..c675fe3656476 100644 --- a/tests/browser_reporting.js +++ b/tests/browser_reporting.js @@ -6,7 +6,7 @@ function reportResultToServer(result, sync, port) { port = port || 8888; if (reportResultToServer.reported) { // Only report one result per test, even if the test misbehaves and tries to report more. - reportErrorToServer("excessive reported results, sending " + result + ", test will fail"); + reportStderrToServer("excessive reported results, sending " + result + ", test will fail"); } reportResultToServer.reported = true; var xhr = new XMLHttpRequest(); @@ -25,12 +25,18 @@ function maybeReportResultToServer(result, sync, port) { reportResultToServer(result, sync, port); } -function reportErrorToServer(message) { +function reportStderrToServer(message) { var xhr = new XMLHttpRequest(); xhr.open('GET', encodeURI('http://localhost:8888?stderr=' + message)); xhr.send(); } +function reportStdoutToServer(message) { + var xhr = new XMLHttpRequest(); + xhr.open('GET', encodeURI('http://localhost:8888?stdout=' + message)); + xhr.send(); +} + if (typeof window === 'object' && window) { function report_error(e) { // MINIMAL_RUNTIME doesn't handle exit or call the below onExit handler @@ -62,4 +68,18 @@ if (hasModule) { Module['onAbort'] = function(reason) { maybeReportResultToServer('abort:' + reason); } + + var oldPrint = Module['print']; + Module['print'] = function() { + reportStdoutToServer(Array.prototype.slice.call(arguments).join(' ')); + if (oldPrint) + oldPrint.apply(null, arguments); + } + + var oldPrintErr = Module['printErr']; + Module['printErr'] = function() { + reportStderrToServer(Array.prototype.slice.call(arguments).join(' ')); + if (oldPrintErr) + oldPrintErr.apply(null, arguments); + } } diff --git a/tests/common.py b/tests/common.py index 5f8cf92e1044a..02ea0073591cf 100644 --- a/tests/common.py +++ b/tests/common.py @@ -1199,16 +1199,7 @@ def do_GET(self): self.send_header('Expires', '-1') self.end_headers() self.wfile.write(b'OK') - elif 'stdout=' in self.path or 'stderr=' in self.path or 'exception=' in self.path: - ''' - To get logging to the console from browser tests, add this to - print/printErr/the exception handler in src/shell.html: - - var xhr = new XMLHttpRequest(); - xhr.open('GET', encodeURI('http://localhost:8888?stdout=' + text)); - xhr.send(); - ''' print('[client logging:', unquote_plus(self.path), ']') self.send_response(200) self.send_header('Content-type', 'text/html')