Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bd8617d
commit 8fceae3
Showing
4 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 not shown.
Binary file not shown.