Skip to content

Commit

Permalink
Re-organized repo and updated Jasmine
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottHamper committed Feb 5, 2013
1 parent 6f41dbf commit 184e18d
Show file tree
Hide file tree
Showing 10 changed files with 371 additions and 301 deletions.
40 changes: 18 additions & 22 deletions tests/SpecRunner.html → SpecRunner.html
@@ -1,52 +1,48 @@
<!doctype html>

<html lang="en">
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Jasmine Spec Runner</title>

<link href="lib/jasmine-1.1.0/jasmine_favicon.png" rel="shortcut icon" type="image/png" />
<title>Cookies.js Test Runner</title>

<link href="lib/jasmine-1.1.0/jasmine.css" rel="stylesheet" />
<script src="lib/jasmine-1.1.0/jasmine.js"></script>
<script src="lib/jasmine-1.1.0/jasmine-html.js"></script>
<link rel="shortcut icon" type="image/png" href="lib/jasmine-1.3.1/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" href="lib/jasmine-1.3.1/jasmine.css">
<script type="text/javascript" src="lib/jasmine-1.3.1/jasmine.js"></script>
<script type="text/javascript" src="lib/jasmine-1.3.1/jasmine-html.js"></script>

<!-- include source files here... -->
<script src="src/cookies.min.js"></script>
<script type="text/javascript" src="src/cookies.min.js"></script>

<!-- include spec files here... -->
<script src="spec/cookies-spec.js"></script>

<script type="text/javascript" src="spec/cookies-spec.js"></script>
<script type="text/javascript">
(function() {
var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 1000;

var htmlReporter = new jasmine.HtmlReporter();

jasmineEnv.addReporter(htmlReporter);

jasmineEnv.specFilter = function(spec) {
return htmlReporter.specFilter(spec);
};

var currentWindowOnload = window.onload;

window.onload = function() {
if (currentWindowOnload) {
currentWindowOnload();
currentWindowOnload();
}
execJasmine();
};

function execJasmine() {
jasmineEnv.execute();
}

})();
</script>
</head>
<body>

</body>
</html>
</html>
File renamed without changes.
Expand Up @@ -78,6 +78,7 @@ jasmine.HtmlReporter = function(_doc) {

createReporterDom(runner.env.versionString());
doc.body.appendChild(dom.reporter);
setExceptionHandling();

reporterView = new jasmine.HtmlReporter.ReporterView(dom);
reporterView.addSpecs(specs, self.specFilter);
Expand Down Expand Up @@ -131,7 +132,7 @@ jasmine.HtmlReporter = function(_doc) {
}

var paramMap = [];
var params = doc.location.search.substring(1).split('&');
var params = jasmine.HtmlReporter.parameters(doc);

for (var i = 0; i < params.length; i++) {
var p = params[i].split('=');
Expand All @@ -151,73 +152,77 @@ jasmine.HtmlReporter = function(_doc) {
self.createDom('span', { className: 'version' }, version)),

dom.symbolSummary = self.createDom('ul', {className: 'symbolSummary'}),
dom.alert = self.createDom('div', {className: 'alert'}),
dom.alert = self.createDom('div', {className: 'alert'},
self.createDom('span', { className: 'exceptions' },
self.createDom('label', { className: 'label', 'for': 'no_try_catch' }, 'No try/catch'),
self.createDom('input', { id: 'no_try_catch', type: 'checkbox' }))),
dom.results = self.createDom('div', {className: 'results'},
dom.summary = self.createDom('div', { className: 'summary' }),
dom.details = self.createDom('div', { id: 'details' }))
);
}
};
jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter);jasmine.HtmlReporterHelpers = {};

