Skip to content

Commit

Permalink
First release
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtimberlake committed Dec 1, 2011
1 parent bd8617d commit 8fceae3
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
13 changes: 13 additions & 0 deletions 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/
63 changes: 63 additions & 0 deletions 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())
Binary file added failed.ico
Binary file not shown.
Binary file added passed.ico
Binary file not shown.

0 comments on commit 8fceae3

Please sign in to comment.