Display deprecation warnings in HTML reporter

- Also no longer check for stack since IE doesn't do that

[#154746527]
This commit is contained in:
Gregg Van Hove
2018-02-05 12:11:36 -08:00
parent 5afe1222f4
commit 24bf3489dc
6 changed files with 87 additions and 14 deletions

View File

@@ -88,7 +88,8 @@ jasmineRequire.HtmlReporter = function(j$) {
results = [],
htmlReporterMain,
symbols,
failedSuites = [];
failedSuites = [],
deprecationWarnings = [];
this.initialize = function() {
clearPrior();
@@ -126,6 +127,7 @@ jasmineRequire.HtmlReporter = function(j$) {
}
stateBuilder.suiteDone(result);
addDeprecationWarnings(result);
};
this.specStarted = function(result) {
@@ -169,6 +171,8 @@ jasmineRequire.HtmlReporter = function(j$) {
failures.push(failure);
}
addDeprecationWarnings(result);
};
this.jasmineDone = function(doneResult) {
@@ -278,6 +282,14 @@ jasmineRequire.HtmlReporter = function(j$) {
alert.appendChild(createDom('span', {className: errorBarClassName}, errorBarMessagePrefix + failure.message));
}
addDeprecationWarnings(doneResult);
var warningBarClassName = 'jasmine-bar jasmine-warning';
for(i = 0; i < deprecationWarnings.length; i++) {
var warning = deprecationWarnings[i];
alert.appendChild(createDom('span', {className: warningBarClassName}, 'DEPRECATION: ' + warning.message));
}
var results = find('.jasmine-results');
results.appendChild(summary);
@@ -352,6 +364,12 @@ jasmineRequire.HtmlReporter = function(j$) {
return this;
function addDeprecationWarnings(result) {
if (result && result.deprecationWarnings && result.deprecationWarnings.length > 0) {
deprecationWarnings = deprecationWarnings.concat(result.deprecationWarnings);
}
}
function find(selector) {
return getContainer().querySelector('.jasmine_html-reporter ' + selector);
}

View File

@@ -33,6 +33,7 @@ body { overflow-y: scroll; }
.jasmine_html-reporter .jasmine-bar.jasmine-passed { background-color: #007069; }
.jasmine_html-reporter .jasmine-bar.jasmine-skipped { background-color: #bababa; }
.jasmine_html-reporter .jasmine-bar.jasmine-errored { background-color: #ca3a11; }
.jasmine_html-reporter .jasmine-bar.jasmine-warning { background-color: #ba9d37; }
.jasmine_html-reporter .jasmine-bar.jasmine-menu { background-color: #fff; color: #aaa; }
.jasmine_html-reporter .jasmine-bar.jasmine-menu a { color: #333; }
.jasmine_html-reporter .jasmine-bar a { color: white; }

View File

@@ -2011,29 +2011,20 @@ describe("Env integration", function() {
reporter.jasmineDone.and.callFake(function(result) {
expect(result.deprecationWarnings).toEqual([
jasmine.objectContaining({
message: 'top level deprecation',
stack: jasmine.any(String)
})
jasmine.objectContaining({ message: 'top level deprecation' })
]);
expect(reporter.suiteDone).toHaveBeenCalledWith(jasmine.objectContaining({
fullName: 'suite',
deprecationWarnings: [
jasmine.objectContaining({
message: 'suite level deprecation',
stack: jasmine.any(String)
})
jasmine.objectContaining({ message: 'suite level deprecation' })
]
}));
expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({
fullName: 'suite spec',
deprecationWarnings: [
jasmine.objectContaining({
message: 'spec level deprecation',
stack: jasmine.any(String)
})
jasmine.objectContaining({ message: 'spec level deprecation' })
]
}));

View File

@@ -208,6 +208,47 @@ describe("New HtmlReporter", function() {
});
});
describe('when there are deprecation warnings', function() {
it('displays the messages in their own alert bars', function() {
var env = new jasmineUnderTest.Env(),
container = document.createElement('div'),
getContainer = function() { return container; },
reporter = new jasmineUnderTest.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() { return document.createElement.apply(document, arguments); },
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
});
reporter.initialize();
reporter.jasmineStarted({});
reporter.specDone({
status: 'passed',
deprecationWarnings: [{ message: 'spec deprecation' }],
failedExpectations: [],
passedExpectations: []
});
reporter.suiteDone({
status: 'passed',
deprecationWarnings: [{ message: 'suite deprecation' }],
failedExpectations: []
});
reporter.jasmineDone({
deprecationWarnings: [{ message: 'global deprecation' }],
failedExpectations: []
});
var alertBars = container.querySelectorAll(".jasmine-alert .jasmine-bar");
expect(alertBars.length).toEqual(4);
expect(alertBars[1].innerHTML).toMatch(/spec deprecation/);
expect(alertBars[1].getAttribute("class")).toEqual('jasmine-bar jasmine-warning');
expect(alertBars[2].innerHTML).toMatch(/suite deprecation/);
expect(alertBars[3].innerHTML).toMatch(/global deprecation/);
});
});
describe("when Jasmine is done", function() {
it("adds a warning to the link title of specs that have no expectations", function() {
if (!window.console) {

View File

@@ -59,7 +59,8 @@ jasmineRequire.HtmlReporter = function(j$) {
results = [],
htmlReporterMain,
symbols,
failedSuites = [];
failedSuites = [],
deprecationWarnings = [];
this.initialize = function() {
clearPrior();
@@ -97,6 +98,7 @@ jasmineRequire.HtmlReporter = function(j$) {
}
stateBuilder.suiteDone(result);
addDeprecationWarnings(result);
};
this.specStarted = function(result) {
@@ -140,6 +142,8 @@ jasmineRequire.HtmlReporter = function(j$) {
failures.push(failure);
}
addDeprecationWarnings(result);
};
this.jasmineDone = function(doneResult) {
@@ -249,6 +253,14 @@ jasmineRequire.HtmlReporter = function(j$) {
alert.appendChild(createDom('span', {className: errorBarClassName}, errorBarMessagePrefix + failure.message));
}
addDeprecationWarnings(doneResult);
var warningBarClassName = 'jasmine-bar jasmine-warning';
for(i = 0; i < deprecationWarnings.length; i++) {
var warning = deprecationWarnings[i];
alert.appendChild(createDom('span', {className: warningBarClassName}, 'DEPRECATION: ' + warning.message));
}
var results = find('.jasmine-results');
results.appendChild(summary);
@@ -323,6 +335,12 @@ jasmineRequire.HtmlReporter = function(j$) {
return this;
function addDeprecationWarnings(result) {
if (result && result.deprecationWarnings && result.deprecationWarnings.length > 0) {
deprecationWarnings = deprecationWarnings.concat(result.deprecationWarnings);
}
}
function find(selector) {
return getContainer().querySelector('.jasmine_html-reporter ' + selector);
}

View File

@@ -216,6 +216,10 @@ body {
background-color: $failing-color;
}
&.jasmine-warning {
background-color: $pending-color;
}
&.jasmine-menu {
background-color: #fff;
color: $faint-text-color;