grunt-wendy
Advanced tools
Comparing version 0.0.4 to 0.0.6
@@ -37,2 +37,5 @@ 'use strict'; | ||
files: { src: ['test/c*.js'] } | ||
}, | ||
fail: { | ||
files: { src: ['test/d*.js'] } | ||
} | ||
@@ -39,0 +42,0 @@ }, |
{ | ||
"name": "grunt-wendy", | ||
"description": "CasperJS test runner", | ||
"version": "0.0.4", | ||
"version": "0.0.6", | ||
"homepage": "https://github.com/davidosomething/grunt-wendy", | ||
@@ -43,2 +43,3 @@ "author": { | ||
"casperjs": "1.1.0-beta3", | ||
"lodash": "^3.10.1", | ||
"phantomjs": "1.9.11" | ||
@@ -45,0 +46,0 @@ }, |
@@ -16,4 +16,5 @@ # grunt-wendy | ||
* no grunt output (`silent` flag of grunt-casperjs is always on) | ||
* custom grunt exit status (warn on skips/fatal on casper error) | ||
* Output parsing and aggregated results | ||
* customizable output parsing | ||
* aggregated results across all casper tasks run | ||
* custom grunt exit status (warns on skips/dubious instead of failing) | ||
@@ -62,3 +63,6 @@ ## Screenshot | ||
cli: [], | ||
runner: null | ||
runner: 'test', | ||
formatter: formatter, // function in tasks/lib/formatter.js | ||
fail: ['failed'], | ||
warn: ['dubious', 'skipped'] | ||
}, | ||
@@ -93,3 +97,4 @@ files: ['tests/e2e/**/*.js'] | ||
You can set the option to false to disable it. | ||
You can set the option to false to disable it. **The default formatter uses this | ||
option.** | ||
@@ -105,2 +110,16 @@ ```javascript | ||
#### CLI Options | ||
CasperJS CLI options (including user defined ones) can be passed in using | ||
'cli' in the options object | ||
```javascript | ||
wendy: { | ||
options: { | ||
cli: ['--foo=bar', '--no-colors'] | ||
}, | ||
files: ['tests/e2e/**/*.js'] | ||
} | ||
``` | ||
#### Runner | ||
@@ -121,6 +140,6 @@ | ||
#### CLI Options | ||
#### Formatter | ||
CasperJS CLI options (including user defined ones) can be passed in using | ||
'cli' in the options object | ||
This task captures all casper output and allows formatting of that output. | ||
The formatter can be customized by passing in a function like so: | ||
@@ -130,3 +149,5 @@ ```javascript | ||
options: { | ||
cli: ['--foo=bar', '--no-colors'] | ||
formatter: function (grunt, options, data) { | ||
grunt.log.write(data); | ||
} | ||
}, | ||
@@ -137,2 +158,25 @@ files: ['tests/e2e/**/*.js'] | ||
The `data` argument is always a string, a line from casper's stdout or stderr. | ||
The default formatter uses the `clean` option as well. See its source here for | ||
an example: [formatter.js] | ||
#### Grunt exit status | ||
Instead of failing on dubious tests or passing when tests are skipped, this | ||
task only fails when a test actually fails. You can go back to default grunt | ||
behavior, or customize your own using the `fail` and `warn` options. | ||
The options take an array with values `passed`, `failed`, `dubious`, and | ||
`skipped`. | ||
```javascript | ||
wendy: { | ||
options: { | ||
fail: ['failed'], // fail the task if any tests failed | ||
warn: ['dubious'] // grunt warning when tests dubious | ||
}, | ||
files: ['tests/e2e/**/*.js'] | ||
} | ||
``` | ||
## Contributing | ||
@@ -147,2 +191,6 @@ | ||
## CHANGELOG | ||
* 0.0.6 | ||
* Add `fail` and `warn` options | ||
* 0.0.5 | ||
* Add `formatter` option | ||
* 0.0.4 | ||
@@ -175,2 +223,3 @@ * Use `grunt.util.linefeed` for better Windows output | ||
[casper's included test runner]: https://github.com/n1k0/casperjs/blob/master/tests/run.js | ||
[formatter.js]: https://github.com/davidosomething/grunt-wendy/blob/master/tasks/lib/formatter.js | ||
@@ -177,0 +226,0 @@ [davidBadge]: https://david-dm.org/davidosomething/grunt-wendy.png?theme=shields.io |
@@ -1,8 +0,16 @@ | ||
module.exports = function (grunt, results) { | ||
/** | ||
* logAggregatedResults | ||
* | ||
* @param {object} grunt | ||
* @param {object} results | ||
*/ | ||
module.exports = function logAggregatedResults(grunt, results) { | ||
grunt.log.subhead(' Aggregated results:'); | ||
grunt.log.writeln(' passed: ' + results.passed); | ||
grunt.log.writeln(' failed: ' + results.failed); | ||
grunt.log.writeln(' dubious: ' + results.dubious); | ||
grunt.log.writeln(' skipped: ' + results.skipped); | ||
if (results && Object.keys(results).length) { | ||
grunt.log.writeln(' passed: ' + results.passed); | ||
grunt.log.writeln(' failed: ' + results.failed); | ||
grunt.log.writeln(' dubious: ' + results.dubious); | ||
grunt.log.writeln(' skipped: ' + results.skipped); | ||
} | ||
}; |
@@ -6,79 +6,56 @@ 'use strict'; | ||
var async = require('async'); | ||
var getCasperBinary = require('./lib/getCasperBinary.js'); | ||
var parseCasperOutput = require('./lib/parseCasperOutput.js'); | ||
var async = require('async'); | ||
var phantomBinPath = require('phantomjs').path; | ||
var getFilepaths = require('./lib/getFilepaths.js'); | ||
var filepathIterator = require('./lib/filepathIterator.js'); | ||
var formatter = require('./lib/formatter.js'); | ||
var logAggregatedResults = require('./lib/logAggregatedResults.js'); | ||
var getFilepaths = require('./lib/getFilepaths.js'); | ||
module.exports = function (grunt) { | ||
// phantom settings | ||
process.env['PHANTOMJS_EXECUTABLE'] = phantomBinPath; | ||
var aggregated = { | ||
passed: 0, | ||
failed: 0, | ||
dubious: 0, | ||
skipped: 0, | ||
}; | ||
grunt.registerMultiTask(taskName, taskDescription, function () { | ||
// grunt settings | ||
module.exports = function wendyModule(grunt) { | ||
// Outside of the task scope so we can aggregate across entire task queue | ||
grunt.registerMultiTask(taskName, taskDescription, function wendyTask() { | ||
var done = this.async(); | ||
var options = this.options({ | ||
async: 'eachSeries', | ||
clean: true, | ||
cli: [], | ||
runner: null | ||
async: 'eachSeries', | ||
clean: true, | ||
cli: [], | ||
runner: 'test', | ||
formatter: formatter, | ||
fail: ['failed'], | ||
warn: ['dubious', 'skipped'], | ||
_aggregated: {} | ||
}); | ||
var files = this.filesSrc; | ||
// phantom settings | ||
var phantomBinPath = require('phantomjs').path; | ||
process.env['PHANTOMJS_EXECUTABLE'] = phantomBinPath; | ||
// casper settings | ||
var command = getCasperBinary(); | ||
var args = []; | ||
// set runner arg | ||
if (!options.runner) { | ||
options.runner = 'test'; | ||
} | ||
args = [options.runner]; | ||
// set cli args | ||
if (options.cli && options.cli.length > 0) { | ||
args = args.concat(options.cli); | ||
} | ||
// Iterate over all specified file groups. | ||
var filepaths = getFilepaths(grunt, this.files) | ||
var asyncType = options.async; | ||
var asyncFn = async[asyncType]; | ||
// Async start up casper processes | ||
var asyncFn = async[options.async]; | ||
var asyncDone = function asyncDone(err, res) { | ||
logAggregatedResults(grunt, options._aggregated); | ||
asyncFn(filepaths, function filepathIterator(filepath, next) { | ||
// spawn casper process | ||
var casperProcess; | ||
casperProcess = grunt.util.spawn({ | ||
cmd: command, | ||
args: args.concat(filepath), | ||
}, function onSuitesDone(error, result, code) { | ||
next(); | ||
var isSuccess = true; | ||
options.fail.forEach(function (key) { | ||
if (options._aggregated[key]) { | ||
isSuccess = false; | ||
grunt.log.writeln(); | ||
grunt.log.error('[ERROR] There were tests with a status of ' + key); | ||
} | ||
}); | ||
// pipe spawned process outputs | ||
casperProcess.stdout.on('data', function (buf) { | ||
parseCasperOutput(grunt, buf, options, aggregated); | ||
options.warn.forEach(function (key) { | ||
if (options._aggregated[key]) { | ||
grunt.log.writeln(); | ||
grunt.log.error('[WARNING] There were tests with a status of ' + key); | ||
} | ||
}); | ||
casperProcess.stderr.on('data', function (buf) { | ||
parseCasperOutput(grunt, buf, options, aggregated); | ||
}); | ||
}, function (err, res) { | ||
logAggregatedResults(grunt, aggregated); | ||
done(); | ||
}); | ||
done(isSuccess); // grunt done | ||
}; | ||
asyncFn(filepaths, filepathIterator(grunt, options), asyncDone); | ||
}); | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
118170
21
294
229
5
+ Addedlodash@^3.10.1
+ Addedlodash@3.10.1(transitive)