Treat multiple calls to done callbacks as errors
This commit is contained in:
@@ -684,7 +684,7 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
};
|
};
|
||||||
this.expectationResultFactory =
|
this.expectationResultFactory =
|
||||||
attrs.expectationResultFactory || function() {};
|
attrs.expectationResultFactory || function() {};
|
||||||
this.deprecated = attrs.deprecated || function() {};
|
this.onLateError = attrs.onLateError || function() {};
|
||||||
this.queueRunnerFactory = attrs.queueRunnerFactory || function() {};
|
this.queueRunnerFactory = attrs.queueRunnerFactory || function() {};
|
||||||
this.catchingExceptions =
|
this.catchingExceptions =
|
||||||
attrs.catchingExceptions ||
|
attrs.catchingExceptions ||
|
||||||
@@ -783,15 +783,13 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
// Issue a deprecation. Include the context ourselves and pass
|
// Issue a deprecation. Include the context ourselves and pass
|
||||||
// ignoreRunnable: true, since getting here always means that we've already
|
// ignoreRunnable: true, since getting here always means that we've already
|
||||||
// moved on and the current runnable isn't the one that caused the problem.
|
// moved on and the current runnable isn't the one that caused the problem.
|
||||||
self.deprecated(
|
self.onLateError(
|
||||||
"An asynchronous function called its 'done' " +
|
new Error(
|
||||||
'callback more than once. This is a bug in the spec, beforeAll, ' +
|
'An asynchronous spec, beforeEach, or afterEach function called its ' +
|
||||||
'beforeEach, afterAll, or afterEach function in question. This will ' +
|
"'done' callback more than once.\n(in spec: " +
|
||||||
'be treated as an error in a future version.\n' +
|
self.getFullName() +
|
||||||
'(in spec: ' +
|
')'
|
||||||
self.getFullName() +
|
)
|
||||||
')',
|
|
||||||
{ ignoreRunnable: true }
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
onComplete: function() {
|
onComplete: function() {
|
||||||
@@ -1332,6 +1330,18 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function recordLateError(error) {
|
||||||
|
topSuite.result.failedExpectations.push(
|
||||||
|
expectationResultFactory({
|
||||||
|
error,
|
||||||
|
passed: false,
|
||||||
|
matcherName: '',
|
||||||
|
expected: '',
|
||||||
|
actual: ''
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function recordLateExpectation(runable, runableType, result) {
|
function recordLateExpectation(runable, runableType, result) {
|
||||||
var delayedExpectationResult = {};
|
var delayedExpectationResult = {};
|
||||||
Object.keys(result).forEach(function(k) {
|
Object.keys(result).forEach(function(k) {
|
||||||
@@ -1509,12 +1519,12 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var topSuite = new j$.Suite({
|
var topSuite = new j$.Suite({
|
||||||
env: this,
|
|
||||||
id: getNextSuiteId(),
|
id: getNextSuiteId(),
|
||||||
description: 'Jasmine__TopLevel__Suite',
|
description: 'Jasmine__TopLevel__Suite',
|
||||||
expectationFactory: expectationFactory,
|
expectationFactory: expectationFactory,
|
||||||
asyncExpectationFactory: suiteAsyncExpectationFactory,
|
asyncExpectationFactory: suiteAsyncExpectationFactory,
|
||||||
expectationResultFactory: expectationResultFactory
|
expectationResultFactory: expectationResultFactory,
|
||||||
|
onLateError: recordLateError
|
||||||
});
|
});
|
||||||
var deprecator = new j$.Deprecator(topSuite);
|
var deprecator = new j$.Deprecator(topSuite);
|
||||||
defaultResourcesForRunnable(topSuite.id);
|
defaultResourcesForRunnable(topSuite.id);
|
||||||
@@ -1604,7 +1614,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
'specDone'
|
'specDone'
|
||||||
],
|
],
|
||||||
queueRunnerFactory,
|
queueRunnerFactory,
|
||||||
self.deprecated
|
recordLateError
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1898,7 +1908,6 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
|
|
||||||
var suiteFactory = function(description) {
|
var suiteFactory = function(description) {
|
||||||
var suite = new j$.Suite({
|
var suite = new j$.Suite({
|
||||||
env: self,
|
|
||||||
id: getNextSuiteId(),
|
id: getNextSuiteId(),
|
||||||
description: description,
|
description: description,
|
||||||
parentSuite: currentDeclarationSuite,
|
parentSuite: currentDeclarationSuite,
|
||||||
@@ -1906,7 +1915,8 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
expectationFactory: expectationFactory,
|
expectationFactory: expectationFactory,
|
||||||
asyncExpectationFactory: suiteAsyncExpectationFactory,
|
asyncExpectationFactory: suiteAsyncExpectationFactory,
|
||||||
expectationResultFactory: expectationResultFactory,
|
expectationResultFactory: expectationResultFactory,
|
||||||
throwOnExpectationFailure: config.stopSpecOnExpectationFailure
|
throwOnExpectationFailure: config.stopSpecOnExpectationFailure,
|
||||||
|
onLateError: recordLateError
|
||||||
});
|
});
|
||||||
|
|
||||||
return suite;
|
return suite;
|
||||||
@@ -2002,7 +2012,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
beforeAndAfterFns: beforeAndAfterFns(suite),
|
beforeAndAfterFns: beforeAndAfterFns(suite),
|
||||||
expectationFactory: expectationFactory,
|
expectationFactory: expectationFactory,
|
||||||
asyncExpectationFactory: specAsyncExpectationFactory,
|
asyncExpectationFactory: specAsyncExpectationFactory,
|
||||||
deprecated: self.deprecated,
|
onLateError: recordLateError,
|
||||||
resultCallback: specResultCallback,
|
resultCallback: specResultCallback,
|
||||||
getSpecName: function(spec) {
|
getSpecName: function(spec) {
|
||||||
return getSpecName(spec, suite);
|
return getSpecName(spec, suite);
|
||||||
@@ -7723,7 +7733,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
getJasmineRequireObj().ReportDispatcher = function(j$) {
|
getJasmineRequireObj().ReportDispatcher = function(j$) {
|
||||||
function ReportDispatcher(methods, queueRunnerFactory, deprecated) {
|
function ReportDispatcher(methods, queueRunnerFactory, onLateError) {
|
||||||
var dispatchedMethods = methods || [];
|
var dispatchedMethods = methods || [];
|
||||||
|
|
||||||
for (var i = 0; i < dispatchedMethods.length; i++) {
|
for (var i = 0; i < dispatchedMethods.length; i++) {
|
||||||
@@ -7769,11 +7779,11 @@ getJasmineRequireObj().ReportDispatcher = function(j$) {
|
|||||||
onComplete: onComplete,
|
onComplete: onComplete,
|
||||||
isReporter: true,
|
isReporter: true,
|
||||||
onMultipleDone: function() {
|
onMultipleDone: function() {
|
||||||
deprecated(
|
onLateError(
|
||||||
"An asynchronous reporter callback called its 'done' callback " +
|
new Error(
|
||||||
'more than once. This is a bug in the reporter callback in ' +
|
"An asynchronous reporter callback called its 'done' callback " +
|
||||||
'question. This will be treated as an error in a future version.',
|
'more than once.'
|
||||||
{ ignoreRunnable: true }
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -9091,7 +9101,6 @@ getJasmineRequireObj().StackTrace = function(j$) {
|
|||||||
|
|
||||||
getJasmineRequireObj().Suite = function(j$) {
|
getJasmineRequireObj().Suite = function(j$) {
|
||||||
function Suite(attrs) {
|
function Suite(attrs) {
|
||||||
this.env = attrs.env;
|
|
||||||
this.id = attrs.id;
|
this.id = attrs.id;
|
||||||
this.parentSuite = attrs.parentSuite;
|
this.parentSuite = attrs.parentSuite;
|
||||||
this.description = attrs.description;
|
this.description = attrs.description;
|
||||||
@@ -9099,6 +9108,7 @@ getJasmineRequireObj().Suite = function(j$) {
|
|||||||
this.asyncExpectationFactory = attrs.asyncExpectationFactory;
|
this.asyncExpectationFactory = attrs.asyncExpectationFactory;
|
||||||
this.expectationResultFactory = attrs.expectationResultFactory;
|
this.expectationResultFactory = attrs.expectationResultFactory;
|
||||||
this.throwOnExpectationFailure = !!attrs.throwOnExpectationFailure;
|
this.throwOnExpectationFailure = !!attrs.throwOnExpectationFailure;
|
||||||
|
this.onLateError = attrs.onLateError;
|
||||||
|
|
||||||
this.beforeFns = [];
|
this.beforeFns = [];
|
||||||
this.afterFns = [];
|
this.afterFns = [];
|
||||||
@@ -9258,29 +9268,25 @@ getJasmineRequireObj().Suite = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Suite.prototype.onMultipleDone = function() {
|
Suite.prototype.onMultipleDone = function() {
|
||||||
var msg;
|
let msg;
|
||||||
|
|
||||||
// Issue a deprecation. Include the context ourselves and pass
|
// Issue a deprecation. Include the context ourselves and pass
|
||||||
// ignoreRunnable: true, since getting here always means that we've already
|
// ignoreRunnable: true, since getting here always means that we've already
|
||||||
// moved on and the current runnable isn't the one that caused the problem.
|
// moved on and the current runnable isn't the one that caused the problem.
|
||||||
if (this.parentSuite) {
|
if (this.parentSuite) {
|
||||||
msg =
|
msg =
|
||||||
"An asynchronous function called its 'done' callback more than " +
|
"An asynchronous beforeAll or afterAll function called its 'done' " +
|
||||||
'once. This is a bug in the spec, beforeAll, beforeEach, afterAll, ' +
|
'callback more than once.\n' +
|
||||||
'or afterEach function in question. This will be treated as an error ' +
|
|
||||||
'in a future version.\n' +
|
|
||||||
'(in suite: ' +
|
'(in suite: ' +
|
||||||
this.getFullName() +
|
this.getFullName() +
|
||||||
')';
|
')';
|
||||||
} else {
|
} else {
|
||||||
msg =
|
msg =
|
||||||
'A top-level beforeAll or afterAll function called its ' +
|
'A top-level beforeAll or afterAll function called its ' +
|
||||||
"'done' callback more than once. This is a bug in the beforeAll " +
|
"'done' callback more than once.";
|
||||||
'or afterAll function in question. This will be treated as an ' +
|
|
||||||
'error in a future version.';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.env.deprecated(msg, { ignoreRunnable: true });
|
this.onLateError(new Error(msg));
|
||||||
};
|
};
|
||||||
|
|
||||||
Suite.prototype.addExpectationResult = function() {
|
Suite.prototype.addExpectationResult = function() {
|
||||||
|
|||||||
@@ -513,11 +513,11 @@ describe('Spec', function() {
|
|||||||
expect(resultCallback.calls.first().args[0].failedExpectations).toEqual([]);
|
expect(resultCallback.calls.first().args[0].failedExpectations).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('passes an onMultipleDone that logs a deprecation', function() {
|
it('treats multiple done calls as late errors', function() {
|
||||||
var queueRunnerFactory = jasmine.createSpy('queueRunnerFactory'),
|
var queueRunnerFactory = jasmine.createSpy('queueRunnerFactory'),
|
||||||
deprecated = jasmine.createSpy('depredated'),
|
onLateError = jasmine.createSpy('onLateError'),
|
||||||
spec = new jasmineUnderTest.Spec({
|
spec = new jasmineUnderTest.Spec({
|
||||||
deprecated: deprecated,
|
onLateError: onLateError,
|
||||||
queueableFn: { fn: function() {} },
|
queueableFn: { fn: function() {} },
|
||||||
queueRunnerFactory: queueRunnerFactory,
|
queueRunnerFactory: queueRunnerFactory,
|
||||||
getSpecName: function() {
|
getSpecName: function() {
|
||||||
@@ -530,13 +530,11 @@ describe('Spec', function() {
|
|||||||
expect(queueRunnerFactory).toHaveBeenCalled();
|
expect(queueRunnerFactory).toHaveBeenCalled();
|
||||||
queueRunnerFactory.calls.argsFor(0)[0].onMultipleDone();
|
queueRunnerFactory.calls.argsFor(0)[0].onMultipleDone();
|
||||||
|
|
||||||
expect(deprecated).toHaveBeenCalledWith(
|
expect(onLateError).toHaveBeenCalledTimes(1);
|
||||||
"An asynchronous function called its 'done' " +
|
expect(onLateError.calls.argsFor(0)[0]).toBeInstanceOf(Error);
|
||||||
'callback more than once. This is a bug in the spec, beforeAll, ' +
|
expect(onLateError.calls.argsFor(0)[0].message).toEqual(
|
||||||
'beforeEach, afterAll, or afterEach function in question. This will ' +
|
'An asynchronous spec, beforeEach, or afterEach function called its ' +
|
||||||
'be treated as an error in a future version.\n' +
|
"'done' callback more than once.\n(in spec: a spec)"
|
||||||
'(in spec: a spec)',
|
|
||||||
{ ignoreRunnable: true }
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -144,25 +144,27 @@ describe('Suite', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('#onMultipleDone', function() {
|
describe('#onMultipleDone', function() {
|
||||||
it('logs a special deprecation when it is the top suite', function() {
|
it('reports a special error when it is the top suite', function() {
|
||||||
var env = jasmine.createSpyObj('env', ['deprecated']);
|
const onLateError = jasmine.createSpy('onLateError');
|
||||||
var suite = new jasmineUnderTest.Suite({ env: env, parentSuite: null });
|
const suite = new jasmineUnderTest.Suite({
|
||||||
|
onLateError,
|
||||||
|
parentSuite: null
|
||||||
|
});
|
||||||
|
|
||||||
suite.onMultipleDone();
|
suite.onMultipleDone();
|
||||||
|
|
||||||
expect(env.deprecated).toHaveBeenCalledWith(
|
expect(onLateError).toHaveBeenCalledTimes(1);
|
||||||
|
expect(onLateError.calls.argsFor(0)[0]).toBeInstanceOf(Error);
|
||||||
|
expect(onLateError.calls.argsFor(0)[0].message).toEqual(
|
||||||
'A top-level beforeAll or afterAll function called its ' +
|
'A top-level beforeAll or afterAll function called its ' +
|
||||||
"'done' callback more than once. This is a bug in the beforeAll " +
|
"'done' callback more than once."
|
||||||
'or afterAll function in question. This will be treated as an ' +
|
|
||||||
'error in a future version.',
|
|
||||||
{ ignoreRunnable: true }
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('logs a deprecation including the suite name when it is a normal suite', function() {
|
it('reports an error including the suite name when it is a normal suite', function() {
|
||||||
var env = jasmine.createSpyObj('env', ['deprecated']);
|
const onLateError = jasmine.createSpy('onLateError');
|
||||||
var suite = new jasmineUnderTest.Suite({
|
var suite = new jasmineUnderTest.Suite({
|
||||||
env: env,
|
onLateError,
|
||||||
description: 'the suite',
|
description: 'the suite',
|
||||||
parentSuite: {
|
parentSuite: {
|
||||||
description: 'the parent suite',
|
description: 'the parent suite',
|
||||||
@@ -172,13 +174,11 @@ describe('Suite', function() {
|
|||||||
|
|
||||||
suite.onMultipleDone();
|
suite.onMultipleDone();
|
||||||
|
|
||||||
expect(env.deprecated).toHaveBeenCalledWith(
|
expect(onLateError).toHaveBeenCalledTimes(1);
|
||||||
"An asynchronous function called its 'done' callback more than " +
|
expect(onLateError.calls.argsFor(0)[0]).toBeInstanceOf(Error);
|
||||||
'once. This is a bug in the spec, beforeAll, beforeEach, afterAll, ' +
|
expect(onLateError.calls.argsFor(0)[0].message).toEqual(
|
||||||
'or afterEach function in question. This will be treated as an error ' +
|
"An asynchronous beforeAll or afterAll function called its 'done' " +
|
||||||
'in a future version.\n' +
|
'callback more than once.\n(in suite: the parent suite the suite)'
|
||||||
'(in suite: the parent suite the suite)',
|
|
||||||
{ ignoreRunnable: true }
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -509,17 +509,13 @@ describe('Env integration', function() {
|
|||||||
env.execute(null, assertions);
|
env.execute(null, assertions);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('deprecates multiple calls to done in the top suite', function(done) {
|
it('reports multiple calls to done in the top suite as errors', function(done) {
|
||||||
var reporter = jasmine.createSpyObj('fakeReporter', ['jasmineDone']);
|
var reporter = jasmine.createSpyObj('fakeReporter', ['jasmineDone']);
|
||||||
var message =
|
var message =
|
||||||
'A top-level beforeAll or afterAll function called its ' +
|
'A top-level beforeAll or afterAll function called its ' +
|
||||||
"'done' callback more than once. This is a bug in the beforeAll " +
|
"'done' callback more than once.";
|
||||||
'or afterAll function in question. This will be treated as an ' +
|
|
||||||
'error in a future version.';
|
|
||||||
|
|
||||||
spyOn(console, 'error');
|
|
||||||
env.addReporter(reporter);
|
env.addReporter(reporter);
|
||||||
env.configure({ verboseDeprecations: true });
|
|
||||||
env.beforeAll(function(innerDone) {
|
env.beforeAll(function(innerDone) {
|
||||||
innerDone();
|
innerDone();
|
||||||
innerDone();
|
innerDone();
|
||||||
@@ -531,31 +527,27 @@ describe('Env integration', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
env.execute(null, function() {
|
env.execute(null, function() {
|
||||||
var warnings;
|
|
||||||
expect(reporter.jasmineDone).toHaveBeenCalled();
|
expect(reporter.jasmineDone).toHaveBeenCalled();
|
||||||
warnings = reporter.jasmineDone.calls.argsFor(0)[0].deprecationWarnings;
|
const errors = reporter.jasmineDone.calls.argsFor(0)[0]
|
||||||
expect(warnings.length).toEqual(2);
|
.failedExpectations;
|
||||||
expect(warnings[0])
|
expect(errors.length).toEqual(2);
|
||||||
|
expect(errors[0].message)
|
||||||
.withContext('top beforeAll')
|
.withContext('top beforeAll')
|
||||||
.toEqual(jasmine.objectContaining({ message: message }));
|
.toContain(message);
|
||||||
expect(warnings[1])
|
expect(errors[1].message)
|
||||||
.withContext('top afterAll')
|
.withContext('top afterAll')
|
||||||
.toEqual(jasmine.objectContaining({ message: message }));
|
.toContain(message);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('deprecates multiple calls to done in a non-top suite', function(done) {
|
it('reports multiple calls to done in a non-top suite as errors', function(done) {
|
||||||
var reporter = jasmine.createSpyObj('fakeReporter', ['jasmineDone']);
|
var reporter = jasmine.createSpyObj('fakeReporter', ['jasmineDone']);
|
||||||
var message =
|
var message =
|
||||||
"An asynchronous function called its 'done' " +
|
"An asynchronous beforeAll or afterAll function called its 'done' " +
|
||||||
'callback more than once. This is a bug in the spec, beforeAll, ' +
|
'callback more than once.\n(in suite: a suite)';
|
||||||
'beforeEach, afterAll, or afterEach function in question. This will ' +
|
|
||||||
'be treated as an error in a future version.';
|
|
||||||
|
|
||||||
spyOn(console, 'error');
|
|
||||||
env.addReporter(reporter);
|
env.addReporter(reporter);
|
||||||
env.configure({ verboseDeprecations: true });
|
|
||||||
env.describe('a suite', function() {
|
env.describe('a suite', function() {
|
||||||
env.beforeAll(function(innerDone) {
|
env.beforeAll(function(innerDone) {
|
||||||
innerDone();
|
innerDone();
|
||||||
@@ -569,40 +561,27 @@ describe('Env integration', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
env.execute(null, function() {
|
env.execute(null, function() {
|
||||||
var warnings;
|
|
||||||
expect(reporter.jasmineDone).toHaveBeenCalled();
|
expect(reporter.jasmineDone).toHaveBeenCalled();
|
||||||
warnings = reporter.jasmineDone.calls.argsFor(0)[0].deprecationWarnings;
|
const errors = reporter.jasmineDone.calls.argsFor(0)[0]
|
||||||
expect(warnings.length).toEqual(2);
|
.failedExpectations;
|
||||||
expect(warnings[0])
|
expect(errors.length).toEqual(2);
|
||||||
|
expect(errors[0].message)
|
||||||
.withContext('suite beforeAll')
|
.withContext('suite beforeAll')
|
||||||
.toEqual(
|
.toContain(message);
|
||||||
jasmine.objectContaining({
|
expect(errors[1].message)
|
||||||
message: message + '\n(in suite: a suite)'
|
|
||||||
})
|
|
||||||
);
|
|
||||||
expect(warnings[1])
|
|
||||||
.withContext('suite afterAll')
|
.withContext('suite afterAll')
|
||||||
.toEqual(
|
.toContain(message);
|
||||||
jasmine.objectContaining({
|
|
||||||
message: message + '\n(in suite: a suite)'
|
|
||||||
})
|
|
||||||
);
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('deprecates multiple calls to done in a spec', function(done) {
|
it('reports multiple calls to done in a spec as errors', function(done) {
|
||||||
var reporter = jasmine.createSpyObj('fakeReporter', ['jasmineDone']);
|
var reporter = jasmine.createSpyObj('fakeReporter', ['jasmineDone']);
|
||||||
var message =
|
var message =
|
||||||
"An asynchronous function called its 'done' " +
|
'An asynchronous spec, beforeEach, or afterEach function called its ' +
|
||||||
'callback more than once. This is a bug in the spec, beforeAll, ' +
|
"'done' callback more than once.\n(in spec: a suite a spec)";
|
||||||
'beforeEach, afterAll, or afterEach function in question. This will ' +
|
|
||||||
'be treated as an error in a future version.\n' +
|
|
||||||
'(in spec: a suite a spec)';
|
|
||||||
|
|
||||||
spyOn(console, 'error');
|
|
||||||
env.addReporter(reporter);
|
env.addReporter(reporter);
|
||||||
env.configure({ verboseDeprecations: true });
|
|
||||||
env.describe('a suite', function() {
|
env.describe('a suite', function() {
|
||||||
env.beforeEach(function(innerDone) {
|
env.beforeEach(function(innerDone) {
|
||||||
innerDone();
|
innerDone();
|
||||||
@@ -619,30 +598,27 @@ describe('Env integration', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
env.execute(null, function() {
|
env.execute(null, function() {
|
||||||
var warnings;
|
|
||||||
expect(reporter.jasmineDone).toHaveBeenCalled();
|
expect(reporter.jasmineDone).toHaveBeenCalled();
|
||||||
warnings = reporter.jasmineDone.calls.argsFor(0)[0].deprecationWarnings;
|
const errors = reporter.jasmineDone.calls.argsFor(0)[0]
|
||||||
expect(warnings.length).toEqual(3);
|
.failedExpectations;
|
||||||
expect(warnings[0])
|
expect(errors.length).toEqual(3);
|
||||||
.withContext('warning caused by beforeEach')
|
expect(errors[0].message)
|
||||||
.toEqual(jasmine.objectContaining({ message: message }));
|
.withContext('error caused by beforeEach')
|
||||||
expect(warnings[1])
|
.toContain(message);
|
||||||
.withContext('warning caused by it')
|
expect(errors[1].message)
|
||||||
.toEqual(jasmine.objectContaining({ message: message }));
|
.withContext('error caused by it')
|
||||||
expect(warnings[2])
|
.toContain(message);
|
||||||
.withContext('warning caused by afterEach')
|
expect(errors[2].message)
|
||||||
.toEqual(jasmine.objectContaining({ message: message }));
|
.withContext('error caused by afterEach')
|
||||||
|
.toContain(message);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('deprecates multiple calls to done in reporters', function(done) {
|
it('reports multiple calls to done in reporters as errors', function(done) {
|
||||||
var message =
|
var message =
|
||||||
"An asynchronous reporter callback called its 'done' callback more " +
|
"An asynchronous reporter callback called its 'done' callback more " +
|
||||||
'than once. This is a bug in the reporter callback in question. This ' +
|
'than once.';
|
||||||
'will be treated as an error in a future version.\nNote: This message ' +
|
|
||||||
'will be shown only once. Set config.verboseDeprecations to true to ' +
|
|
||||||
'see every occurrence.';
|
|
||||||
var reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone']);
|
var reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone']);
|
||||||
reporter.specDone = function(result, done) {
|
reporter.specDone = function(result, done) {
|
||||||
done();
|
done();
|
||||||
@@ -652,19 +628,17 @@ describe('Env integration', function() {
|
|||||||
|
|
||||||
env.it('a spec', function() {});
|
env.it('a spec', function() {});
|
||||||
|
|
||||||
spyOn(console, 'error');
|
|
||||||
env.execute(null, function() {
|
env.execute(null, function() {
|
||||||
expect(reporter.jasmineDone).toHaveBeenCalled();
|
expect(reporter.jasmineDone).toHaveBeenCalled();
|
||||||
warnings = reporter.jasmineDone.calls.argsFor(0)[0].deprecationWarnings;
|
const errors = reporter.jasmineDone.calls.argsFor(0)[0]
|
||||||
expect(warnings.length).toEqual(1);
|
.failedExpectations;
|
||||||
expect(warnings[0]).toEqual(
|
expect(errors.length).toEqual(1);
|
||||||
jasmine.objectContaining({ message: message })
|
expect(errors[0].message).toContain(message);
|
||||||
);
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not deprecate a call to done that comes after a timeout', function(done) {
|
it('does not report an error for a call to done that comes after a timeout', function(done) {
|
||||||
var reporter = jasmine.createSpyObj('fakeReporter', ['jasmineDone']),
|
var reporter = jasmine.createSpyObj('fakeReporter', ['jasmineDone']),
|
||||||
firstSpecDone;
|
firstSpecDone;
|
||||||
|
|
||||||
@@ -687,7 +661,7 @@ describe('Env integration', function() {
|
|||||||
env.execute(null, function() {
|
env.execute(null, function() {
|
||||||
expect(reporter.jasmineDone).toHaveBeenCalledWith(
|
expect(reporter.jasmineDone).toHaveBeenCalledWith(
|
||||||
jasmine.objectContaining({
|
jasmine.objectContaining({
|
||||||
deprecationWarnings: []
|
failedExpectations: []
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
done();
|
done();
|
||||||
|
|||||||
@@ -338,6 +338,18 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function recordLateError(error) {
|
||||||
|
topSuite.result.failedExpectations.push(
|
||||||
|
expectationResultFactory({
|
||||||
|
error,
|
||||||
|
passed: false,
|
||||||
|
matcherName: '',
|
||||||
|
expected: '',
|
||||||
|
actual: ''
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function recordLateExpectation(runable, runableType, result) {
|
function recordLateExpectation(runable, runableType, result) {
|
||||||
var delayedExpectationResult = {};
|
var delayedExpectationResult = {};
|
||||||
Object.keys(result).forEach(function(k) {
|
Object.keys(result).forEach(function(k) {
|
||||||
@@ -515,12 +527,12 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var topSuite = new j$.Suite({
|
var topSuite = new j$.Suite({
|
||||||
env: this,
|
|
||||||
id: getNextSuiteId(),
|
id: getNextSuiteId(),
|
||||||
description: 'Jasmine__TopLevel__Suite',
|
description: 'Jasmine__TopLevel__Suite',
|
||||||
expectationFactory: expectationFactory,
|
expectationFactory: expectationFactory,
|
||||||
asyncExpectationFactory: suiteAsyncExpectationFactory,
|
asyncExpectationFactory: suiteAsyncExpectationFactory,
|
||||||
expectationResultFactory: expectationResultFactory
|
expectationResultFactory: expectationResultFactory,
|
||||||
|
onLateError: recordLateError
|
||||||
});
|
});
|
||||||
var deprecator = new j$.Deprecator(topSuite);
|
var deprecator = new j$.Deprecator(topSuite);
|
||||||
defaultResourcesForRunnable(topSuite.id);
|
defaultResourcesForRunnable(topSuite.id);
|
||||||
@@ -610,7 +622,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
'specDone'
|
'specDone'
|
||||||
],
|
],
|
||||||
queueRunnerFactory,
|
queueRunnerFactory,
|
||||||
self.deprecated
|
recordLateError
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -904,7 +916,6 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
|
|
||||||
var suiteFactory = function(description) {
|
var suiteFactory = function(description) {
|
||||||
var suite = new j$.Suite({
|
var suite = new j$.Suite({
|
||||||
env: self,
|
|
||||||
id: getNextSuiteId(),
|
id: getNextSuiteId(),
|
||||||
description: description,
|
description: description,
|
||||||
parentSuite: currentDeclarationSuite,
|
parentSuite: currentDeclarationSuite,
|
||||||
@@ -912,7 +923,8 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
expectationFactory: expectationFactory,
|
expectationFactory: expectationFactory,
|
||||||
asyncExpectationFactory: suiteAsyncExpectationFactory,
|
asyncExpectationFactory: suiteAsyncExpectationFactory,
|
||||||
expectationResultFactory: expectationResultFactory,
|
expectationResultFactory: expectationResultFactory,
|
||||||
throwOnExpectationFailure: config.stopSpecOnExpectationFailure
|
throwOnExpectationFailure: config.stopSpecOnExpectationFailure,
|
||||||
|
onLateError: recordLateError
|
||||||
});
|
});
|
||||||
|
|
||||||
return suite;
|
return suite;
|
||||||
@@ -1008,7 +1020,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
beforeAndAfterFns: beforeAndAfterFns(suite),
|
beforeAndAfterFns: beforeAndAfterFns(suite),
|
||||||
expectationFactory: expectationFactory,
|
expectationFactory: expectationFactory,
|
||||||
asyncExpectationFactory: specAsyncExpectationFactory,
|
asyncExpectationFactory: specAsyncExpectationFactory,
|
||||||
deprecated: self.deprecated,
|
onLateError: recordLateError,
|
||||||
resultCallback: specResultCallback,
|
resultCallback: specResultCallback,
|
||||||
getSpecName: function(spec) {
|
getSpecName: function(spec) {
|
||||||
return getSpecName(spec, suite);
|
return getSpecName(spec, suite);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
getJasmineRequireObj().ReportDispatcher = function(j$) {
|
getJasmineRequireObj().ReportDispatcher = function(j$) {
|
||||||
function ReportDispatcher(methods, queueRunnerFactory, deprecated) {
|
function ReportDispatcher(methods, queueRunnerFactory, onLateError) {
|
||||||
var dispatchedMethods = methods || [];
|
var dispatchedMethods = methods || [];
|
||||||
|
|
||||||
for (var i = 0; i < dispatchedMethods.length; i++) {
|
for (var i = 0; i < dispatchedMethods.length; i++) {
|
||||||
@@ -45,11 +45,11 @@ getJasmineRequireObj().ReportDispatcher = function(j$) {
|
|||||||
onComplete: onComplete,
|
onComplete: onComplete,
|
||||||
isReporter: true,
|
isReporter: true,
|
||||||
onMultipleDone: function() {
|
onMultipleDone: function() {
|
||||||
deprecated(
|
onLateError(
|
||||||
"An asynchronous reporter callback called its 'done' callback " +
|
new Error(
|
||||||
'more than once. This is a bug in the reporter callback in ' +
|
"An asynchronous reporter callback called its 'done' callback " +
|
||||||
'question. This will be treated as an error in a future version.',
|
'more than once.'
|
||||||
{ ignoreRunnable: true }
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
};
|
};
|
||||||
this.expectationResultFactory =
|
this.expectationResultFactory =
|
||||||
attrs.expectationResultFactory || function() {};
|
attrs.expectationResultFactory || function() {};
|
||||||
this.deprecated = attrs.deprecated || function() {};
|
this.onLateError = attrs.onLateError || function() {};
|
||||||
this.queueRunnerFactory = attrs.queueRunnerFactory || function() {};
|
this.queueRunnerFactory = attrs.queueRunnerFactory || function() {};
|
||||||
this.catchingExceptions =
|
this.catchingExceptions =
|
||||||
attrs.catchingExceptions ||
|
attrs.catchingExceptions ||
|
||||||
@@ -123,15 +123,13 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
// Issue a deprecation. Include the context ourselves and pass
|
// Issue a deprecation. Include the context ourselves and pass
|
||||||
// ignoreRunnable: true, since getting here always means that we've already
|
// ignoreRunnable: true, since getting here always means that we've already
|
||||||
// moved on and the current runnable isn't the one that caused the problem.
|
// moved on and the current runnable isn't the one that caused the problem.
|
||||||
self.deprecated(
|
self.onLateError(
|
||||||
"An asynchronous function called its 'done' " +
|
new Error(
|
||||||
'callback more than once. This is a bug in the spec, beforeAll, ' +
|
'An asynchronous spec, beforeEach, or afterEach function called its ' +
|
||||||
'beforeEach, afterAll, or afterEach function in question. This will ' +
|
"'done' callback more than once.\n(in spec: " +
|
||||||
'be treated as an error in a future version.\n' +
|
self.getFullName() +
|
||||||
'(in spec: ' +
|
')'
|
||||||
self.getFullName() +
|
)
|
||||||
')',
|
|
||||||
{ ignoreRunnable: true }
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
onComplete: function() {
|
onComplete: function() {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
getJasmineRequireObj().Suite = function(j$) {
|
getJasmineRequireObj().Suite = function(j$) {
|
||||||
function Suite(attrs) {
|
function Suite(attrs) {
|
||||||
this.env = attrs.env;
|
|
||||||
this.id = attrs.id;
|
this.id = attrs.id;
|
||||||
this.parentSuite = attrs.parentSuite;
|
this.parentSuite = attrs.parentSuite;
|
||||||
this.description = attrs.description;
|
this.description = attrs.description;
|
||||||
@@ -8,6 +7,7 @@ getJasmineRequireObj().Suite = function(j$) {
|
|||||||
this.asyncExpectationFactory = attrs.asyncExpectationFactory;
|
this.asyncExpectationFactory = attrs.asyncExpectationFactory;
|
||||||
this.expectationResultFactory = attrs.expectationResultFactory;
|
this.expectationResultFactory = attrs.expectationResultFactory;
|
||||||
this.throwOnExpectationFailure = !!attrs.throwOnExpectationFailure;
|
this.throwOnExpectationFailure = !!attrs.throwOnExpectationFailure;
|
||||||
|
this.onLateError = attrs.onLateError;
|
||||||
|
|
||||||
this.beforeFns = [];
|
this.beforeFns = [];
|
||||||
this.afterFns = [];
|
this.afterFns = [];
|
||||||
@@ -167,29 +167,25 @@ getJasmineRequireObj().Suite = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Suite.prototype.onMultipleDone = function() {
|
Suite.prototype.onMultipleDone = function() {
|
||||||
var msg;
|
let msg;
|
||||||
|
|
||||||
// Issue a deprecation. Include the context ourselves and pass
|
// Issue a deprecation. Include the context ourselves and pass
|
||||||
// ignoreRunnable: true, since getting here always means that we've already
|
// ignoreRunnable: true, since getting here always means that we've already
|
||||||
// moved on and the current runnable isn't the one that caused the problem.
|
// moved on and the current runnable isn't the one that caused the problem.
|
||||||
if (this.parentSuite) {
|
if (this.parentSuite) {
|
||||||
msg =
|
msg =
|
||||||
"An asynchronous function called its 'done' callback more than " +
|
"An asynchronous beforeAll or afterAll function called its 'done' " +
|
||||||
'once. This is a bug in the spec, beforeAll, beforeEach, afterAll, ' +
|
'callback more than once.\n' +
|
||||||
'or afterEach function in question. This will be treated as an error ' +
|
|
||||||
'in a future version.\n' +
|
|
||||||
'(in suite: ' +
|
'(in suite: ' +
|
||||||
this.getFullName() +
|
this.getFullName() +
|
||||||
')';
|
')';
|
||||||
} else {
|
} else {
|
||||||
msg =
|
msg =
|
||||||
'A top-level beforeAll or afterAll function called its ' +
|
'A top-level beforeAll or afterAll function called its ' +
|
||||||
"'done' callback more than once. This is a bug in the beforeAll " +
|
"'done' callback more than once.";
|
||||||
'or afterAll function in question. This will be treated as an ' +
|
|
||||||
'error in a future version.';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.env.deprecated(msg, { ignoreRunnable: true });
|
this.onLateError(new Error(msg));
|
||||||
};
|
};
|
||||||
|
|
||||||
Suite.prototype.addExpectationResult = function() {
|
Suite.prototype.addExpectationResult = function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user