Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

Commit

Permalink
Merge branch 'options-output' of https://github.com/stanleyhlng/grunt…
Browse files Browse the repository at this point in the history
…-protractor-runner into stanleyhlng-options-output
  • Loading branch information
teerapap committed Jan 18, 2015
2 parents e410950 + 61d55aa commit 6c0455e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,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.
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,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"
Expand Down
33 changes: 30 additions & 3 deletions tasks/protractor_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand All @@ -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.
Expand Down Expand Up @@ -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) {
Expand All @@ -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));
}
});

};

0 comments on commit 6c0455e

Please sign in to comment.