|
|
@ -101,6 +101,7 @@ class Test { |
|
|
|
this.calledEnd = false; |
|
|
|
this.duration = null; |
|
|
|
this.endCallbackFinisher = null; |
|
|
|
this.finishing = false; |
|
|
|
this.pendingAssertions = []; |
|
|
|
this.planCount = null; |
|
|
|
this.startedAt = 0; |
|
|
@ -142,15 +143,27 @@ class Test { |
|
|
|
} |
|
|
|
|
|
|
|
countPassedAssertion() { |
|
|
|
if (this.finishing) { |
|
|
|
this.saveFirstError(new Error('Assertion passed, but test has already ended')); |
|
|
|
} |
|
|
|
|
|
|
|
this.assertCount++; |
|
|
|
} |
|
|
|
|
|
|
|
addPendingAssertion(promise) { |
|
|
|
if (this.finishing) { |
|
|
|
this.saveFirstError(new Error('Assertion passed, but test has already ended')); |
|
|
|
} |
|
|
|
|
|
|
|
this.assertCount++; |
|
|
|
this.pendingAssertions.push(promise); |
|
|
|
} |
|
|
|
|
|
|
|
addFailedAssertion(error) { |
|
|
|
if (this.finishing) { |
|
|
|
this.saveFirstError(new Error('Assertion failed, but test has already ended')); |
|
|
|
} |
|
|
|
|
|
|
|
this.assertCount++; |
|
|
|
this.saveFirstError(error); |
|
|
|
} |
|
|
@ -265,12 +278,13 @@ class Test { |
|
|
|
} |
|
|
|
|
|
|
|
finish() { |
|
|
|
this.finishing = true; |
|
|
|
this.verifyPlan(); |
|
|
|
|
|
|
|
if (this.pendingAssertions.length === 0) { |
|
|
|
return this.finishImmediately(); |
|
|
|
return this.completeFinish(); |
|
|
|
} |
|
|
|
|
|
|
|
this.verifyPlan(); |
|
|
|
|
|
|
|
// Consume errors, ensuring there are no unhandled rejections.
|
|
|
|
const consumedErrors = Promise.all(this.pendingAssertions) |
|
|
|
.catch(err => this.saveFirstError(err)); |
|
|
@ -281,9 +295,7 @@ class Test { |
|
|
|
} |
|
|
|
|
|
|
|
// Finish after potential errors from pending assertions have been consumed.
|
|
|
|
// Note that the plan must be verified again in case a new assertion was
|
|
|
|
// added.
|
|
|
|
return consumedErrors.then(() => this.finishImmediately()); |
|
|
|
return consumedErrors.then(() => this.completeFinish()); |
|
|
|
} |
|
|
|
|
|
|
|
finishPromised() { |
|
|
@ -292,11 +304,6 @@ class Test { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
finishImmediately() { |
|
|
|
this.verifyPlan(); |
|
|
|
return this.completeFinish(); |
|
|
|
} |
|
|
|
|
|
|
|
completeFinish() { |
|
|
|
this.duration = globals.now() - this.startedAt; |
|
|
|
globals.clearTimeout(this.timeoutHandle); |
|
|
|