Permalink
Browse files

1.2.0: Build via grunt.

  • Loading branch information...
1 parent b8b2a36 commit e1815380519ecd750d9d66967deebab226183657 @ryanve committed Sep 3, 2013
Showing with 253 additions and 14 deletions.
  1. +1 −0 .gitignore
  2. +45 −0 GruntFile.js
  3. +3 −8 aok.js
  4. +6 −4 aok.min.js
  5. +8 −2 package.json
  6. +145 −0 src/aok.js
  7. +3 −0 test/index.html
  8. +42 −0 test/tests.js
View
@@ -0,0 +1 @@
+node_modules
View
@@ -0,0 +1,45 @@
+module.exports = function(grunt) {
+ grunt.initConfig({
+ pkg: grunt.file.readJSON('package.json'),
+ jshint: {
+ beforeconcat: ['src/', 'test/', 'GruntFile.js'],
+ afterconcat: ['<%= pkg.name %>.js'],
+ options: {
+ expr:true, sub:true, supernew:true, debug:true, node:true,
+ boss:true, devel:true, evil:true, laxcomma:true, eqnull:true,
+ undef:true, unused:true, browser:true, jquery:true, maxerr:10
+ }
+ },
+ concat: {
+ options: {
+ banner: [
+ '/*!',
+ ' * <%= pkg.name %> <%= pkg.version %>+<%= grunt.template.today("UTC:yyyymmddHHMM") %>',
+ ' * <%= pkg.homepage %>',
+ ' * MIT License 2013 <%= pkg.author %>',
+ ' */\n\n'
+ ].join('\n')
+ },
+ build: {
+ files: {
+ '<%= pkg.name %>.js': ['src/<%= pkg.name %>.js']
+ }
+ }
+ },
+ uglify: {
+ options: {
+ report: 'gzip',
+ preserveComments: 'some'
+ },
+ build: {
+ files: {
+ '<%= pkg.name %>.min.js': ['<%= pkg.name %>.js']
+ }
+ }
+ }
+ });
+ grunt.loadNpmTasks('grunt-contrib-jshint');
+ grunt.loadNpmTasks('grunt-contrib-concat');
+ grunt.loadNpmTasks('grunt-contrib-uglify');
+ grunt.registerTask('default', ['jshint:beforeconcat', 'concat', 'jshint:afterconcat', 'uglify']);
+};
View
11 aok.js
@@ -1,14 +1,9 @@
/*!
- * aok Extensible test suite API
- * @link github.com/ryanve/aok
- * @license MIT
- * @copyright 2013 Ryan Van Etten
- * @version 1.1.0
+ * aok 1.2.0+201309031941
+ * https://github.com/ryanve/aok
+ * MIT License 2013 Ryan Van Etten
*/
-/*jshint expr:true, sub:true, supernew:true, debug:true, node:true, boss:true, devel:true, evil:true,
- laxcomma:true, eqnull:true, undef:true, unused:true, browser:true, jquery:true, maxerr:100 */
-
(function(root, name, make) {
typeof module != 'undefined' && module['exports'] ? module['exports'] = make() : root[name] = make();
}(this, 'aok', function() {
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -1,14 +1,20 @@
{
"name": "aok",
"description": "Extensible test suite API.",
- "version": "1.1.0",
+ "version": "1.2.0",
"homepage": "https://github.com/ryanve/aok",
- "author": "Ryan Van Etten <@ryanve>",
+ "author": "Ryan Van Etten",
"keywords": ["testing", "test suite", "javascript", "ender"],
"main": "./aok.js",
"ender": "noop",
"repository": {
"type": "git",
"url": "https://github.com/ryanve/aok.git"
+ },
+ "devDependencies": {
+ "grunt": "~0.4.1",
+ "grunt-contrib-uglify": "~0.2.4",
+ "grunt-contrib-concat": "~0.3.0",
+ "grunt-contrib-jshint": "~0.6.4"
}
}
View
@@ -0,0 +1,145 @@
+(function(root, name, make) {
+ typeof module != 'undefined' && module['exports'] ? module['exports'] = make() : root[name] = make();
+}(this, 'aok', function() {
+
+ var win = window
+ , doc = document
+ , plain = {}
+ , owns = plain.hasOwnProperty
+ , toString = plain.toString
+ , uid = 0;
+
+ /**
+ * @constructor
+ * @param {*=} data
+ */
+ function Aok(data) {
+ // Own 'test' unless instantiated w/o args,
+ // or unless `data` is 'object' w/o 'test'.
+ // Running proceeds only if 'test' is owned.
+ if (data && typeof data == 'object') {
+ for (var k in data) {
+ owns.call(data, k) && (this[k] = data[k]);
+ }
+ } else if (arguments.length) {
+ this['test'] = data;
+ }
+ this['init']();
+ }
+
+ /**
+ * @param {*=} data
+ * @return {Aok}
+ */
+ function aok(data) {
+ return arguments.length ? new Aok(data) : new Aok;
+ }
+
+ // Sync the prototypes
+ aok.prototype = Aok.prototype;
+
+ // Default messages
+ aok.prototype['pass'] = 'Pass';
+ aok.prototype['fail'] = 'Fail';
+
+ // Console abstractions
+ (function(target, console, win) {
+ /**
+ * @param {string} name
+ * @param {(boolean|number)=} force
+ * @param {string=} key
+ */
+ function assign(name, force, key) {
+ var method = console && typeof console[name] == 'function' ? function() {
+ console[name].apply(console, arguments);
+ } : function() {
+ method['force'] && win['alert'](name + ': ' + [].join.call(arguments, ' '));
+ };
+ method['force'] = !!force;
+ target[key || name] = method;
+ }
+
+ assign('info', 1);
+ assign('warn', 1);
+ assign('error', 1);
+ assign('trace');
+ assign('log');
+ assign('log', 0, 'express');
+ }(aok, win.console, win));
+
+ // Alias the "express" method. `aok.prototype.express` is used in the
+ // default handler. Override it as needed for customization.
+ aok.prototype['express'] = aok['express'];
+
+ /**
+ * @param {*} item
+ * @return {string}
+ */
+ function explain(item) {
+ return '' + (item === Object(item) ? toString.call(item) : item);
+ }
+ aok['explain'] = explain;
+
+ /**
+ * @param {*} o is an Object or mixed value
+ * @param {(string|number)=} k
+ * @example result(0) // 0
+ * @example result([1], 0) // 1
+ */
+ function result(o, k) {
+ return 2 == arguments.length ? result.call(o, o[k]) : typeof o == 'function' ? o.call(this) : o;
+ }
+ aok['result'] = result;
+
+ /**
+ * @return {Aok}
+ */
+ aok.prototype['init'] = function() {
+ if (this === win) { throw new Error('@this'); }
+ owns.call(this, 'id') || (this['id'] = ++uid);
+ owns.call(this, 'test') && this['run']();
+ return this;
+ };
+
+ /**
+ * @return {Aok}
+ */
+ aok.prototype['run'] = function() {
+ if (this === win) { throw new Error('@this'); }
+ this['test'] = !!result(this, 'test'); // run the test
+ return this['handler'](); // trigger the handler
+ };
+
+ /**
+ * @param {(string|number)=} key
+ */
+ aok.prototype['cull'] = function(key) {
+ return this[this[null == key ? 'test' : key] ? 'pass' : 'fail'];
+ };
+
+ /**
+ * default handler can be overridden
+ * @return {Aok}
+ */
+ aok.prototype['handler'] = function() {
+ var msg = this['cull']();
+ if (typeof msg == 'function') {
+ msg.call(this);
+ } else {
+ msg = explain(msg);
+ owns.call(this, 'remark') && (msg += ' (' + explain(this['remark']) + ')');
+ this['express']('#' + this['id'] + ': ' + msg);
+ }
+ return this;
+ };
+
+ /**
+ * @param {string} n
+ * @return {Node|boolean}
+ */
+ aok['id'] = function(n) {
+ return doc.getElementById(n) || false;
+ };
+
+ return aok;
+}));
View
@@ -0,0 +1,3 @@
+<p>Open the console.</p>
+<script src="../aok.js"></script>
+<script src="tests.js"></script>
View
@@ -0,0 +1,42 @@
+(function(aok) {
+ var instance = aok();
+ aok(function() {
+ return isFinite(this.id);
+ });
+ aok({
+ id: 'handler',
+ test: false,
+ handler: function() {
+ this.test = this instanceof aok;
+ return aok.prototype.handler.call(this);
+ }
+ });
+ aok({
+ id: 'instance',
+ test: instance instanceof aok
+ });
+ aok({
+ id: 'cull',
+ test: function() {
+ var culled = this.cull();
+ this.remark = culled;
+ return culled === this.pass;
+ },
+ });
+ aok({
+ id: 'remark',
+ test: function() {
+ return this.remark = {};
+ },
+ });
+ aok({
+ id: 'resultParams',
+ test: aok.result(function() {
+ return !arguments.length && aok === this;
+ })
+ });
+ aok({
+ id: 'resultReturn',
+ test: 1 === aok.result(1) && 1 === aok.result([1], 0)
+ });
+}(this.aok));

0 comments on commit e181538

Please sign in to comment.