Add ability to report deprecation warnings from within the suite

[#154746527]
This commit is contained in:
Gregg Van Hove
2018-02-05 11:19:15 -08:00
parent 70bce55721
commit 5afe1222f4
6 changed files with 101 additions and 4 deletions
+24 -2
View File
@@ -505,6 +505,7 @@ getJasmineRequireObj().Spec = function(j$) {
* @property {String} fullName - The full description including all ancestors of this spec. * @property {String} fullName - The full description including all ancestors of this spec.
* @property {Expectation[]} failedExpectations - The list of expectations that failed during execution of this spec. * @property {Expectation[]} failedExpectations - The list of expectations that failed during execution of this spec.
* @property {Expectation[]} passedExpectations - The list of expectations that passed during execution of this spec. * @property {Expectation[]} passedExpectations - The list of expectations that passed during execution of this spec.
* @property {Expectation[]} deprecationWarnings - The list of deprecation warnings that occurred during execution this spec.
* @property {String} pendingReason - If the spec is {@link pending}, this will be the reason. * @property {String} pendingReason - If the spec is {@link pending}, this will be the reason.
* @property {String} status - Once the spec has completed, this string represents the pass/fail status of this spec. * @property {String} status - Once the spec has completed, this string represents the pass/fail status of this spec.
*/ */
@@ -514,6 +515,7 @@ getJasmineRequireObj().Spec = function(j$) {
fullName: this.getFullName(), fullName: this.getFullName(),
failedExpectations: [], failedExpectations: [],
passedExpectations: [], passedExpectations: [],
deprecationWarnings: [],
pendingReason: '' pendingReason: ''
}; };
} }
@@ -629,6 +631,10 @@ getJasmineRequireObj().Spec = function(j$) {
return this.getSpecName(this); return this.getSpecName(this);
}; };
Spec.prototype.addDeprecationWarning = function(msg) {
this.result.deprecationWarnings.push(this.expectationResultFactory({ message: msg }));
};
var extractCustomPendingMessage = function(e) { var extractCustomPendingMessage = function(e) {
var fullMessage = e.toString(), var fullMessage = e.toString(),
boilerplateStart = fullMessage.indexOf(Spec.pendingSpecExceptionMessage), boilerplateStart = fullMessage.indexOf(Spec.pendingSpecExceptionMessage),
@@ -933,6 +939,14 @@ getJasmineRequireObj().Env = function(j$) {
return seed; return seed;
}; };
this.deprecated = function(msg) {
var runnable = currentRunnable() || topSuite;
runnable.addDeprecationWarning(msg);
if(typeof console !== 'undefined' && typeof console.warn !== 'undefined') {
console.error('DEPRECATION: ' + msg);
}
};
var queueRunnerFactory = function(options) { var queueRunnerFactory = function(options) {
options.catchException = catchException; options.catchException = catchException;
options.clearStack = options.clearStack || clearStack; options.clearStack = options.clearStack || clearStack;
@@ -1025,10 +1039,12 @@ getJasmineRequireObj().Env = function(j$) {
* @typedef JasmineDoneInfo * @typedef JasmineDoneInfo
* @property {Order} order - Information about the ordering (random or not) of this execution of the suite. * @property {Order} order - Information about the ordering (random or not) of this execution of the suite.
* @property {Expectation[]} failedExpectations - List of expectations that failed in an {@link afterAll} at the global level. * @property {Expectation[]} failedExpectations - List of expectations that failed in an {@link afterAll} at the global level.
* @property {Expectation[]} deprecationWarnings - List of deprecation warnings that occurred at the global level.
*/ */
reporter.jasmineDone({ reporter.jasmineDone({
order: order, order: order,
failedExpectations: topSuite.result.failedExpectations failedExpectations: topSuite.result.failedExpectations,
deprecationWarnings: topSuite.result.deprecationWarnings
}); });
}); });
}; };
@@ -5147,13 +5163,15 @@ getJasmineRequireObj().Suite = function(j$) {
* @property {String} description - The description text passed to the {@link describe} that made this suite. * @property {String} description - The description text passed to the {@link describe} that made this suite.
* @property {String} fullName - The full description including all ancestors of this suite. * @property {String} fullName - The full description including all ancestors of this suite.
* @property {Expectation[]} failedExpectations - The list of expectations that failed in an {@link afterAll} for this suite. * @property {Expectation[]} failedExpectations - The list of expectations that failed in an {@link afterAll} for this suite.
* @property {Expectation[]} deprecationWarnings - The list of deprecation warnings that occurred on this suite.
* @property {String} status - Once the suite has completed, this string represents the pass/fail status of this suite. * @property {String} status - Once the suite has completed, this string represents the pass/fail status of this suite.
*/ */
this.result = { this.result = {
id: this.id, id: this.id,
description: this.description, description: this.description,
fullName: this.getFullName(), fullName: this.getFullName(),
failedExpectations: [] failedExpectations: [],
deprecationWarnings: []
}; };
} }
@@ -5273,6 +5291,10 @@ getJasmineRequireObj().Suite = function(j$) {
} }
}; };
Suite.prototype.addDeprecationWarning = function(msg) {
this.result.deprecationWarnings.push(this.expectationResultFactory({ message: msg }));
};
function isAfterAll(children) { function isAfterAll(children) {
return children && children[0].result.status; return children && children[0].result.status;
} }
+1
View File
@@ -222,6 +222,7 @@ describe("Spec", function() {
fullName: 'a suite with a spec', fullName: 'a suite with a spec',
failedExpectations: [], failedExpectations: [],
passedExpectations: [], passedExpectations: [],
deprecationWarnings: [],
pendingReason: '' pendingReason: ''
}); });
}); });
+52
View File
@@ -2004,4 +2004,56 @@ describe("Env integration", function() {
env.execute(); env.execute();
}); });
it('should report deprecation warnings on the correct specs and suites', function(done) {
var env = new jasmineUnderTest.Env(),
reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
reporter.jasmineDone.and.callFake(function(result) {
expect(result.deprecationWarnings).toEqual([
jasmine.objectContaining({
message: 'top level deprecation',
stack: jasmine.any(String)
})
]);
expect(reporter.suiteDone).toHaveBeenCalledWith(jasmine.objectContaining({
fullName: 'suite',
deprecationWarnings: [
jasmine.objectContaining({
message: 'suite level deprecation',
stack: jasmine.any(String)
})
]
}));
expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({
fullName: 'suite spec',
deprecationWarnings: [
jasmine.objectContaining({
message: 'spec level deprecation',
stack: jasmine.any(String)
})
]
}));
done();
});
env.addReporter(reporter);
env.deprecated('top level deprecation');
env.describe('suite', function() {
env.beforeAll(function() {
env.deprecated('suite level deprecation');
});
env.it('spec', function() {
env.deprecated('spec level deprecation');
});
});
env.execute();
});
}); });
+11 -1
View File
@@ -234,6 +234,14 @@ getJasmineRequireObj().Env = function(j$) {
return seed; return seed;
}; };
this.deprecated = function(msg) {
var runnable = currentRunnable() || topSuite;
runnable.addDeprecationWarning(msg);
if(typeof console !== 'undefined' && typeof console.warn !== 'undefined') {
console.error('DEPRECATION: ' + msg);
}
};
var queueRunnerFactory = function(options) { var queueRunnerFactory = function(options) {
options.catchException = catchException; options.catchException = catchException;
options.clearStack = options.clearStack || clearStack; options.clearStack = options.clearStack || clearStack;
@@ -326,10 +334,12 @@ getJasmineRequireObj().Env = function(j$) {
* @typedef JasmineDoneInfo * @typedef JasmineDoneInfo
* @property {Order} order - Information about the ordering (random or not) of this execution of the suite. * @property {Order} order - Information about the ordering (random or not) of this execution of the suite.
* @property {Expectation[]} failedExpectations - List of expectations that failed in an {@link afterAll} at the global level. * @property {Expectation[]} failedExpectations - List of expectations that failed in an {@link afterAll} at the global level.
* @property {Expectation[]} deprecationWarnings - List of deprecation warnings that occurred at the global level.
*/ */
reporter.jasmineDone({ reporter.jasmineDone({
order: order, order: order,
failedExpectations: topSuite.result.failedExpectations failedExpectations: topSuite.result.failedExpectations,
deprecationWarnings: topSuite.result.deprecationWarnings
}); });
}); });
}; };
+6
View File
@@ -25,6 +25,7 @@ getJasmineRequireObj().Spec = function(j$) {
* @property {String} fullName - The full description including all ancestors of this spec. * @property {String} fullName - The full description including all ancestors of this spec.
* @property {Expectation[]} failedExpectations - The list of expectations that failed during execution of this spec. * @property {Expectation[]} failedExpectations - The list of expectations that failed during execution of this spec.
* @property {Expectation[]} passedExpectations - The list of expectations that passed during execution of this spec. * @property {Expectation[]} passedExpectations - The list of expectations that passed during execution of this spec.
* @property {Expectation[]} deprecationWarnings - The list of deprecation warnings that occurred during execution this spec.
* @property {String} pendingReason - If the spec is {@link pending}, this will be the reason. * @property {String} pendingReason - If the spec is {@link pending}, this will be the reason.
* @property {String} status - Once the spec has completed, this string represents the pass/fail status of this spec. * @property {String} status - Once the spec has completed, this string represents the pass/fail status of this spec.
*/ */
@@ -34,6 +35,7 @@ getJasmineRequireObj().Spec = function(j$) {
fullName: this.getFullName(), fullName: this.getFullName(),
failedExpectations: [], failedExpectations: [],
passedExpectations: [], passedExpectations: [],
deprecationWarnings: [],
pendingReason: '' pendingReason: ''
}; };
} }
@@ -149,6 +151,10 @@ getJasmineRequireObj().Spec = function(j$) {
return this.getSpecName(this); return this.getSpecName(this);
}; };
Spec.prototype.addDeprecationWarning = function(msg) {
this.result.deprecationWarnings.push(this.expectationResultFactory({ message: msg }));
};
var extractCustomPendingMessage = function(e) { var extractCustomPendingMessage = function(e) {
var fullMessage = e.toString(), var fullMessage = e.toString(),
boilerplateStart = fullMessage.indexOf(Spec.pendingSpecExceptionMessage), boilerplateStart = fullMessage.indexOf(Spec.pendingSpecExceptionMessage),
+7 -1
View File
@@ -21,13 +21,15 @@ getJasmineRequireObj().Suite = function(j$) {
* @property {String} description - The description text passed to the {@link describe} that made this suite. * @property {String} description - The description text passed to the {@link describe} that made this suite.
* @property {String} fullName - The full description including all ancestors of this suite. * @property {String} fullName - The full description including all ancestors of this suite.
* @property {Expectation[]} failedExpectations - The list of expectations that failed in an {@link afterAll} for this suite. * @property {Expectation[]} failedExpectations - The list of expectations that failed in an {@link afterAll} for this suite.
* @property {Expectation[]} deprecationWarnings - The list of deprecation warnings that occurred on this suite.
* @property {String} status - Once the suite has completed, this string represents the pass/fail status of this suite. * @property {String} status - Once the suite has completed, this string represents the pass/fail status of this suite.
*/ */
this.result = { this.result = {
id: this.id, id: this.id,
description: this.description, description: this.description,
fullName: this.getFullName(), fullName: this.getFullName(),
failedExpectations: [] failedExpectations: [],
deprecationWarnings: []
}; };
} }
@@ -147,6 +149,10 @@ getJasmineRequireObj().Suite = function(j$) {
} }
}; };
Suite.prototype.addDeprecationWarning = function(msg) {
this.result.deprecationWarnings.push(this.expectationResultFactory({ message: msg }));
};
function isAfterAll(children) { function isAfterAll(children) {
return children && children[0].result.status; return children && children[0].result.status;
} }