Treat multiple calls to done callbacks as errors

This commit is contained in:
Steve Gravrock
2021-09-10 18:07:35 -07:00
parent 15f7013f85
commit d092a59bd1
8 changed files with 144 additions and 160 deletions

View File

@@ -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) {
var delayedExpectationResult = {};
Object.keys(result).forEach(function(k) {
@@ -515,12 +527,12 @@ getJasmineRequireObj().Env = function(j$) {
};
var topSuite = new j$.Suite({
env: this,
id: getNextSuiteId(),
description: 'Jasmine__TopLevel__Suite',
expectationFactory: expectationFactory,
asyncExpectationFactory: suiteAsyncExpectationFactory,
expectationResultFactory: expectationResultFactory
expectationResultFactory: expectationResultFactory,
onLateError: recordLateError
});
var deprecator = new j$.Deprecator(topSuite);
defaultResourcesForRunnable(topSuite.id);
@@ -610,7 +622,7 @@ getJasmineRequireObj().Env = function(j$) {
'specDone'
],
queueRunnerFactory,
self.deprecated
recordLateError
);
/**
@@ -904,7 +916,6 @@ getJasmineRequireObj().Env = function(j$) {
var suiteFactory = function(description) {
var suite = new j$.Suite({
env: self,
id: getNextSuiteId(),
description: description,
parentSuite: currentDeclarationSuite,
@@ -912,7 +923,8 @@ getJasmineRequireObj().Env = function(j$) {
expectationFactory: expectationFactory,
asyncExpectationFactory: suiteAsyncExpectationFactory,
expectationResultFactory: expectationResultFactory,
throwOnExpectationFailure: config.stopSpecOnExpectationFailure
throwOnExpectationFailure: config.stopSpecOnExpectationFailure,
onLateError: recordLateError
});
return suite;
@@ -1008,7 +1020,7 @@ getJasmineRequireObj().Env = function(j$) {
beforeAndAfterFns: beforeAndAfterFns(suite),
expectationFactory: expectationFactory,
asyncExpectationFactory: specAsyncExpectationFactory,
deprecated: self.deprecated,
onLateError: recordLateError,
resultCallback: specResultCallback,
getSpecName: function(spec) {
return getSpecName(spec, suite);

View File

@@ -1,5 +1,5 @@
getJasmineRequireObj().ReportDispatcher = function(j$) {
function ReportDispatcher(methods, queueRunnerFactory, deprecated) {
function ReportDispatcher(methods, queueRunnerFactory, onLateError) {
var dispatchedMethods = methods || [];
for (var i = 0; i < dispatchedMethods.length; i++) {
@@ -45,11 +45,11 @@ getJasmineRequireObj().ReportDispatcher = function(j$) {
onComplete: onComplete,
isReporter: true,
onMultipleDone: function() {
deprecated(
"An asynchronous reporter callback called its 'done' callback " +
'more than once. This is a bug in the reporter callback in ' +
'question. This will be treated as an error in a future version.',
{ ignoreRunnable: true }
onLateError(
new Error(
"An asynchronous reporter callback called its 'done' callback " +
'more than once.'
)
);
}
});

View File

@@ -24,7 +24,7 @@ getJasmineRequireObj().Spec = function(j$) {
};
this.expectationResultFactory =
attrs.expectationResultFactory || function() {};
this.deprecated = attrs.deprecated || function() {};
this.onLateError = attrs.onLateError || function() {};
this.queueRunnerFactory = attrs.queueRunnerFactory || function() {};
this.catchingExceptions =
attrs.catchingExceptions ||
@@ -123,15 +123,13 @@ getJasmineRequireObj().Spec = function(j$) {
// Issue a deprecation. Include the context ourselves and pass
// 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.
self.deprecated(
"An asynchronous function called its 'done' " +
'callback more than once. This is a bug in the spec, beforeAll, ' +
'beforeEach, afterAll, or afterEach function in question. This will ' +
'be treated as an error in a future version.\n' +
'(in spec: ' +
self.getFullName() +
')',
{ ignoreRunnable: true }
self.onLateError(
new Error(
'An asynchronous spec, beforeEach, or afterEach function called its ' +
"'done' callback more than once.\n(in spec: " +
self.getFullName() +
')'
)
);
},
onComplete: function() {

View File

@@ -1,6 +1,5 @@
getJasmineRequireObj().Suite = function(j$) {
function Suite(attrs) {
this.env = attrs.env;
this.id = attrs.id;
this.parentSuite = attrs.parentSuite;
this.description = attrs.description;
@@ -8,6 +7,7 @@ getJasmineRequireObj().Suite = function(j$) {
this.asyncExpectationFactory = attrs.asyncExpectationFactory;
this.expectationResultFactory = attrs.expectationResultFactory;
this.throwOnExpectationFailure = !!attrs.throwOnExpectationFailure;
this.onLateError = attrs.onLateError;
this.beforeFns = [];
this.afterFns = [];
@@ -167,29 +167,25 @@ getJasmineRequireObj().Suite = function(j$) {
};
Suite.prototype.onMultipleDone = function() {
var msg;
let msg;
// Issue a deprecation. Include the context ourselves and pass
// 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.
if (this.parentSuite) {
msg =
"An asynchronous function called its 'done' callback more than " +
'once. This is a bug in the spec, beforeAll, beforeEach, afterAll, ' +
'or afterEach function in question. This will be treated as an error ' +
'in a future version.\n' +
"An asynchronous beforeAll or afterAll function called its 'done' " +
'callback more than once.\n' +
'(in suite: ' +
this.getFullName() +
')';
} else {
msg =
'A top-level beforeAll or afterAll function called its ' +
"'done' callback more than once. This is a bug in the beforeAll " +
'or afterAll function in question. This will be treated as an ' +
'error in a future version.';
"'done' callback more than once.";
}
this.env.deprecated(msg, { ignoreRunnable: true });
this.onLateError(new Error(msg));
};
Suite.prototype.addExpectationResult = function() {