Permalink
Browse files

Add development and compressed versions of lib, and specs.

  • Loading branch information...
1 parent ebe6bd2 commit 5b4646f5996b7841a7fc531a52d37fe2b5eaf4b4 @demiazz committed Jan 28, 2012
Showing with 481 additions and 0 deletions.
  1. +186 −0 jasmine-wkreporter.js
  2. +9 −0 jasmine-wkreporter.min.js
  3. +286 −0 jasmine-wkreporter.spec.js
View
@@ -1,5 +1,191 @@
+
+/*
+ @class
+
+ Simple reporter for Jasmine. Using Notification API from Chrome/Chromium browser,
+ for report results of running specs.
+
+ @author Alexey Plutalov <demiazz.py@gmail.com>
+ @since Jasmine Webkit Reporter 0.1
+*/
+
(function() {
+ var __hasProp = Object.prototype.hasOwnProperty,
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
+
+ jasmine.WebkitReporter = (function(_super) {
+
+ __extends(WebkitReporter, _super);
+
+ /*
+ Title using for header of notification. May used for identify specs.
+
+ @type {String}
+ @default "jasmine"
+ */
+
+ WebkitReporter.prototype.title = "Jasmine";
+
+ /*
+ This is ID used for replacing notifications with this ID, when creating new
+ notification.
+
+ @type {String}
+ @default "jasmine"
+
+ @see Notification API Draft
+ */
+
+ WebkitReporter.prototype.replaceId = "jasmine";
+
+ /*
+ Timeout used for set timeout before notification be autoclosed. If timeout
+ is equal 0, then notification not be autoclosed.
+
+ @type {Integer}
+ @default 0
+ */
+
+ WebkitReporter.prototype.timeout = 0;
+
+ /*
+ Passed icon is a icon for notification, when all specs are passed.
+
+ @type {String}
+ @default ""
+ */
+
+ WebkitReporter.prototype.passedIcon = "";
+
+ /*
+ Failed icon is a icon for notification, when at least one spec are failed.
+
+ @type {String}
+ @default ""
+ */
+
+ WebkitReporter.prototype.failedIcon = "";
+
+ /*
+ Running icons is a icon for notification, while specs running.
+
+ @type {String}
+ @default ""
+ */
+
+ WebkitReporter.prototype.runningIcon = "";
+
+ /*
+ WebkitReporter constructor.
+
+ Options:
+ * title
+ * replaceId
+ * timeout
+ * passedIcon
+ * failedIcon
+ * runningIcon
+
+ @param {Object|null} options - options for reporter
+ */
+
+ function WebkitReporter(options) {
+ if (options == null) options = {};
+ if (options) {
+ if (options.title) this.title = options.title;
+ if (options.replaceId) this.replaceId = options.replaceId;
+ if (options.timeout) this.timeout = options.timeout;
+ if (options.passedIcon) this.passedIcon = options.passedIcon;
+ if (options.failedIcon) this.failedIcon = options.failedIcon;
+ if (options.runningIcon) this.runningIcon = options.runningIcon;
+ }
+ this.startedAt = null;
+ this.finishedAt = null;
+ return;
+ }
+
+ /*
+ Callback for jasmine.Runner, when Runner starting.
+
+ If notification permission is not allowed then request permission
+ instead show notification.
+
+ @param {jasmine.Runner} runner jasmine.Runner for reporting.
+ */
+
+ WebkitReporter.prototype.reportRunnerStarting = function(runner) {
+ var title;
+ if (jasmine.getGlobal().webkitNotifications.checkPermission() === 0) {
+ this.startedAt = new Date();
+ this.finishedAt = null;
+ if (this.title && this.title.length > 0) {
+ title = "" + this.title + ": RUNNING";
+ } else {
+ title = "RUNNING";
+ }
+ this.showReport(this.runningIcon, title, "Running specs. Please wait...");
+ } else {
+ jasmine.getGlobal().webkitNotifications.requestPermission();
+ }
+ };
+
+ /*
+ Callback for jasmine.Runner, when Runner finished.
+
+ If notification permission is not allowed then request permission
+ instead show notification.
+
+ @param {jasmine.Runner} runner jasmine.Runner for reporting.
+ */
+
+ WebkitReporter.prototype.reportRunnerResults = function(runner) {
+ var icon, message, results, time, title;
+ this.finishedAt = new Date();
+ if (jasmine.getGlobal().webkitNotifications.checkPermission() === 0) {
+ icon = "";
+ title = "";
+ message = "";
+ time = (this.finishedAt.getTime() - this.startedAt.getTime()) / 1000;
+ if (this.title && this.title.length > 0) title = this.title + ": ";
+ results = runner.results();
+ if (results.failedCount > 0) {
+ icon = this.failedIcon;
+ title += "FAILED";
+ } else {
+ icon = this.passedIcon;
+ title += "PASSED";
+ }
+ message += "" + results.totalCount + " spec" + (results.totalCount === 1 ? "" : "s");
+ message += ", " + results.failedCount + " failure" + (results.failedCount === 1 ? "" : "s");
+ message += " in " + time + "s";
+ this.showReport(icon, title, message);
+ } else {
+ jasmine.getGlobal().webkitNotifications.requestPermission();
+ }
+ };
+
+ /*
+ Show notification by Notification API. Set timeout for autoclose if exist.
+
+ @param {String} icon - icon for notification
+ @param {String} title - title for notification
+ @param {String} message - message for notification
+ */
+
+ WebkitReporter.prototype.showReport = function(icon, title, message) {
+ var notification;
+ notification = jasmine.getGlobal().webkitNotifications.createNotification(icon, title, message);
+ notification.replaceId = this.replaceId;
+ notification.show();
+ if (this.timeout > 0) {
+ setTimeout(function() {
+ notification.cancel();
+ }, this.timeout);
+ }
+ };
+ return WebkitReporter;
+ })(jasmine.Reporter);
}).call(this);
@@ -0,0 +1,9 @@
+/*
+ @class
+
+ Simple reporter for Jasmine. Using Notification API from Chrome/Chromium browser,
+ for report results of running specs.
+
+ @author Alexey Plutalov <demiazz.py@gmail.com>
+ @since Jasmine Webkit Reporter 0.1
+*/((function(){var a=Object.prototype.hasOwnProperty,b=function(b,c){function e(){this.constructor=b}for(var d in c)a.call(c,d)&&(b[d]=c[d]);return e.prototype=c.prototype,b.prototype=new e,b.__super__=c.prototype,b};jasmine.WebkitReporter=function(a){function c(a){a==null&&(a={}),a&&(a.title&&(this.title=a.title),a.replaceId&&(this.replaceId=a.replaceId),a.timeout&&(this.timeout=a.timeout),a.passedIcon&&(this.passedIcon=a.passedIcon),a.failedIcon&&(this.failedIcon=a.failedIcon),a.runningIcon&&(this.runningIcon=a.runningIcon)),this.startedAt=null,this.finishedAt=null;return}return b(c,a),c.prototype.title="Jasmine",c.prototype.replaceId="jasmine",c.prototype.timeout=0,c.prototype.passedIcon="",c.prototype.failedIcon="",c.prototype.runningIcon="",c.prototype.reportRunnerStarting=function(a){var b;jasmine.getGlobal().webkitNotifications.checkPermission()===0?(this.startedAt=new Date,this.finishedAt=null,this.title&&this.title.length>0?b=""+this.title+": RUNNING":b="RUNNING",this.showReport(this.runningIcon,b,"Running specs. Please wait...")):jasmine.getGlobal().webkitNotifications.requestPermission()},c.prototype.reportRunnerResults=function(a){var b,c,d,e,f;this.finishedAt=new Date,jasmine.getGlobal().webkitNotifications.checkPermission()===0?(b="",f="",c="",e=(this.finishedAt.getTime()-this.startedAt.getTime())/1e3,this.title&&this.title.length>0&&(f=this.title+": "),d=a.results(),d.failedCount>0?(b=this.failedIcon,f+="FAILED"):(b=this.passedIcon,f+="PASSED"),c+=""+d.totalCount+" spec"+(d.totalCount===1?"":"s"),c+=", "+d.failedCount+" failure"+(d.failedCount===1?"":"s"),c+=" in "+e+"s",this.showReport(b,f,c)):jasmine.getGlobal().webkitNotifications.requestPermission()},c.prototype.showReport=function(a,b,c){var d;d=jasmine.getGlobal().webkitNotifications.createNotification(a,b,c),d.replaceId=this.replaceId,d.show(),this.timeout>0&&setTimeout(function(){d.cancel()},this.timeout)},c}(jasmine.Reporter)})).call(this);
Oops, something went wrong.

0 comments on commit 5b4646f

Please sign in to comment.