Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

First release

  • Loading branch information...
commit 8fceae30c2520cb8f1ab0208630bf4f49484e2f1 1 parent bd8617d
@andrewtimberlake authored
View
13 README.markdown
@@ -0,0 +1,13 @@
+# jasmine-document-title-reporter
+
+A reporter for Jasmine that puts the results into the browser title/tab bar
+
+- Changes the document title to indicate number of failures or number of passed specs
+- Changes the favicon to a green/red dot
+
+I run my specs continuously in two browsers using livereload to re-run the specs every time a file is changed. Often the specs are run in a browser tab that is not the current tab I'm working on.
+This reporter gives you a visual indication on the state of your specs as you work.
+
+## Instalation
+
+Download jasmine_title_reporter.js and the 2 .ico files and place them in spec/javascripts/helpers/
View
63 document_title_reporter.js
@@ -0,0 +1,63 @@
+var DocumentTitleReporter = function(_doc) {
+ var self = this,
+ doc = _doc || window.document,
+ existingTitle = doc.title,
+ totalSpecsCount = 0,
+ skippedSpecs = 0,
+ runSpecs = 0,
+ failedSpecs = 0;
+
+ var updateTitle = function(text) {
+ document.title = text + " - " + existingTitle;
+ }
+
+ var removeShortcutIcons = function() {
+ linkTags = document.getElementsByTagName('link');
+ for(i = linkTags.length-1; i >= 0; i--) {
+ var linkTag = linkTags[i];
+ if(linkTag.getAttribute('rel') == 'shortcut icon') {
+ linkTag.parentNode.removeChild(linkTag);
+ }
+ }
+ }
+
+ var setShortcutIcon = function(icon) {
+ var head = document.getElementsByTagName('HEAD')[0]
+ var linkTag = document.createElement('LINK');
+ linkTag.setAttribute('rel', 'shortcut icon');
+ linkTag.setAttribute('type', 'image/x-icon');
+ linkTag.setAttribute('href', '/__spec__/helpers/'+icon+'.ico');
+ head.appendChild(linkTag);
+ }
+
+ self.reportRunnerStarting = function(runner) {
+ totalSpecsCount = runner.specs().length;
+ removeShortcutIcons();
+ updateTitle("Running... ");
+ }
+
+ self.reportRunnerResults = function(runner) {
+ var results = runner.results();
+ removeShortcutIcons();
+ if(failedSpecs == 0) {
+ setShortcutIcon('passed');
+ updateTitle(runSpecs + " of " + totalSpecsCount);
+ } else {
+ setShortcutIcon('failed');
+ updateTitle(failedSpecs + ' failed');
+ }
+ }
+
+ self.reportSpecResults = function(spec) {
+ var results = spec.results();
+ if(results.skipped) {
+ skippedSpecs++;
+ } else {
+ runSpecs++;
+ }
+ if(results.failedCount > 0) {
+ failedSpecs++;
+ }
+ }
+}
+jasmine.getEnv().addReporter(new DocumentTitleReporter())
View
BIN  failed.ico
Binary file not shown
View
BIN  passed.ico
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.