From 8956e081adbe61d22bbd2d7c26962d58826152c6 Mon Sep 17 00:00:00 2001 From: Stanley Ng Date: Tue, 5 Aug 2014 22:04:27 -0700 Subject: [PATCH 1/2] updated README.md to include options.output --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index fc411c6..588c488 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,11 @@ Default value: `false` If true, protractor will not give colored output. If false, protractor will give colored output, as it does by default. +#### options.output +Type: `String` + +The file that the task should output the results to. + #### options.debug Type: `Boolean` Default value: `false` From 61d55aafcf2ad736231b3f666d20ee734d9aa50e Mon Sep 17 00:00:00 2001 From: Stanley Ng Date: Tue, 5 Aug 2014 23:47:38 -0700 Subject: [PATCH 2/2] implement the logic to write the reuslt to a file if options.output is defined --- README.md | 11 ++++++----- package.json | 4 +++- tasks/protractor_runner.js | 33 ++++++++++++++++++++++++++++++--- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 588c488..704b336 100644 --- a/README.md +++ b/README.md @@ -68,11 +68,6 @@ Default value: `false` If true, protractor will not give colored output. If false, protractor will give colored output, as it does by default. -#### options.output -Type: `String` - -The file that the task should output the results to. - #### options.debug Type: `Boolean` Default value: `false` @@ -107,6 +102,12 @@ Supported arguments are below. * cucumberOpts `object`: Cucumber framework options object to be passed to the test, e.g. require, tags and format * mochaOpts `object`: Mocha test framework options object to be passed +#### options.output +Type: `String` +Default value: `false` + +The file that the task should output the results to. + ## Tests Run `npm install` to install dependencies. diff --git a/package.json b/package.json index 4393f4e..bd8972d 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,9 @@ "grunt-contrib-jshint": "~0.6.0", "grunt-contrib-clean": "~0.4.0", "grunt-contrib-nodeunit": "~0.2.0", - "grunt": "~0.4.1" + "grunt": "~0.4.1", + "split": "~0.3.0", + "through2": "~0.5.1" }, "peerDependencies": { "grunt": "~0.4.1" diff --git a/tasks/protractor_runner.js b/tasks/protractor_runner.js index 4043b56..7a86e9c 100644 --- a/tasks/protractor_runner.js +++ b/tasks/protractor_runner.js @@ -10,6 +10,9 @@ var util = require('util'); var path = require('path'); +var fs = require('fs'); +var split = require('split'); +var through2 = require('through2'); module.exports = function(grunt) { @@ -28,7 +31,8 @@ module.exports = function(grunt) { keepAlive: false, noColor: false, debug: false, - args: {} + args: {}, + output: false }); // configFile is a special property which need not to be in options{} object. @@ -102,11 +106,11 @@ module.exports = function(grunt) { // Spawn protractor command var done = this.async(); - grunt.util.spawn({ + var child = grunt.util.spawn({ cmd: 'node', args: args, opts: { - stdio:'inherit' + stdio:'pipe' } }, function(error, result, code) { @@ -128,6 +132,29 @@ module.exports = function(grunt) { } } ); + child.stdout.pipe(process.stdout); + child.stderr.pipe(process.stderr); + + // Write the result in the output file + if (!grunt.util._.isUndefined(opts.output) && opts.output !== false) { + + grunt.verbose.writeln("Write the result to: " + opts.output); + + grunt.file.mkdir(path.dirname(opts.output)); + + child.stdout + .pipe(split()) + .pipe(through2(function (chunk, encoding, callback) { + if ((/^Using the selenium server at/).test(chunk.toString())) { + // skip + } + else { + this.push(chunk + '\n'); + } + callback(); + })) + .pipe(fs.createWriteStream(opts.output)); + } }); };