@samitouri / QOS-React-2 / commits / 465b8dc646

test server middleware for receiving test results

Thomas Aylott committed Oct 31, 2013 at 13:26 UTC 465b8dc6466443d991fcb11e562059d541b674d1
2 files changed +35 -6
Gruntfile.js
+1 -1
@@ -17,7 +17,7 @@ module.exports = function(grunt) {
17 browserify: require('./grunt/config/browserify'),
18 populist: require('./grunt/config/populist'),
19 phantom: require('./grunt/config/phantom'),
20 - connect: require('./grunt/config/server'),
20 + connect: require('./grunt/config/server')(grunt),
21 "saucelabs-jasmine": require('./grunt/config/saucelabs-jasmine'),
22 npm: require('./grunt/config/npm'),
23 clean: ['./build', './*.gem', './docs/_site', './examples/shared/*.js'],
grunt/config/server.js
+34 -5
@@ -1,8 +1,37 @@
1 -module.exports = {
2 - server: {
3 - options: {
4 - base: "",
5 - port: 9999
1 +var pxlgif = Buffer('R0lGODlhAQABAIAAAP///wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==', 'base64');
2 +
3 +module.exports = function(grunt){
4 +
5 + function printMiddleware(req, res, next) {
6 + if (req._parsedUrl.pathname != '/print') return next();
7 + grunt[req.query.type || 'log'].writeln(req.query.message);
8 + res.end(pxlgif);
9 + }
10 + function testResultLoggerMiddleware(req, res, next) {
11 + if (!(req.body && req.body.data)) return next();
12 + grunt.log.writeln(req.body.data);
13 + res.end('Got it, thanks!');
14 + }
15 +
16 + return {
17 + server: {
18 + options: {
19 + base: '.',
20 + hostname: '*',
21 + port: 9999,
22 + middleware: function(connect, options) {
23 + return [
24 + connect.logger(':method :url - :referrer'),
25 +
26 + connect.query(),
27 + printMiddleware,
28 + connect.bodyParser(),
29 + testResultLoggerMiddleware,
30 +
31 + connect.static(options.base)
32 + ];
33 + },
34 + }
35 }
36 }
37 }