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

Commit

Permalink
implement the logic to write the reuslt to a file if options.output i…
Browse files Browse the repository at this point in the history
…s defined
  • Loading branch information
stanleyhlng committed Aug 6, 2014
1 parent 8956e08 commit 61d55aa
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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 61d55aa

Please sign in to comment.