diff --git a/grunt/config/server.js b/grunt/config/server.js index c91165b1de10e..3e43e07f7c080 100644 --- a/grunt/config/server.js +++ b/grunt/config/server.js @@ -1,8 +1,18 @@ module.exports = function(grunt){ function testResultLoggerMiddleware(req, res, next) { - if (!(req.body && req.body.data)) return next(); - grunt.log.writeln('[%s][%s]', req.headers['user-agent'], Date.now(), req.body.data); + if (!(req.method == 'POST' && req._parsedUrl.pathname.indexOf('/reportTestResults') === 0)) return next(); + var logType = 'writeln'; + var message = req.body; + + if (req.body.type && req.body.message){ + if (req.body.type == 'error') logType = 'error'; + else if (req.body.message.indexOf('ok') === 0) logType = 'ok'; + else if (req.body.message.indexOf('not ok') === 0) logType = 'error'; + message = req.body.message; + } + if (typeof message != 'string') message = JSON.stringify(message, null, 2); + grunt.log[logType]('[%s][%s]', req.headers['user-agent'], Date.now(), message); res.write(''); res.end('Got it, thanks!'); } @@ -19,10 +29,10 @@ module.exports = function(grunt){ connect.logger.token('timestamp', function(req, res){ return Date.now(); }); return [ - connect.logger({format:'[:user-agent][:timestamp] :method :url', stream:grunt.verbose}), - connect.bodyParser(), + connect.json(), testResultLoggerMiddleware, + connect.logger({format:'[:user-agent][:timestamp] :method :url', stream:grunt.verbose}), connect.static(options.base), connect.directory(options.base) ]; diff --git a/test/lib/reportTestResults.browser.js b/test/lib/reportTestResults.browser.js index d18ea2ff7fe64..ea4435ea47df6 100644 --- a/test/lib/reportTestResults.browser.js +++ b/test/lib/reportTestResults.browser.js @@ -42,8 +42,8 @@ function postDataToURL(data, url, callback) { callback(request.status == 200 ? null : request.status, request.responseText); }; request.open('POST', url); - request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); - request.send('data=' + encodeURIComponent(JSON.stringify(data))); + request.setRequestHeader('Content-Type', 'application/json'); + request.send(JSON.stringify(data)); } postDataToURL.defaultCallback = function(error){ // console.log('postDataToURL.defaultCallback', arguments)