Compare commits
4 Commits
master
...
fancy-html
Author | SHA1 | Date |
---|---|---|
Lee Byrd & Christian Williams | a5926d22a1 | |
Lee Byrd & Christian Williams | 25f57c3321 | |
Christian Williams | 3d66c5f051 | |
Christian Williams | 9384512138 |
|
@ -12,7 +12,7 @@
|
||||||
<body>
|
<body>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var jasmineEnv = jasmine.getEnv();
|
var jasmineEnv = jasmine.getEnv();
|
||||||
jasmineEnv.reporter = new jasmine.TrivialReporter();
|
jasmineEnv.addReporter(jasmine.TrivialReporter());
|
||||||
jasmineEnv.execute();
|
jasmineEnv.execute();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ jasmine.TrivialReporter = function(doc) {
|
||||||
this.document = doc || document;
|
this.document = doc || document;
|
||||||
this.suiteDivs = {};
|
this.suiteDivs = {};
|
||||||
this.logRunningSpecs = false;
|
this.logRunningSpecs = false;
|
||||||
|
this.domPrettyPrint = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarArgs) {
|
jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarArgs) {
|
||||||
|
@ -145,7 +146,7 @@ jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
|
||||||
if (result.type == 'log') {
|
if (result.type == 'log') {
|
||||||
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
|
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
|
||||||
} else if (result.type == 'expect' && result.passed && !result.passed()) {
|
} else if (result.type == 'expect' && result.passed && !result.passed()) {
|
||||||
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
|
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, this.reportWhatever(result)));
|
||||||
|
|
||||||
if (result.trace.stack) {
|
if (result.trace.stack) {
|
||||||
messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
|
messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
|
||||||
|
@ -160,6 +161,31 @@ jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
|
||||||
this.suiteDivs[spec.suite.id].appendChild(specDiv);
|
this.suiteDivs[spec.suite.id].appendChild(specDiv);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
jasmine.TrivialReporter.prototype.reportWhatever = function(result) {
|
||||||
|
if (this.domPrettyPrint) {
|
||||||
|
var actualDiv, expectedDiv;
|
||||||
|
|
||||||
|
var matcherString = result.matcherName;
|
||||||
|
var table = this.createDom('table', {},
|
||||||
|
this.createDom('tr', {},
|
||||||
|
this.createDom('td', {colspan: 2}, result.message)),
|
||||||
|
this.createDom('tr', {},
|
||||||
|
this.createDom('th', {}, 'expect()'),
|
||||||
|
this.createDom('th', {}, matcherString + "()")),
|
||||||
|
this.createDom('tr', {},
|
||||||
|
actualDiv = this.createDom('td'),
|
||||||
|
expectedDiv = this.createDom('td'))
|
||||||
|
);
|
||||||
|
|
||||||
|
new jasmine.HtmlPrettyPrinter(actualDiv).format(result.actual);
|
||||||
|
new jasmine.HtmlPrettyPrinter(expectedDiv).format(result.expected);
|
||||||
|
|
||||||
|
return table;
|
||||||
|
} else {
|
||||||
|
return result.message;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
jasmine.TrivialReporter.prototype.log = function() {
|
jasmine.TrivialReporter.prototype.log = function() {
|
||||||
var console = jasmine.getGlobal().console;
|
var console = jasmine.getGlobal().console;
|
||||||
if (console && console.log) console.log.apply(console, arguments);
|
if (console && console.log) console.log.apply(console, arguments);
|
||||||
|
@ -180,3 +206,61 @@ jasmine.TrivialReporter.prototype.specFilter = function(spec) {
|
||||||
if (!paramMap["spec"]) return true;
|
if (!paramMap["spec"]) return true;
|
||||||
return spec.getFullName().indexOf(paramMap["spec"]) == 0;
|
return spec.getFullName().indexOf(paramMap["spec"]) == 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
jasmine.HtmlPrettyPrinter = function(el) {
|
||||||
|
jasmine.PrettyPrinter.call(this);
|
||||||
|
this.el = el;
|
||||||
|
};
|
||||||
|
|
||||||
|
jasmine.util.inherit(jasmine.HtmlPrettyPrinter, jasmine.PrettyPrinter);
|
||||||
|
|
||||||
|
jasmine.HtmlPrettyPrinter.prototype.createDom = jasmine.FancyHtmlReporter.prototype.createDom;
|
||||||
|
|
||||||
|
jasmine.HtmlPrettyPrinter.prototype.emitScalar = function(value) {
|
||||||
|
this.append(this.createDom('pre', {}, value));
|
||||||
|
};
|
||||||
|
|
||||||
|
jasmine.HtmlPrettyPrinter.prototype.emitString = function(value) {
|
||||||
|
this.append(this.createDom('pre', {className: 'string'}, value));
|
||||||
|
};
|
||||||
|
|
||||||
|
jasmine.HtmlPrettyPrinter.prototype.emitArray = function(array) {
|
||||||
|
var table = this.createDom('table', {className: 'array'});
|
||||||
|
|
||||||
|
for (var i = 0; i < array.length; i++) {
|
||||||
|
var oldEl = this.el;
|
||||||
|
this.el = this.createDom('td');
|
||||||
|
table.appendChild(this.createDom('tr', {}, this.el));
|
||||||
|
this.format(array[i]);
|
||||||
|
this.el = oldEl;
|
||||||
|
}
|
||||||
|
this.append(table);
|
||||||
|
};
|
||||||
|
|
||||||
|
jasmine.HtmlPrettyPrinter.prototype.emitObject = function(obj) {
|
||||||
|
var self = this;
|
||||||
|
var table = this.createDom('table', {className: 'object'});
|
||||||
|
|
||||||
|
this.iterateObject(obj, function(property, isGetter) {
|
||||||
|
var tr = self.createDom('tr');
|
||||||
|
table.appendChild(tr);
|
||||||
|
|
||||||
|
tr.appendChild(self.createDom('th', {}, property));
|
||||||
|
|
||||||
|
var oldEl = self.el;
|
||||||
|
self.el = self.createDom('td');
|
||||||
|
tr.appendChild(self.createDom('th', {}, self.el));
|
||||||
|
if (isGetter) {
|
||||||
|
self.el.appendChild(self.createDom('pre', {className: 'getter'}, '<getter>'));
|
||||||
|
} else {
|
||||||
|
self.format(obj[property]);
|
||||||
|
}
|
||||||
|
self.el = oldEl;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.append(table);
|
||||||
|
};
|
||||||
|
|
||||||
|
jasmine.HtmlPrettyPrinter.prototype.append = function(element) {
|
||||||
|
this.el.appendChild(element);
|
||||||
|
};
|
||||||
|
|
|
@ -131,6 +131,38 @@ body {
|
||||||
color: black;
|
color: black;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.resultMessage > table {
|
||||||
|
background-color: white;
|
||||||
|
width: 100%;
|
||||||
|
font-size: .8em;
|
||||||
|
padding: .5em;
|
||||||
|
margin: .5em;
|
||||||
|
border: 1px solid black;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resultMessage > table > tr > th, .resultMessage > table > tr > td {
|
||||||
|
text-align: left;
|
||||||
|
width: 50%;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resultMessage td {
|
||||||
|
vertical-align: top;
|
||||||
|
border: 1px inset;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resultMessage pre {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resultMessage .object, .resultMessage .array {
|
||||||
|
}
|
||||||
|
|
||||||
|
.resultMessage .string {
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
.stackTrace {
|
.stackTrace {
|
||||||
white-space: pre;
|
white-space: pre;
|
||||||
font-size: .8em;
|
font-size: .8em;
|
||||||
|
|
|
@ -59,12 +59,13 @@
|
||||||
var jasmineEnv = jasmine.getEnv();
|
var jasmineEnv = jasmine.getEnv();
|
||||||
jasmineEnv.updateInterval = 1000;
|
jasmineEnv.updateInterval = 1000;
|
||||||
|
|
||||||
var trivialReporter = new jasmine.TrivialReporter();
|
var reporter = new jasmine.TrivialReporter();
|
||||||
|
reporter.domPrettyPrint = true;
|
||||||
|
|
||||||
jasmineEnv.addReporter(trivialReporter);
|
jasmineEnv.addReporter(reporter);
|
||||||
|
|
||||||
jasmineEnv.specFilter = function(spec) {
|
jasmineEnv.specFilter = function(spec) {
|
||||||
return trivialReporter.specFilter(spec);
|
return reporter.specFilter(spec);
|
||||||
};
|
};
|
||||||
|
|
||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
|
|
|
@ -155,6 +155,15 @@ describe("TrivialReporter", function() {
|
||||||
var errorDiv = findElement(divs, 'resultMessage fail');
|
var errorDiv = findElement(divs, 'resultMessage fail');
|
||||||
expect(errorDiv.innerHTML).toEqual("Expected '1 < 2' to <b>e null, & it was not");
|
expect(errorDiv.innerHTML).toEqual("Expected '1 < 2' to <b>e null, & it was not");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
xit("should not look weird", function() {
|
||||||
|
expect(123).toBeLessThan(121);
|
||||||
|
expect(jasmine.createSpy("uncalled spy")).toHaveBeenCalled();
|
||||||
|
expect(jasmine.createSpy("uncalled spy")).toHaveBeenCalledWith(123, 456);
|
||||||
|
|
||||||
|
expect(true).not.toEqual(true);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("log messages", function() {
|
describe("log messages", function() {
|
||||||
|
|
Loading…
Reference in New Issue