jasmine.HtmlReporterHelpers.createDom = function(type, attrs, childrenVarArgs) {
var el = document.createElement(type);
function noTryCatch() {
return window.location.search.match(/catch=false/);
}

for (var i = 2; i < arguments.length; i++) {
var child = arguments[i];
function searchWithCatch() {
var params = jasmine.HtmlReporter.parameters(window.document);
var removed = false;
var i = 0;

if (typeof child === 'string') {
el.appendChild(document.createTextNode(child));
} else {
if (child) {
el.appendChild(child);
while (!removed && i < params.length) {
if (params[i].match(/catch=/)) {
params.splice(i, 1);
removed = true;
}
i++;
}
}

for (var attr in attrs) {
if (attr == "className") {
el[attr] = attrs[attr];
} else {
el.setAttribute(attr, attrs[attr]);
if (jasmine.CATCH_EXCEPTIONS) {
params.push("catch=false");
}
}

return el;
};

jasmine.HtmlReporterHelpers.getSpecStatus = function(child) {
var results = child.results();
var status = results.passed() ? 'passed' : 'failed';
if (results.skipped) {
status = 'skipped';
return params.join("&");
}

return status;
};

jasmine.HtmlReporterHelpers.appendToSummary = function(child, childElement) {
var parentDiv = this.dom.summary;
var parentSuite = (typeof child.parentSuite == 'undefined') ? 'suite' : 'parentSuite';
var parent = child[parentSuite];
function setExceptionHandling() {
var chxCatch = document.getElementById('no_try_catch');

if (parent) {
if (typeof this.views.suites[parent.id] == 'undefined') {
this.views.suites[parent.id] = new jasmine.HtmlReporter.SuiteView(parent, this.dom, this.views);
if (noTryCatch()) {
chxCatch.setAttribute('checked', true);
jasmine.CATCH_EXCEPTIONS = false;
}
parentDiv = this.views.suites[parent.id].element;
chxCatch.onclick = function() {
window.location.search = searchWithCatch();
};
}

parentDiv.appendChild(childElement);
};
jasmine.HtmlReporter.parameters = function(doc) {
var paramStr = doc.location.search.substring(1);
var params = [];


jasmine.HtmlReporterHelpers.addHelpers = function(ctor) {
for(var fn in jasmine.HtmlReporterHelpers) {
ctor.prototype[fn] = jasmine.HtmlReporterHelpers[fn];
if (paramStr.length > 0) {
params = paramStr.split('&');
}
return params;
}
jasmine.HtmlReporter.sectionLink = function(sectionName) {
var link = '?';
var params = [];

if (sectionName) {
params.push('spec=' + encodeURIComponent(sectionName));
}
if (!jasmine.CATCH_EXCEPTIONS) {
params.push("catch=false");
}
if (params.length > 0) {
link += params.join("&");
}
};

return link;
};
jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter);
jasmine.HtmlReporter.ReporterView = function(dom) {
this.startedAt = new Date();
this.runningSpecCount = 0;
Expand Down Expand Up @@ -301,14 +306,14 @@ jasmine.HtmlReporter.ReporterView = function(dom) {

// currently running UI
if (isUndefined(this.runningAlert)) {
this.runningAlert = this.createDom('a', {href: "?", className: "runningAlert bar"});
this.runningAlert = this.createDom('a', { href: jasmine.HtmlReporter.sectionLink(), className: "runningAlert bar" });
dom.alert.appendChild(this.runningAlert);
}
this.runningAlert.innerHTML = "Running " + this.completeSpecCount + " of " + specPluralizedFor(this.totalSpecCount);

// skipped specs UI
if (isUndefined(this.skippedAlert)) {
this.skippedAlert = this.createDom('a', {href: "?", className: "skippedAlert bar"});
this.skippedAlert = this.createDom('a', { href: jasmine.HtmlReporter.sectionLink(), className: "skippedAlert bar" });
}

this.skippedAlert.innerHTML = "Skipping " + this.skippedCount + " of " + specPluralizedFor(this.totalSpecCount) + " - run all";
Expand All @@ -319,7 +324,7 @@ jasmine.HtmlReporter.ReporterView = function(dom) {

// passing specs UI
if (isUndefined(this.passedAlert)) {
this.passedAlert = this.createDom('span', {href: "?", className: "passingAlert bar"});
this.passedAlert = this.createDom('span', { href: jasmine.HtmlReporter.sectionLink(), className: "passingAlert bar" });
}
this.passedAlert.innerHTML = "Passing " + specPluralizedFor(this.passedCount);

Expand Down Expand Up @@ -391,11 +396,11 @@ jasmine.HtmlReporter.SpecView = function(spec, dom, views) {
this.dom.symbolSummary.appendChild(this.symbol);

this.summary = this.createDom('div', { className: 'specSummary' },
this.createDom('a', {
className: 'description',
href: '?spec=' + encodeURIComponent(this.spec.getFullName()),
title: this.spec.getFullName()
}, this.spec.description)
this.createDom('a', {
className: 'description',
href: jasmine.HtmlReporter.sectionLink(this.spec.getFullName()),
title: this.spec.getFullName()
}, this.spec.description)
);

this.detail = this.createDom('div', { className: 'specDetail' },
Expand Down Expand Up @@ -466,7 +471,7 @@ jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.SpecView);jasmine.Ht
this.views = views;

this.element = this.createDom('div', { className: 'suite' },
this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(this.suite.getFullName()) }, this.suite.description)
this.createDom('a', { className: 'description', href: jasmine.HtmlReporter.sectionLink(this.suite.getFullName()) }, this.suite.description)
);

this.appendToSummary(this.suite, this.element);
Expand Down
Expand Up @@ -19,6 +19,7 @@ body { background-color: #eeeeee; padding: 0; margin: 5px; overflow-y: scroll; }
#HTMLReporter .symbolSummary li.skipped:before { color: #bababa; content: "\02022"; }
#HTMLReporter .symbolSummary li.pending { line-height: 11px; }
#HTMLReporter .symbolSummary li.pending:before { color: #aaaaaa; content: "-"; }
#HTMLReporter .exceptions { color: #fff; float: right; margin-top: 5px; margin-right: 5px; }
#HTMLReporter .bar { line-height: 28px; font-size: 14px; display: block; color: #eee; }
#HTMLReporter .runningAlert { background-color: #666666; }
#HTMLReporter .skippedAlert { background-color: #aaaaaa; }
Expand Down

0 comments on commit 184e18d

Please sign in to comment.