Merge branch 'deprecation-object' of https://github.com/UziTech/jasmine into UziTech-deprecation-object
- Merges #1498 from @UziTech
This commit is contained in:
@@ -641,8 +641,11 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
return this.getSpecName(this);
|
||||
};
|
||||
|
||||
Spec.prototype.addDeprecationWarning = function(msg) {
|
||||
this.result.deprecationWarnings.push(this.expectationResultFactory({ message: msg }));
|
||||
Spec.prototype.addDeprecationWarning = function(deprecation) {
|
||||
if (typeof deprecation === 'string') {
|
||||
deprecation = { message: deprecation };
|
||||
}
|
||||
this.result.deprecationWarnings.push(this.expectationResultFactory(deprecation));
|
||||
};
|
||||
|
||||
var extractCustomPendingMessage = function(e) {
|
||||
@@ -915,11 +918,11 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
handlingLoadErrors = false;
|
||||
};
|
||||
|
||||
this.deprecated = function(msg) {
|
||||
this.deprecated = function(deprecation) {
|
||||
var runnable = currentRunnable() || topSuite;
|
||||
runnable.addDeprecationWarning(msg);
|
||||
if(typeof console !== 'undefined' && typeof console.warn !== 'undefined') {
|
||||
console.error('DEPRECATION: ' + msg);
|
||||
runnable.addDeprecationWarning(deprecation);
|
||||
if(typeof console !== 'undefined' && typeof console.error === 'function') {
|
||||
console.error('DEPRECATION:', deprecation);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2530,10 +2533,14 @@ getJasmineRequireObj().buildExpectationResult = function() {
|
||||
|
||||
var error = options.error;
|
||||
if (!error) {
|
||||
try {
|
||||
throw new Error(message());
|
||||
} catch (e) {
|
||||
error = e;
|
||||
if (options.stack) {
|
||||
error = options;
|
||||
} else {
|
||||
try {
|
||||
throw new Error(message());
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
}
|
||||
}
|
||||
return stackFormatter(error);
|
||||
@@ -5749,8 +5756,11 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
}
|
||||
};
|
||||
|
||||
Suite.prototype.addDeprecationWarning = function(msg) {
|
||||
this.result.deprecationWarnings.push(this.expectationResultFactory({ message: msg }));
|
||||
Suite.prototype.addDeprecationWarning = function(deprecation) {
|
||||
if (typeof deprecation === 'string') {
|
||||
deprecation = { message: deprecation };
|
||||
}
|
||||
this.result.deprecationWarnings.push(this.expectationResultFactory(deprecation));
|
||||
};
|
||||
|
||||
function isFailure(args) {
|
||||
|
||||
@@ -2303,6 +2303,9 @@ describe("Env integration", function() {
|
||||
var env = new jasmineUnderTest.Env(),
|
||||
reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
|
||||
|
||||
// prevent deprecation from being desplayed
|
||||
spyOn(console, "error");
|
||||
|
||||
reporter.jasmineDone.and.callFake(function(result) {
|
||||
expect(result.deprecationWarnings).toEqual([
|
||||
jasmine.objectContaining({ message: 'top level deprecation' })
|
||||
@@ -2341,4 +2344,65 @@ describe("Env integration", function() {
|
||||
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it('should report deprecation stack with an error object', function(done) {
|
||||
var env = new jasmineUnderTest.Env(),
|
||||
exceptionFormatter = new jasmineUnderTest.ExceptionFormatter(),
|
||||
reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']),
|
||||
topLevelError, suiteLevelError, specLevelError;
|
||||
|
||||
try { throw new Error('top level deprecation') } catch (err) { topLevelError = err; }
|
||||
try { throw new Error('suite level deprecation') } catch (err) { suiteLevelError = err; }
|
||||
try { throw new Error('spec level deprecation') } catch (err) { specLevelError = err; }
|
||||
|
||||
// prevent deprecation from being desplayed
|
||||
spyOn(console, "error");
|
||||
|
||||
reporter.jasmineDone.and.callFake(function(result) {
|
||||
expect(result.deprecationWarnings).toEqual([
|
||||
jasmine.objectContaining({
|
||||
message: topLevelError.message,
|
||||
stack: exceptionFormatter.stack(topLevelError)
|
||||
})
|
||||
]);
|
||||
|
||||
expect(reporter.suiteDone).toHaveBeenCalledWith(jasmine.objectContaining({
|
||||
fullName: 'suite',
|
||||
deprecationWarnings: [
|
||||
jasmine.objectContaining({
|
||||
message: suiteLevelError.message,
|
||||
stack: exceptionFormatter.stack(suiteLevelError)
|
||||
})
|
||||
]
|
||||
}));
|
||||
|
||||
expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({
|
||||
fullName: 'suite spec',
|
||||
deprecationWarnings: [
|
||||
jasmine.objectContaining({
|
||||
message: specLevelError.message,
|
||||
stack: exceptionFormatter.stack(specLevelError)
|
||||
})
|
||||
]
|
||||
}));
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
env.addReporter(reporter);
|
||||
|
||||
env.deprecated(topLevelError);
|
||||
|
||||
env.describe('suite', function() {
|
||||
env.beforeAll(function() {
|
||||
env.deprecated(suiteLevelError);
|
||||
});
|
||||
|
||||
env.it('spec', function() {
|
||||
env.deprecated(specLevelError);
|
||||
});
|
||||
});
|
||||
|
||||
env.execute();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -200,11 +200,11 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
handlingLoadErrors = false;
|
||||
};
|
||||
|
||||
this.deprecated = function(msg) {
|
||||
this.deprecated = function(deprecation) {
|
||||
var runnable = currentRunnable() || topSuite;
|
||||
runnable.addDeprecationWarning(msg);
|
||||
if(typeof console !== 'undefined' && typeof console.warn !== 'undefined') {
|
||||
console.error('DEPRECATION: ' + msg);
|
||||
runnable.addDeprecationWarning(deprecation);
|
||||
if(typeof console !== 'undefined' && typeof console.error === 'function') {
|
||||
console.error('DEPRECATION:', deprecation);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -45,10 +45,14 @@ getJasmineRequireObj().buildExpectationResult = function() {
|
||||
|
||||
var error = options.error;
|
||||
if (!error) {
|
||||
try {
|
||||
throw new Error(message());
|
||||
} catch (e) {
|
||||
error = e;
|
||||
if (options.stack) {
|
||||
error = options;
|
||||
} else {
|
||||
try {
|
||||
throw new Error(message());
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
}
|
||||
}
|
||||
return stackFormatter(error);
|
||||
|
||||
@@ -152,8 +152,11 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
return this.getSpecName(this);
|
||||
};
|
||||
|
||||
Spec.prototype.addDeprecationWarning = function(msg) {
|
||||
this.result.deprecationWarnings.push(this.expectationResultFactory({ message: msg }));
|
||||
Spec.prototype.addDeprecationWarning = function(deprecation) {
|
||||
if (typeof deprecation === 'string') {
|
||||
deprecation = { message: deprecation };
|
||||
}
|
||||
this.result.deprecationWarnings.push(this.expectationResultFactory(deprecation));
|
||||
};
|
||||
|
||||
var extractCustomPendingMessage = function(e) {
|
||||
|
||||
@@ -148,8 +148,11 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
}
|
||||
};
|
||||
|
||||
Suite.prototype.addDeprecationWarning = function(msg) {
|
||||
this.result.deprecationWarnings.push(this.expectationResultFactory({ message: msg }));
|
||||
Suite.prototype.addDeprecationWarning = function(deprecation) {
|
||||
if (typeof deprecation === 'string') {
|
||||
deprecation = { message: deprecation };
|
||||
}
|
||||
this.result.deprecationWarnings.push(this.expectationResultFactory(deprecation));
|
||||
};
|
||||
|
||||
function isFailure(args) {
|
||||
|
||||
Reference in New Issue
Block a user