Permalink
Browse files

support running `ava` without arguments

  • Loading branch information...
1 parent f3c12c1 commit 35b7e5bde2fc87c1561b566eeae19ca52a75311c @sindresorhus sindresorhus committed Aug 26, 2015
Showing with 1,780 additions and 142 deletions.
  1. +2 −0 .gitattributes
  2. +14 −8 cli.js
  3. +0 −27 index.js
  4. +0 −51 lib/runner.js
  5. +14 −41 lib/test.js
  6. BIN media/header.png
  7. BIN media/header.psd
  8. +1,507 −0 media/logo.ai
  9. BIN media/logo.png
  10. +1 −0 media/logo.svg
  11. +6 −3 package.json
  12. +185 −12 readme.md
  13. BIN screenshot.png
  14. +51 −0 test/test.js
View
@@ -1 +1,3 @@
* text=auto
+*.ai binary
+*.psd binary
View
@@ -11,10 +11,13 @@ var cli = meow({
'Usage',
' ava <file|folder|glob> [...]',
'',
- 'Example',
+ 'Examples',
+ ' ava',
' ava test.js test2.js',
- ' ava test',
- ' ava test-*.js'
+ ' ava test-*.js',
+ '',
+ 'Default patterns when no arguments:',
+ 'test.js test-*.js test/**'
]
}, {
string: ['_']
@@ -37,6 +40,14 @@ function run(file) {
}
function init(files) {
+ if (files.length === 0) {
+ files = [
+ 'test.js',
+ 'test-*.js',
+ 'test/**'
+ ];
+ }
+
globby(files, function (err, files) {
if (err) {
console.error(err.message);
@@ -51,9 +62,4 @@ function init(files) {
updateNotifier({pkg: cli.pkg}).notify();
-if (cli.input.length === 0) {
- console.error('Input required');
- process.exit(1);
-}
-
init(cli.input);
View
@@ -7,10 +7,6 @@ var Runner = require('./lib/runner');
var log = new Squeak({separator: ' '});
var runner = new Runner();
-/**
- * Add log types
- */
-
log.type('success', {
color: 'green',
prefix: figures.tick
@@ -21,14 +17,6 @@ log.type('error', {
prefix: figures.cross
});
-/**
- * Handle test
- *
- * @param {Object} err
- * @param {String} title
- * @api private
- */
-
function test(err, title) {
if (err) {
log.error(title, chalk.red(err.message));
@@ -38,13 +26,6 @@ function test(err, title) {
log.success(title);
}
-/**
- * Show stack for each failed test
- *
- * @param {Array} results
- * @api private
- */
-
function stack(results) {
var i = 0;
@@ -61,14 +42,6 @@ function stack(results) {
});
}
-/**
- * Show summary and exit
- *
- * @param {Object} stats
- * @param {Array} results
- * @api private
- */
-
function exit(stats, results) {
if (stats.testCount > 0) {
log.write();
View
@@ -5,13 +5,6 @@ var each = require('each-async');
var eachSerial = require('async-each-series');
var Test = require('./test');
-/**
- * Initialize a new `Runner`
- *
- * @param {Object} opts
- * @api public
- */
-
function Runner(opts) {
if (!(this instanceof Runner)) {
return new Runner(opts);
@@ -31,39 +24,16 @@ function Runner(opts) {
util.inherits(Runner, EventEmitter);
module.exports = Runner;
-/**
- * Add concurrent test to `Runner`
- *
- * @param {String} title
- * @param {Function} cb
- * @api public
- */
-
Runner.prototype.addTest = function (title, cb) {
this.stats.testCount++;
this.tests.concurrent.push(new Test(title, cb));
};
-/**
- * Add serial test to `Runner`
- *
- * @param {String} title
- * @param {Function} cb
- * @api public
- */
-
Runner.prototype.addSerialTest = function (title, cb) {
this.stats.testCount++;
this.tests.serial.push(new Test(title, cb));
};
-/**
- * Run concurrent tests
- *
- * @param {Function} cb
- * @api private
- */
-
Runner.prototype.concurrent = function (cb) {
each(this.tests.concurrent, function (test, i, next) {
test.run(function (err) {
@@ -82,13 +52,6 @@ Runner.prototype.concurrent = function (cb) {
}.bind(this), cb);
};
-/**
- * Run serial tests
- *
- * @param {Function} cb
- * @api private
- */
-
Runner.prototype.serial = function (cb) {
eachSerial(this.tests.serial, function (test, next) {
test.run(function (err) {
@@ -107,13 +70,6 @@ Runner.prototype.serial = function (cb) {
}.bind(this), cb);
};
-/**
- * Run the `Runner`
- *
- * @param {Function} cb
- * @api public
- */
-
Runner.prototype.run = function (cb) {
var concurrent = this.tests.concurrent;
var serial = this.tests.serial;
@@ -136,13 +92,6 @@ Runner.prototype.run = function (cb) {
this.end(cb);
};
-/**
- * Handle completion
- *
- * @param {Function} cb
- * @api private
- */
-
Runner.prototype.end = function (cb) {
this.stats.passCount = this.stats.testCount - this.stats.failCount;
cb(this.stats, this.results);
View
@@ -5,14 +5,6 @@ var EventEmitter = require('events').EventEmitter;
var fnName = require('fn-name');
var claim = require('claim');
-/**
- * Initialize a new `Test`
- *
- * @param {String} title
- * @param {Function} fn
- * @api public
- */
-
function Test(title, fn) {
if (!(this instanceof Test)) {
return new Test(title, fn);
@@ -56,13 +48,6 @@ Object.keys(claim).forEach(function (el) {
};
});
-/**
- * Plan number of assertions
- *
- * @param {Number} count
- * @api public
- */
-
Test.prototype.plan = function (count) {
if (typeof count !== 'number') {
throw new TypeError('Expected a number');
@@ -71,23 +56,10 @@ Test.prototype.plan = function (count) {
this.planCount = count;
};
-/**
- * Skip test
- *
- * @api public
- */
-
Test.prototype.skip = function () {
this.skipTest = true;
};
-/**
- * Run test
- *
- * @param {Function} cb
- * @api public
- */
-
Test.prototype.run = function (cb) {
this.cb = cb;
@@ -96,19 +68,26 @@ Test.prototype.run = function (cb) {
}
try {
- this.fn(this);
+ var ret = this.fn(this);
+
+ if (ret && typeof ret.then === 'function') {
+ ret.then(this.exit.bind(this)).catch(function (err) {
+ this.assertError = new assert.AssertionError({
+ actual: err,
+ message: 'Promise rejected → ' + err,
+ operator: 'promise',
+ stackStartFunction: this
+ });
+
+ this.exit();
+ }.bind(this));
+ }
} catch (err) {
this.assertError = err;
this.exit();
}
};
-/**
- * End test
- *
- * @api public
- */
-
Test.prototype.end = function () {
if (this.endCalled) {
throw new Error('.end() called more than once');
@@ -118,12 +97,6 @@ Test.prototype.end = function () {
this.exit();
};
-/**
- * Exit test
- *
- * @api private
- */
-
Test.prototype.exit = function () {
if (this.planCount !== null && this.planCount !== this.assertCount) {
this.assertError = new assert.AssertionError({
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.

0 comments on commit 35b7e5b

Please sign in to comment.