Show the name of the spec/suite that caused a deprecation

This commit is contained in:
Steve Gravrock
2020-09-13 12:39:42 -07:00
parent 51ad18cb28
commit e7daa429a1
8 changed files with 130 additions and 52 deletions

View File

@@ -581,12 +581,22 @@ getJasmineRequireObj().Env = function(j$) {
this.deprecated = function(deprecation) {
var runnable = currentRunnable() || topSuite;
var context;
if (runnable === topSuite) {
context = '';
} else if (runnable === currentSuite()) {
context = ' (in suite: ' + runnable.getFullName() + ')';
} else {
context = ' (in spec: ' + runnable.getFullName() + ')';
}
runnable.addDeprecationWarning(deprecation);
if (
typeof console !== 'undefined' &&
typeof console.error === 'function'
) {
console.error('DEPRECATION:', deprecation);
console.error('DEPRECATION: ' + deprecation + context);
}
};

View File

@@ -218,17 +218,21 @@ getJasmineRequireObj().QueueRunner = function(j$) {
if (retval && j$.isFunction_(retval.then)) {
// Issue a warning that matches the user's code
if (j$.isAsyncFunction_(fn)) {
this.deprecated('An asynchronous before/it/after ' +
'function was defined with the async keyword but also took a ' +
'done callback. This is not supported and will stop working in' +
' the future. Either remove the done callback (recommended) or ' +
'remove the async keyword.');
this.deprecated(
'An asynchronous before/it/after ' +
'function was defined with the async keyword but also took a ' +
'done callback. This is not supported and will stop working in' +
' the future. Either remove the done callback (recommended) or ' +
'remove the async keyword.'
);
} else {
this.deprecated('An asynchronous before/it/after ' +
'function took a done callback but also returned a promise. ' +
'This is not supported and will stop working in the future. ' +
'Either remove the done callback (recommended) or change the ' +
'function to not return a promise.');
this.deprecated(
'An asynchronous before/it/after ' +
'function took a done callback but also returned a promise. ' +
'This is not supported and will stop working in the future. ' +
'Either remove the done callback (recommended) or change the ' +
'function to not return a promise.'
);
}
}
};

View File

@@ -101,7 +101,7 @@ jasmineRequire.HtmlReporter = function(j$) {
if (result.status === 'failed') {
failures.push(failureDom(result));
}
addDeprecationWarnings(result);
addDeprecationWarnings(result, 'suite');
};
this.specStarted = function(result) {
@@ -137,7 +137,7 @@ jasmineRequire.HtmlReporter = function(j$) {
failures.push(failureDom(result));
}
addDeprecationWarnings(result);
addDeprecationWarnings(result, 'spec');
};
this.displaySpecInCorrectFormat = function(result) {
@@ -276,14 +276,27 @@ jasmineRequire.HtmlReporter = function(j$) {
addDeprecationWarnings(doneResult);
var warningBarClassName = 'jasmine-bar jasmine-warning';
for (i = 0; i < deprecationWarnings.length; i++) {
var warning = deprecationWarnings[i];
var context;
switch (deprecationWarnings[i].runnableType) {
case 'spec':
context = '(in spec: ' + deprecationWarnings[i].runnableName + ')';
break;
case 'suite':
context = '(in suite: ' + deprecationWarnings[i].runnableName + ')';
break;
default:
context = '';
}
alert.appendChild(
createDom(
'span',
{ className: warningBarClassName },
'DEPRECATION: ' + warning
{ className: 'jasmine-bar jasmine-warning' },
'DEPRECATION: ' + deprecationWarnings[i].message,
createDom('br'),
context
)
);
}
@@ -594,12 +607,18 @@ jasmineRequire.HtmlReporter = function(j$) {
return addToExistingQueryString('spec', els.join(' '));
}
function addDeprecationWarnings(result) {
function addDeprecationWarnings(result, runnableType) {
if (result && result.deprecationWarnings) {
for (var i = 0; i < result.deprecationWarnings.length; i++) {
var warning = result.deprecationWarnings[i].message;
debugger;
if (!j$.util.arrayContains(warning)) {
deprecationWarnings.push(warning);
debugger;
deprecationWarnings.push({
message: warning,
runnableName: result.fullName,
runnableType: runnableType
});
}
}
}