Permalink
Browse files

init

  • Loading branch information...
0 parents commit 1089a87c2c6e5f99de8a715c41ddb074c2602404 @sindresorhus sindresorhus committed Nov 18, 2014
Showing with 508 additions and 0 deletions.
  1. +15 −0 .editorconfig
  2. +1 −0 .gitattributes
  3. +1 −0 .gitignore
  4. +13 −0 .jshintrc
  5. +3 −0 .travis.yml
  6. +25 −0 cli.js
  7. +35 −0 index.js
  8. +54 −0 lib/runner.js
  9. +144 −0 lib/test.js
  10. +21 −0 license
  11. +48 −0 package.json
  12. +45 −0 readme.md
  13. +103 −0 test/test.js
@@ -0,0 +1,15 @@
+root = true
+
+[*]
+indent_style = tab
+end_of_line = lf
+charset = utf-8
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[package.json]
+indent_style = space
+indent_size = 2
+
+[*.md]
+trim_trailing_whitespace = false
@@ -0,0 +1 @@
+* text=auto
@@ -0,0 +1 @@
+node_modules
@@ -0,0 +1,13 @@
+{
+ "node": true,
+ "esnext": true,
+ "bitwise": true,
+ "camelcase": true,
+ "curly": true,
+ "immed": true,
+ "newcap": true,
+ "noarg": true,
+ "undef": true,
+ "unused": "vars",
+ "strict": true
+}
@@ -0,0 +1,3 @@
+language: node_js
+node_js:
+ - '0.10'
@@ -0,0 +1,25 @@
+#!/usr/bin/env node
+'use strict';
+var updateNotifier = require('update-notifier');
+var meow = require('meow');
+var ava = require('./');
+
+var cli = meow({
+ help: [
+ 'Usage',
+ ' ava <file> [<file> ...]',
+ '',
+ 'Example',
+ ' ava test.js test2.js'
+ ].join('\n')
+}, {
+ string: ['_']
+});
+
+updateNotifier({
+ packageName: cli.pkg.name,
+ packageVersion: cli.pkg.version
+}).notify();
+
+console.error('not implemented');
+process.exit(1);
@@ -0,0 +1,35 @@
+'use strict';
+var chalk = require('chalk');
+var logSymbols = require('log-symbols');
+var Runner = require('./lib/runner');
+var runner = new Runner();
+
+setImmediate(function () {
+ console.log('\n');
+
+ runner.on('test', function (err, title) {
+ if (err) {
+ console.log(' ', logSymbols.error, title, ' ', chalk.red(err.message));
+ return;
+ }
+
+ console.log(' ', logSymbols.success, title);
+ });
+
+ runner.run(function (stats, results) {
+ if (stats.failCount === 0) {
+ console.log(chalk.green('\n ', stats.passCount, (stats.passCount === 1 ? 'test' : 'tests'), 'passed\n'));
+ } else {
+ console.log(chalk.red('\n ', stats.failCount, (stats.failCount === 1 ? 'test' : 'tests'), 'failed\n'));
+ // TODO: show detailed fails when at least one test failed
+ }
+
+ console.log('runner run cb', arguments);
+ process.exit(stats.failCount > 0 ? 1 : 0);
+ });
+});
+
+module.exports = runner.addTest.bind(runner);
+
+// TODO: expose it when more stable
+//module.exports.Runner = Runner;
@@ -0,0 +1,54 @@
+'use strict';
+var inherits = require('util').inherits;
+var EventEmitter = require('events').EventEmitter;
+var eachAsync = require('each-async');
+var Test = require('./test');
+
+inherits(Runner, EventEmitter);
+
+function Runner(opts) {
+ this._tests = [];
+ this._results = [];
+ this._firstError = null;
+ this._failCount = 0;
+}
+
+Runner.prototype.addTest = function (title, cb) {
+ this._tests.push(new Test(title, cb));
+};
+
+Runner.prototype.run = function (cb) {
+ var self = this;
+
+ eachAsync(this._tests, function (test, i, next) {
+ test.run(function (err) {
+ if (err) {
+ if (!self._firstError) {
+ self._firstError = err;
+ }
+
+ self._failCount++;
+ }
+
+ self._results.push({
+ title: test.title,
+ error: err
+ });
+
+ self.emit('test', err, test.title);
+ next();
+ });
+ }, function () {
+ var testCount = self._tests.length;
+ var failCount = self._failCount;
+ var passCount = testCount - failCount;
+
+ cb({
+ testCount: testCount,
+ failCount: failCount,
+ passCount: passCount
+ }, self._results);
+ });
+};
+
+module.exports = Runner;
@@ -0,0 +1,144 @@
+'use strict';
+var assert = require('assert');
+var inherits = require('util').inherits;
+var EventEmitter = require('events').EventEmitter;
+
+inherits(Test, EventEmitter);
+
+function Test(title, fn) {
+ if (!(this instanceof Test)) {
+ return new Test(title, fn);
+ }
+
+ if (typeof title !== 'string') {
+ fn = title;
+ title = null;
+ }
+
+ this.title = title || fn.name || '[anonymous]';
+ this._fn = fn;
+ this._skip = false;
+ this._planCount = null;
+ this._assertCount = 0;
+ this._assertError = null;
+ this._endCalled = false;
+ this._ended = false;
+}
+
+Test.prototype.end = function () {
+ if (this._endCalled) {
+ this._assert(false, {
+ msg: '.end() called more than once'
+ });
+ }
+
+ this._endCalled = true;
+ this._end();
+};
+
+Test.prototype._end = function () {
+ if (this._planCount !== null && this._planCount !== this._assertCount) {
+ this._assert(false, {
+ msg: 'Assertion count doens\'t match planned',
+ actual: this._assertCount,
+ expected: this._planCount
+ });
+ }
+
+ if (!this._ended) {
+ this._ended = true;
+ setImmediate(function () {
+ this.emit('end', this._assertError);
+ }.bind(this))
+ }
+};
+
+/*
+TODO:
+t.is() or t.equal() ??
+t.not() or t.notEqual() ??
+t.same() or t.deepEqual() ??
+t.notDeepEqual()
+t.throws()
+t.doesNotThrow()
+*/
+
+Test.prototype.true = function (val, msg) {
+ this._assert(val, {
+ message: msg,
+ operator: 'true',
+ expected: true,
+ actual: val
+ });
+};
+
+Test.prototype.false = function (val, msg) {
+ this._assert(val, {
+ message: msg,
+ operator: 'false',
+ expected: false,
+ actual: val
+ });
+};
+
+Test.prototype.error = function (err, msg) {
+ this._assert(!err, {
+ message: msg || err.toString(), // TODO: show the stack or something useful
+ operator: 'error',
+ actual: err
+ });
+};
+
+Test.prototype.fail = function (msg) {
+ this._assert(false, {
+ message: msg,
+ operator: 'fail'
+ });
+};
+
+Test.prototype._assert = function (ok, opts) {
+ console.error('assert count', this._assertCount);
+ this._assertCount++;
+
+ if (!ok) {
+ opts.stackStartFunction = this._fn;
+ this._assertError = new assert.AssertionError(opts);
+ }
+
+ if (this._assertCount === this._planCount) {
+ // delay end so all assertion have a chance to
+ // run so we can catch unplanned assertions
+ setImmediate(this._end.bind(this));
+ }
+};
+
+Test.prototype.plan = function (count) {
+ if (typeof count !== 'number') {
+ throw new TypeError('Expected a number');
+ }
+
+ this._planCount = count;
+};
+
+Test.prototype.skip = function () {
+ this._skip = true;
+};
+
+Test.prototype.run = function (cb) {
+ if (!this._fn || this._skip) {
+ return;
+ }
+
+ this.on('end', function (err) {
+ cb.call(this, err);
+ });
+
+ try {
+ this._fn(this);
+ } catch (err) {
+ this.error(err);
+ this._end();
+ }
+};
+
+module.exports = Test;
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
@@ -0,0 +1,48 @@
+{
+ "name": "ava",
+ "version": "0.0.4",
+ "description": "WIP - Simple concurrent test runner",
+ "license": "MIT",
+ "repository": "sindresorhus/ava",
+ "bin": {
+ "ava": "cli.js"
+ },
+ "author": {
+ "name": "Sindre Sorhus",
+ "email": "sindresorhus@gmail.com",
+ "url": "http://sindresorhus.com"
+ },
+ "engines": {
+ "node": ">=0.10.0"
+ },
+ "scripts": {
+ "test": "tape test/* | faucet"
+ },
+ "files": [
+ "index.js",
+ "cli.js",
+ "lib"
+ ],
+ "keywords": [
+ "cli",
+ "bin",
+ "ava",
+ "test",
+ "runner",
+ "concurrent",
+ "parallel"
+ ],
+ "dependencies": {
+ "chalk": "^0.5.1",
+ "each-async": "^1.0.0",
+ "insist": "^0.2.3",
+ "log-symbols": "^1.0.0",
+ "meow": "^2.0.0"
+ },
+ "devDependencies": {
+ "ava": "0.0.4",
+ "faucet": "0.0.1",
+ "tape": "^3.0.3",
+ "update-notifier": "^0.2.2"
+ }
+}
Oops, something went wrong.

0 comments on commit 1089a87

Please sign in to comment.