Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

Added support for pending tests. Closes #27

Tj Holowaychukfe956b172450
diff --git a/lib/reporters/base.js b/lib/reporters/base.js
index aee1cc07..513db035 100644
--- a/lib/reporters/base.js
+++ b/lib/reporters/base.js
@@ -32,6 +32,7 @@ exports.colors = {
, 'pass message': 32
, 'fail': 31
, 'fail message': 31
+ , 'pending': 36
, 'error title': 0
, 'error message': 31
, 'error stack': 90
diff --git a/lib/reporters/dot.js b/lib/reporters/dot.js
index 1083675d..2225d30b 100644
--- a/lib/reporters/dot.js
+++ b/lib/reporters/dot.js
@@ -27,18 +27,19 @@ function Dot(runner) {
, width = Base.window.width * .75 | 0
, n = 0;
- // tests started
runner.on('start', function(){
process.stdout.write('\n ');
});
- // test passed, output a dot
+ runner.on('pending', function(test){
+ process.stdout.write(color('pending', '.'));
+ });
+
runner.on('pass', function(test){
if (++n % width == 0) process.stdout.write('\n ');
process.stdout.write(color(test.speed, '.'));
});
- // test failed, output a dot
runner.on('fail', function(test, err){
if (++n % width == 0) process.stdout.write('\n ');
process.stdout.write(color('fail', '.'));
diff --git a/lib/reporters/json-stream.js b/lib/reporters/json-stream.js
index ef83dbdd..f6956791 100644
--- a/lib/reporters/json-stream.js
+++ b/lib/reporters/json-stream.js
@@ -26,24 +26,22 @@ function List(runner) {
, stats = this.stats
, total = runner.total;
- // tests started
runner.on('start', function(){
console.log(JSON.stringify(['start', { total: total }]));
});
- // test passed
runner.on('pass', function(test){
console.log(JSON.stringify(['pass', clean(test)]));
});
- // test failed
runner.on('fail', function(test, err){
console.log(JSON.stringify(['fail', clean(test)]));
});
- // tests are complete
runner.on('end', function(){
- process.stdout.write(JSON.stringify(['end', self.stats]));
+ process.stdout.write(JSON.stringify(['end', self.stats]), function(){
+ process.exit(0);
+ });
});
}
diff --git a/lib/reporters/json.js b/lib/reporters/json.js
index ef5c2ff8..d6edce98 100644
--- a/lib/reporters/json.js
+++ b/lib/reporters/json.js
@@ -48,7 +48,9 @@ function JSONReporter(runner) {
, passes: passes.map(clean)
};
- process.stdout.write(JSON.stringify(obj));
+ process.stdout.write(JSON.stringify(obj), function(){
+ process.exit(0);
+ });
});
}
diff --git a/lib/reporters/list.js b/lib/reporters/list.js
index b4a61542..b906f22c 100644
--- a/lib/reporters/list.js
+++ b/lib/reporters/list.js
@@ -26,17 +26,20 @@ function List(runner) {
, stats = this.stats
, n = 0;
- // tests started
runner.on('start', function(){
console.log();
});
- // test started
runner.on('test', function(test){
process.stdout.write(color('pass', ' ' + test.fullTitle() + ': '));
});
- // test passed
+ runner.on('pending', function(test){
+ var fmt = color('checkmark', ' -')
+ + color('pending', ' %s');
+ console.log(fmt, test.fullTitle());
+ });
+
runner.on('pass', function(test){
var fmt = color('checkmark', ' ✔')
+ color('pass', ' %s: ')
@@ -44,7 +47,6 @@ function List(runner) {
console.log('\r' + fmt, test.fullTitle(), test.duration);
});
- // test failed
runner.on('fail', function(test, err){
console.log('\r' + color('fail', ' %d) %s'), n++, test.fullTitle());
});
diff --git a/lib/runner.js b/lib/runner.js
index 74a8b844..2304644e 100644
--- a/lib/runner.js
+++ b/lib/runner.js
@@ -199,6 +199,13 @@ Runner.prototype.runTests = function(suite, fn){
// grep
if (!self._grep.test(test.fullTitle())) return next();
+ // pending
+ if (test.pending) {
+ self.emit('pending', test);
+ self.emit('test end', test);
+ return next();
+ }
+
// execute test and hook(s)
self.emit('test', self.test = test);
self.hook('beforeEach', function(err){
diff --git a/lib/test.js b/lib/test.js
index 32c1443c..d5ddafc0 100644
--- a/lib/test.js
+++ b/lib/test.js
@@ -16,7 +16,8 @@ module.exports = Test;
function Test(title, fn) {
this.title = title;
this.fn = fn;
- this.async = !! fn.length;
+ this.pending = !fn;
+ this.async = fn && fn.length;
this.sync = ! this.async;
this.timeout(2000);
}
@@ -75,7 +76,7 @@ Test.prototype.run = function(fn){
});
// sync
} else {
- this.fn();
+ if (!this.pending) this.fn();
this.duration = new Date - start;
}
};
diff --git a/test/unit/pending.js b/test/unit/pending.js
new file mode 100644
index 00000000..cf738b27
--- /dev/null
+++ b/test/unit/pending.js
@@ -0,0 +1,4 @@
+
+describe('pending', function(){
+ it('should be allowed')
+})
\ No newline at end of file