Improved & unified deprecation handling
* De-duplication now happens in core, not in reporters. This ensures that the console doesn't get flooded. * Stack traces are opt-out, not opt-in. * The current runnable is not reported or logged for certain deprecations where it's irrelevant. * HtmlReporter shows stack traces in expandable widgets. * Env#deprecated and Env#deprecatedOnceWithStack are merged.
This commit is contained in:
@@ -0,0 +1,329 @@
|
||||
/* eslint no-console: 0 */
|
||||
describe('Deprecator', function() {
|
||||
describe('#deprecate', function() {
|
||||
beforeEach(function() {
|
||||
spyOn(console, 'error');
|
||||
});
|
||||
|
||||
it('logs the mesage without context when the runnable is the top suite', function() {
|
||||
var runnable = { addDeprecationWarning: function() {} };
|
||||
var deprecator = new jasmineUnderTest.Deprecator(runnable);
|
||||
deprecator.verboseDeprecations(true);
|
||||
|
||||
deprecator.addDeprecationWarning(runnable, 'the message', {
|
||||
omitStackTrace: true
|
||||
});
|
||||
|
||||
expect(console.error).toHaveBeenCalledWith('DEPRECATION: the message');
|
||||
});
|
||||
|
||||
it('logs the message in a descendant suite', function() {
|
||||
var runnable = {
|
||||
addDeprecationWarning: function() {},
|
||||
getFullName: function() {
|
||||
return 'the suite';
|
||||
},
|
||||
children: []
|
||||
};
|
||||
var deprecator = new jasmineUnderTest.Deprecator({});
|
||||
deprecator.verboseDeprecations(true);
|
||||
|
||||
deprecator.addDeprecationWarning(runnable, 'the message', {
|
||||
omitStackTrace: true
|
||||
});
|
||||
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
'DEPRECATION: the message (in suite: the suite)'
|
||||
);
|
||||
});
|
||||
|
||||
it('logs and reports the message in a spec', function() {
|
||||
var runnable = {
|
||||
addDeprecationWarning: function() {},
|
||||
getFullName: function() {
|
||||
return 'the spec';
|
||||
}
|
||||
};
|
||||
var deprecator = new jasmineUnderTest.Deprecator({});
|
||||
deprecator.verboseDeprecations(true);
|
||||
|
||||
deprecator.addDeprecationWarning(runnable, 'the message', {
|
||||
omitStackTrace: true
|
||||
});
|
||||
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
'DEPRECATION: the message (in spec: the spec)'
|
||||
);
|
||||
});
|
||||
|
||||
it('logs and reports the message without runnable info when ignoreRunnable is true', function() {
|
||||
var topSuite = jasmine.createSpyObj('topSuite', [
|
||||
'addDeprecationWarning',
|
||||
'getFullName'
|
||||
]);
|
||||
var deprecator = new jasmineUnderTest.Deprecator(topSuite);
|
||||
var runnable = jasmine.createSpyObj('spec', [
|
||||
'addDeprecationWarning',
|
||||
'getFullName'
|
||||
]);
|
||||
runnable.getFullName.and.returnValue('a spec');
|
||||
|
||||
deprecator.addDeprecationWarning(runnable, 'the message', {
|
||||
ignoreRunnable: true
|
||||
});
|
||||
|
||||
expect(topSuite.addDeprecationWarning).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringMatching(/^the message/)
|
||||
})
|
||||
);
|
||||
expect(runnable.addDeprecationWarning).not.toHaveBeenCalled();
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(/the message/)
|
||||
);
|
||||
expect(console.error).not.toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(/a spec/)
|
||||
);
|
||||
});
|
||||
|
||||
describe('with no options', function() {
|
||||
it('includes the stack trace', function() {
|
||||
testStackTrace(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
it('omits the stack trace when omitStackTrace is true', function() {
|
||||
testNoStackTrace({ omitStackTrace: true });
|
||||
});
|
||||
|
||||
it('includes the stack trace when omitStackTrace is false', function() {
|
||||
testStackTrace({ omitStackTrace: false });
|
||||
});
|
||||
|
||||
it('includes the stack trace when omitStackTrace is undefined', function() {
|
||||
testStackTrace({ includeStackTrace: undefined });
|
||||
});
|
||||
|
||||
it('emits the deprecation only once when verboseDeprecations is not set', function() {
|
||||
var deprecator = new jasmineUnderTest.Deprecator({});
|
||||
var runnable1 = jasmine.createSpyObj('runnable1', [
|
||||
'addDeprecationWarning',
|
||||
'getFullName'
|
||||
]);
|
||||
var runnable2 = jasmine.createSpyObj('runnable2', [
|
||||
'addDeprecationWarning',
|
||||
'getFullName'
|
||||
]);
|
||||
|
||||
deprecator.addDeprecationWarning(runnable1, 'the message');
|
||||
deprecator.addDeprecationWarning(runnable1, 'the message');
|
||||
deprecator.addDeprecationWarning(runnable2, 'the message');
|
||||
|
||||
expect(runnable1.addDeprecationWarning).toHaveBeenCalledTimes(1);
|
||||
expect(runnable2.addDeprecationWarning).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('emits the deprecation only once when verboseDeprecations is false', function() {
|
||||
var deprecator = new jasmineUnderTest.Deprecator({});
|
||||
var runnable1 = jasmine.createSpyObj('runnable1', [
|
||||
'addDeprecationWarning',
|
||||
'getFullName'
|
||||
]);
|
||||
var runnable2 = jasmine.createSpyObj('runnable2', [
|
||||
'addDeprecationWarning',
|
||||
'getFullName'
|
||||
]);
|
||||
|
||||
deprecator.verboseDeprecations(false);
|
||||
deprecator.addDeprecationWarning(runnable1, 'the message');
|
||||
deprecator.addDeprecationWarning(runnable1, 'the message');
|
||||
deprecator.addDeprecationWarning(runnable2, 'the message');
|
||||
|
||||
expect(runnable1.addDeprecationWarning).toHaveBeenCalledTimes(1);
|
||||
expect(runnable2.addDeprecationWarning).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('emits the deprecation for each call when verboseDeprecations is true', function() {
|
||||
var deprecator = new jasmineUnderTest.Deprecator({});
|
||||
var runnable1 = jasmine.createSpyObj('runnable1', [
|
||||
'addDeprecationWarning',
|
||||
'getFullName'
|
||||
]);
|
||||
var runnable2 = jasmine.createSpyObj('runnable2', [
|
||||
'addDeprecationWarning',
|
||||
'getFullName'
|
||||
]);
|
||||
|
||||
deprecator.verboseDeprecations(true);
|
||||
deprecator.addDeprecationWarning(runnable1, 'the message');
|
||||
deprecator.addDeprecationWarning(runnable1, 'the message');
|
||||
deprecator.addDeprecationWarning(runnable2, 'the message');
|
||||
|
||||
expect(runnable1.addDeprecationWarning).toHaveBeenCalledTimes(2);
|
||||
expect(runnable2.addDeprecationWarning).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('includes a note about verboseDeprecations', function() {
|
||||
var deprecator = new jasmineUnderTest.Deprecator({});
|
||||
var runnable = jasmine.createSpyObj('runnable', [
|
||||
'addDeprecationWarning',
|
||||
'getFullName'
|
||||
]);
|
||||
|
||||
deprecator.addDeprecationWarning(runnable, 'the message');
|
||||
|
||||
expect(runnable.addDeprecationWarning).toHaveBeenCalledTimes(1);
|
||||
expect(
|
||||
runnable.addDeprecationWarning.calls.argsFor(0)[0].message
|
||||
).toContain(verboseDeprecationsNote());
|
||||
expect(console.error).toHaveBeenCalledTimes(1);
|
||||
expect(console.error.calls.argsFor(0)[0]).toContain(
|
||||
verboseDeprecationsNote()
|
||||
);
|
||||
});
|
||||
|
||||
it('omits the note about verboseDeprecations when verboseDeprecations is true', function() {
|
||||
var deprecator = new jasmineUnderTest.Deprecator({});
|
||||
var runnable = jasmine.createSpyObj('runnable', [
|
||||
'addDeprecationWarning',
|
||||
'getFullName'
|
||||
]);
|
||||
|
||||
deprecator.verboseDeprecations(true);
|
||||
deprecator.addDeprecationWarning(runnable, 'the message');
|
||||
|
||||
expect(runnable.addDeprecationWarning).toHaveBeenCalledTimes(1);
|
||||
expect(
|
||||
runnable.addDeprecationWarning.calls.argsFor(0)[0].message
|
||||
).not.toContain(verboseDeprecationsNote());
|
||||
expect(console.error).toHaveBeenCalledTimes(1);
|
||||
expect(console.error.calls.argsFor(0)[0]).not.toContain(
|
||||
verboseDeprecationsNote()
|
||||
);
|
||||
});
|
||||
|
||||
describe('When the deprecation is an Error', function() {
|
||||
// This form is used by external systems like atom-jasmine3-test-runner
|
||||
// to report their own deprecations through Jasmine. See
|
||||
// <https://github.com/jasmine/jasmine/pull/1498>.
|
||||
it('passes the error through unchanged', function() {
|
||||
var deprecator = new jasmineUnderTest.Deprecator({});
|
||||
var runnable = jasmine.createSpyObj('runnable', [
|
||||
'addDeprecationWarning',
|
||||
'getFullName'
|
||||
]);
|
||||
var exceptionFormatter = new jasmineUnderTest.ExceptionFormatter();
|
||||
var deprecation, originalStack;
|
||||
|
||||
try {
|
||||
throw new Error('the deprecation');
|
||||
} catch (err) {
|
||||
deprecation = err;
|
||||
originalStack = err.stack;
|
||||
}
|
||||
|
||||
deprecator.addDeprecationWarning(runnable, deprecation);
|
||||
|
||||
expect(runnable.addDeprecationWarning).toHaveBeenCalledTimes(1);
|
||||
expect(
|
||||
runnable.addDeprecationWarning.calls.argsFor(0)[0].message
|
||||
).toEqual('the deprecation');
|
||||
expect(runnable.addDeprecationWarning.calls.argsFor(0)[0].stack).toBe(
|
||||
originalStack
|
||||
);
|
||||
expect(console.error).toHaveBeenCalledTimes(1);
|
||||
expect(console.error.calls.argsFor(0)[0].message).toEqual(
|
||||
'the deprecation'
|
||||
);
|
||||
expect(console.error.calls.argsFor(0)[0].stack).toEqual(originalStack);
|
||||
});
|
||||
|
||||
it('reports the deprecation every time, regardless of config.verboseDeprecations', function() {
|
||||
var deprecator = new jasmineUnderTest.Deprecator({});
|
||||
var runnable = jasmine.createSpyObj('runnable', [
|
||||
'addDeprecationWarning',
|
||||
'getFullName'
|
||||
]);
|
||||
var deprecation;
|
||||
|
||||
try {
|
||||
throw new Error('the deprecation');
|
||||
} catch (err) {
|
||||
deprecation = err;
|
||||
}
|
||||
|
||||
deprecator.addDeprecationWarning(runnable, deprecation);
|
||||
deprecator.addDeprecationWarning(runnable, deprecation);
|
||||
|
||||
expect(runnable.addDeprecationWarning).toHaveBeenCalledTimes(2);
|
||||
expect(console.error).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('omits the note about verboseDeprecations', function() {
|
||||
var deprecator = new jasmineUnderTest.Deprecator({});
|
||||
var runnable = jasmine.createSpyObj('runnable', [
|
||||
'addDeprecationWarning',
|
||||
'getFullName'
|
||||
]);
|
||||
var deprecation;
|
||||
|
||||
try {
|
||||
throw new Error('the deprecation');
|
||||
} catch (err) {
|
||||
deprecation = err;
|
||||
}
|
||||
|
||||
deprecator.addDeprecationWarning(runnable, deprecation);
|
||||
|
||||
expect(runnable.addDeprecationWarning).toHaveBeenCalledTimes(1);
|
||||
expect(
|
||||
runnable.addDeprecationWarning.calls.argsFor(0)[0].message
|
||||
).not.toContain(verboseDeprecationsNote());
|
||||
expect(console.error).toHaveBeenCalledTimes(1);
|
||||
expect(console.error.calls.argsFor(0)[0]).not.toContain(
|
||||
verboseDeprecationsNote()
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
function verboseDeprecationsNote() {
|
||||
return (
|
||||
'Note: This message will be shown only once. Set ' +
|
||||
'config.verboseDeprecations to true to see every occurrence.'
|
||||
);
|
||||
}
|
||||
|
||||
function testStackTrace(options) {
|
||||
var deprecator = new jasmineUnderTest.Deprecator({});
|
||||
var runnable = jasmine.createSpyObj('runnable', [
|
||||
'addDeprecationWarning',
|
||||
'getFullName'
|
||||
]);
|
||||
|
||||
deprecator.addDeprecationWarning(runnable, 'the message', options);
|
||||
|
||||
expect(runnable.addDeprecationWarning).toHaveBeenCalledWith({
|
||||
message: jasmine.stringMatching(/^the message/),
|
||||
omitStackTrace: false
|
||||
});
|
||||
expect(console.error).toHaveBeenCalledTimes(1);
|
||||
expect(console.error.calls.argsFor(0)[0]).toContain('the message');
|
||||
expect(console.error.calls.argsFor(0)[0]).toContain('DeprecatorSpec.js');
|
||||
}
|
||||
|
||||
function testNoStackTrace(options) {
|
||||
var deprecator = new jasmineUnderTest.Deprecator({});
|
||||
var runnable = jasmine.createSpyObj('runnable', [
|
||||
'addDeprecationWarning',
|
||||
'getFullName'
|
||||
]);
|
||||
|
||||
deprecator.addDeprecationWarning(runnable, 'the message', options);
|
||||
|
||||
expect(runnable.addDeprecationWarning).toHaveBeenCalledWith({
|
||||
message: jasmine.stringMatching(/^the message/),
|
||||
omitStackTrace: true
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -294,60 +294,6 @@ describe('Env', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#deprecatedOnceWithStack', function() {
|
||||
it('includes a stack trace', function() {
|
||||
spyOn(env, 'deprecated');
|
||||
|
||||
env.deprecatedOnceWithStack('msg');
|
||||
|
||||
expect(env.deprecated).toHaveBeenCalled();
|
||||
var msg = env.deprecated.calls.argsFor(0)[0];
|
||||
expect(msg).toContain('msg');
|
||||
expect(msg).toContain('EnvSpec.js');
|
||||
expect(msg).not.toContain('Error');
|
||||
});
|
||||
|
||||
describe('When verboseDeprecations is true', function() {
|
||||
it('calls #deprecated every time', function() {
|
||||
env.configure({ verboseDeprecations: true });
|
||||
spyOn(env, 'deprecated');
|
||||
|
||||
env.deprecatedOnceWithStack('msg');
|
||||
env.deprecatedOnceWithStack('msg');
|
||||
expect(env.deprecated).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(/msg/)
|
||||
);
|
||||
expect(env.deprecated).toHaveBeenCalledTimes(2);
|
||||
expect(env.deprecated).not.toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(/only once/)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('When verboseDeprecations is false', function() {
|
||||
it('calls #deprecated once per unique message', function() {
|
||||
env.configure({ verboseDeprecations: false });
|
||||
spyOn(env, 'deprecated');
|
||||
|
||||
env.deprecatedOnceWithStack('foo');
|
||||
env.deprecatedOnceWithStack('bar');
|
||||
env.deprecatedOnceWithStack('foo');
|
||||
|
||||
expect(env.deprecated).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(
|
||||
/foo\nNote: This message will be shown only once. Set config.verboseDeprecations to true to see every occurrence/m
|
||||
)
|
||||
);
|
||||
expect(env.deprecated).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(
|
||||
/bar\nNote: This message will be shown only once. Set config.verboseDeprecations to true to see every occurrence/m
|
||||
)
|
||||
);
|
||||
expect(env.deprecated).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when not constructed with suppressLoadErrors: true', function() {
|
||||
it('installs a global error handler on construction', function() {
|
||||
var globalErrors = jasmine.createSpyObj('globalErrors', [
|
||||
|
||||
@@ -533,7 +533,8 @@ describe('QueueRunner', function() {
|
||||
'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.'
|
||||
'to not return a promise.',
|
||||
{ omitStackTrace: true }
|
||||
);
|
||||
});
|
||||
|
||||
@@ -553,7 +554,8 @@ describe('QueueRunner', function() {
|
||||
'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.'
|
||||
'(recommended) or remove the async keyword.',
|
||||
{ omitStackTrace: true }
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -202,7 +202,7 @@ describe('Custom Async Matchers (Integration)', function() {
|
||||
env.execute(null, done);
|
||||
});
|
||||
|
||||
it('logs a deprecation once per matcher if the matcher factory takes two arguments', function(done) {
|
||||
it('logs a distinct deprecation for each matcher if the matcher factory takes two arguments', function(done) {
|
||||
var matcherFactory = function(matchersUtil, customEqualityTesters) {
|
||||
return { compare: function() {} };
|
||||
};
|
||||
@@ -232,7 +232,6 @@ describe('Custom Async Matchers (Integration)', function() {
|
||||
'See <https://jasmine.github.io/tutorials/upgrading_to_4.0> for details.'
|
||||
)
|
||||
);
|
||||
expect(env.deprecated).toHaveBeenCalledTimes(2);
|
||||
done();
|
||||
}
|
||||
|
||||
|
||||
@@ -350,7 +350,7 @@ describe('Custom Matchers (Integration)', function() {
|
||||
env.execute(null, done);
|
||||
});
|
||||
|
||||
it('logs a deprecation once per matcher if the matcher factory takes two arguments', function(done) {
|
||||
it('logs a distinct deprecation per matcher if the matcher factory takes two arguments', function(done) {
|
||||
var matcherFactory = function(matchersUtil, customEqualityTesters) {
|
||||
return { compare: function() {} };
|
||||
};
|
||||
@@ -380,7 +380,6 @@ describe('Custom Matchers (Integration)', function() {
|
||||
'See <https://jasmine.github.io/tutorials/upgrading_to_4.0> for details.'
|
||||
)
|
||||
);
|
||||
expect(env.deprecated).toHaveBeenCalledTimes(2);
|
||||
done();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,322 @@
|
||||
/* eslint no-console: 0 */
|
||||
describe('Deprecation (integration)', function() {
|
||||
var env;
|
||||
|
||||
beforeEach(function() {
|
||||
env = new jasmineUnderTest.Env();
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
env.cleanup_();
|
||||
});
|
||||
|
||||
it('reports a deprecation on the top suite', function(done) {
|
||||
var reporter = jasmine.createSpyObj('reporter', ['jasmineDone']);
|
||||
env.addReporter(reporter);
|
||||
spyOn(console, 'error');
|
||||
|
||||
env.beforeAll(function() {
|
||||
env.deprecated('the message');
|
||||
});
|
||||
env.it('a spec', function() {});
|
||||
|
||||
env.execute(null, function() {
|
||||
expect(reporter.jasmineDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
deprecationWarnings: [
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringMatching(/^the message/)
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(/^DEPRECATION: the message/)
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('reports a deprecation on a descendent suite', function(done) {
|
||||
var reporter = jasmine.createSpyObj('reporter', ['suiteDone']);
|
||||
env.addReporter(reporter);
|
||||
spyOn(console, 'error');
|
||||
|
||||
env.describe('a suite', function() {
|
||||
env.beforeAll(function() {
|
||||
env.deprecated('the message');
|
||||
});
|
||||
env.it('a spec', function() {});
|
||||
});
|
||||
|
||||
env.execute(null, function() {
|
||||
expect(reporter.suiteDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
deprecationWarnings: [
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringMatching(/^the message/)
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(
|
||||
/^DEPRECATION: the message \(in suite: a suite\)/
|
||||
)
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('reports a deprecation on a spec', function(done) {
|
||||
var reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||
env.addReporter(reporter);
|
||||
spyOn(console, 'error');
|
||||
|
||||
env.describe('a suite', function() {
|
||||
env.it('a spec', function() {
|
||||
env.deprecated('the message');
|
||||
});
|
||||
});
|
||||
|
||||
env.execute(null, function() {
|
||||
expect(reporter.specDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
deprecationWarnings: [
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringMatching(/^the message/)
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(
|
||||
/^DEPRECATION: the message \(in spec: a suite a spec\)/
|
||||
)
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('omits the suite or spec context when ignoreRunnable is true', function(done) {
|
||||
var reporter = jasmine.createSpyObj('reporter', ['jasmineDone']);
|
||||
env.addReporter(reporter);
|
||||
spyOn(console, 'error');
|
||||
|
||||
env.it('a spec', function() {
|
||||
env.deprecated('the message', { ignoreRunnable: true });
|
||||
});
|
||||
|
||||
env.execute(null, function() {
|
||||
expect(reporter.jasmineDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
deprecationWarnings: [
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringMatching(/^the message/)
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(/the message/)
|
||||
);
|
||||
expect(console.error).not.toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(/a spec/)
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('includes the stack trace', function(done) {
|
||||
var reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||
env.addReporter(reporter);
|
||||
spyOn(console, 'error');
|
||||
|
||||
env.describe('a suite', function() {
|
||||
env.it('a spec', function() {
|
||||
env.deprecated('the message');
|
||||
});
|
||||
});
|
||||
|
||||
env.execute(null, function() {
|
||||
expect(reporter.specDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
deprecationWarnings: [
|
||||
jasmine.objectContaining({
|
||||
stack: jasmine.stringMatching(/DeprecationSpec.js/)
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(console.error).toHaveBeenCalled();
|
||||
expect(console.error.calls.argsFor(0)[0].replace(/\n/g, 'NL')).toMatch(
|
||||
/^DEPRECATION: the message \(in spec: a suite a spec\)NL.*DeprecationSpec.js/
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('excludes the stack trace when omitStackTrace is true', function(done) {
|
||||
var reporter = jasmine.createSpyObj('reporter', ['specDone']);
|
||||
env.addReporter(reporter);
|
||||
spyOn(console, 'error');
|
||||
|
||||
env.describe('a suite', function() {
|
||||
env.it('a spec', function() {
|
||||
env.deprecated('the message', { omitStackTrace: true });
|
||||
});
|
||||
});
|
||||
|
||||
env.execute(null, function() {
|
||||
expect(reporter.specDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
deprecationWarnings: [
|
||||
jasmine.objectContaining({
|
||||
stack: jasmine.falsy()
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(console.error).toHaveBeenCalled();
|
||||
expect(console.error).not.toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(/DeprecationSpec.js/)
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('emits a given deprecation only once', function(done) {
|
||||
var reporter = jasmine.createSpyObj('reporter', ['specDone', 'suiteDone']);
|
||||
env.addReporter(reporter);
|
||||
spyOn(console, 'error');
|
||||
|
||||
env.describe('a suite', function() {
|
||||
env.beforeAll(function() {
|
||||
env.deprecated('the message');
|
||||
env.deprecated('the message');
|
||||
});
|
||||
|
||||
env.it('a spec', function() {
|
||||
env.deprecated('the message');
|
||||
env.deprecated('a different message');
|
||||
});
|
||||
});
|
||||
|
||||
env.execute(null, function() {
|
||||
expect(reporter.suiteDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
deprecationWarnings: [
|
||||
// only one
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringMatching(/^the message/)
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(reporter.specDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
deprecationWarnings: [
|
||||
// only the other one
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringMatching(/^a different message/)
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(console.error).toHaveBeenCalledTimes(2);
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(
|
||||
/^DEPRECATION: the message \(in suite: a suite\)/
|
||||
)
|
||||
);
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(
|
||||
/^DEPRECATION: a different message \(in spec: a suite a spec\)/
|
||||
)
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('emits a given deprecation each time when config.verboseDeprecations is true', function(done) {
|
||||
var reporter = jasmine.createSpyObj('reporter', ['specDone', 'suiteDone']);
|
||||
env.addReporter(reporter);
|
||||
spyOn(console, 'error');
|
||||
|
||||
env.configure({ verboseDeprecations: true });
|
||||
|
||||
env.describe('a suite', function() {
|
||||
env.beforeAll(function() {
|
||||
env.deprecated('the message');
|
||||
env.deprecated('the message');
|
||||
});
|
||||
|
||||
env.it('a spec', function() {
|
||||
env.deprecated('the message');
|
||||
});
|
||||
});
|
||||
|
||||
env.execute(null, function() {
|
||||
expect(reporter.suiteDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
deprecationWarnings: [
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringMatching(/^the message/)
|
||||
}),
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringMatching(/^the message/)
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(reporter.specDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
deprecationWarnings: [
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringMatching(/^the message/)
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(console.error).toHaveBeenCalledTimes(3);
|
||||
expect(console.error.calls.argsFor(0)[0]).toMatch(
|
||||
/^DEPRECATION: the message \(in suite: a suite\)/
|
||||
);
|
||||
expect(console.error.calls.argsFor(1)[0]).toMatch(
|
||||
/^DEPRECATION: the message \(in suite: a suite\)/
|
||||
);
|
||||
expect(console.error.calls.argsFor(2)[0]).toMatch(
|
||||
/^DEPRECATION: the message \(in spec: a suite a spec\)/
|
||||
);
|
||||
expect(console.error.calls.argsFor(2)[0]).toMatch(
|
||||
/^DEPRECATION: the message \(in spec: a suite a spec\)/
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('handles deprecations that occur before execute() is called', function(done) {
|
||||
var reporter = jasmine.createSpyObj('reporter', ['jasmineDone']);
|
||||
env.addReporter(reporter);
|
||||
spyOn(console, 'error');
|
||||
|
||||
env.deprecated('the message');
|
||||
env.it('a spec', function() {});
|
||||
|
||||
env.execute(null, function() {
|
||||
expect(reporter.jasmineDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
deprecationWarnings: [
|
||||
jasmine.objectContaining({
|
||||
message: jasmine.stringMatching(/^the message/)
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
jasmine.stringMatching(/^DEPRECATION: the message/)
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -2626,70 +2626,6 @@ describe('Env integration', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should report deprecation warnings on the correct specs and suites', function(done) {
|
||||
var reporter = jasmine.createSpyObj('reporter', [
|
||||
'jasmineDone',
|
||||
'suiteDone',
|
||||
'specDone'
|
||||
]);
|
||||
|
||||
// prevent deprecation from being displayed, as well as letting us observe calls
|
||||
spyOn(console, 'error');
|
||||
|
||||
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(null, function() {
|
||||
var result = reporter.jasmineDone.calls.argsFor(0)[0];
|
||||
expect(result.deprecationWarnings).toEqual([
|
||||
jasmine.objectContaining({ message: 'top level deprecation' })
|
||||
]);
|
||||
/* eslint-disable-next-line no-console */
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
'DEPRECATION: top level deprecation'
|
||||
);
|
||||
|
||||
expect(reporter.suiteDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
fullName: 'suite',
|
||||
deprecationWarnings: [
|
||||
jasmine.objectContaining({ message: 'suite level deprecation' })
|
||||
]
|
||||
})
|
||||
);
|
||||
/* eslint-disable-next-line no-console */
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
'DEPRECATION: suite level deprecation (in suite: suite)'
|
||||
);
|
||||
|
||||
expect(reporter.specDone).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
fullName: 'suite spec',
|
||||
deprecationWarnings: [
|
||||
jasmine.objectContaining({ message: 'spec level deprecation' })
|
||||
]
|
||||
})
|
||||
);
|
||||
/* eslint-disable-next-line no-console */
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
'DEPRECATION: spec level deprecation (in spec: suite spec)'
|
||||
);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should report deprecation stack with an error object', function(done) {
|
||||
var exceptionFormatter = new jasmineUnderTest.ExceptionFormatter(),
|
||||
reporter = jasmine.createSpyObj('reporter', [
|
||||
|
||||
Reference in New Issue
Block a user