Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add BashTapReporter

  • Loading branch information...
commit ac46d828e0255e24e8ec33e04143ab71d74d89fa 1 parent 3dc4345
@skomski skomski authored
Showing with 51 additions and 5 deletions.
  1. +8 −1 Readme.md
  2. +5 −4 index.js
  3. +38 −0 lib/reporter/BashTapReporter.js
View
9 Readme.md
@@ -30,7 +30,14 @@ The only other feature is specifying a regex for the files to run (default is
`/test-.+\.js$/`), for example:
```js
-require('urun')(__dirname, /.+Test\.js$/);
+require('urun')(__dirname, { include: /.+Test\.js$/ });
+```
+
+## Reporter
+
+```js
+require('urun')(__dirname, { reporter: 'BashReporter' }); // default
+require('urun')(__dirname, { reporter: 'BashTapReporter' }); // tap compliant output
```
## License
View
9 index.js
@@ -1,10 +1,11 @@
var FileFilter = require('./lib/FileFilter');
var FileFinder = require('./lib/FileFinder');
var Runner = require('./lib/Runner');
-var BashReporter = require('./lib/reporter/BashReporter');
-module.exports = function(dir, include) {
- include = include || /test-.+\.js$/;
+module.exports = function(dir, options) {
+ var options = options || {};
+ var include = options.include || /test-.+\.js$/;
+ var Reporter = require('./lib/reporter/' + (options.reporter || 'BashReporter'));
var finder = new FileFinder(dir);
var filter = new FileFilter({include: include});
@@ -15,7 +16,7 @@ module.exports = function(dir, include) {
files = filter.filter(files);
var runner = new Runner({files: files});
- var reporter = new BashReporter({runner: runner});
+ var reporter = new Reporter({runner: runner});
runner.execute();
});
};
View
38 lib/reporter/BashTapReporter.js
@@ -0,0 +1,38 @@
+module.exports = BashTapReporter;
+
+function BashTapReporter(options) {
+ this._runner = options.runner;
+ this._fail = false;
+ this._count = 1;
+
+ this._runner.on('start', this._handleStart.bind(this));
+ this._runner.on('fileEnd', this._handleFileEnd.bind(this));
+ this._runner.on('end', this._handleEnd.bind(this));
+}
+
+BashTapReporter.prototype._handleStart = function(files) {
+ console.log('%d..%d', 1, files.length);
+};
+
+BashTapReporter.prototype._handleFileEnd = function(file, err, output) {
+ if (err) {
+ console.log('not ok %d %s', this._count, this._tapTitle(file));
+ console.log(output.replace(/^/gm, ' '));
+ this._fail = true;
+ } else {
+ console.log('ok %d %s', this._count, this._tapTitle(file));
+ }
+ this._count++;
+};
+
+BashTapReporter.prototype._handleEnd = function() {
+ var exitCode = (this._fail)
+ ? 1
+ : 0;
+
+ process.exit(exitCode);
+};
+
+BashTapReporter.prototype._tapTitle = function(title) {
+ return title.replace(/#/g, '');
+}
Please sign in to comment.
Something went wrong with that request. Please try again.