|
|
@ -26,6 +26,7 @@ function Test(title, fn) { |
|
|
|
this.assertCount = 0; |
|
|
|
this.planCount = null; |
|
|
|
this.duration = null; |
|
|
|
this.assertError = undefined; |
|
|
|
|
|
|
|
// test type, can be: test, hook, eachHook
|
|
|
|
this.type = 'test'; |
|
|
@ -67,20 +68,32 @@ Object.keys(assert).forEach(function (el) { |
|
|
|
if (isPromise(fn)) { |
|
|
|
return Promise.resolve(fn) |
|
|
|
.catch(function (err) { |
|
|
|
self.assertError = err; |
|
|
|
self._setAssertError(err); |
|
|
|
}) |
|
|
|
.finally(function () { |
|
|
|
self._assert(); |
|
|
|
}); |
|
|
|
} |
|
|
|
} catch (err) { |
|
|
|
this.assertError = err; |
|
|
|
this._setAssertError(err); |
|
|
|
} |
|
|
|
|
|
|
|
this._assert(); |
|
|
|
}; |
|
|
|
}); |
|
|
|
|
|
|
|
Test.prototype._setAssertError = function (err) { |
|
|
|
if (this.assertError !== undefined) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (err === undefined) { |
|
|
|
err = 'undefined'; |
|
|
|
} |
|
|
|
|
|
|
|
this.assertError = err; |
|
|
|
}; |
|
|
|
|
|
|
|
// Workaround for power-assert
|
|
|
|
// `t` must be capturable for decorated assert output
|
|
|
|
Test.prototype._capt = assert._capt; |
|
|
@ -118,7 +131,7 @@ Test.prototype.run = function () { |
|
|
|
try { |
|
|
|
ret = this.fn(this); |
|
|
|
} catch (err) { |
|
|
|
this.assertError = err; |
|
|
|
this._setAssertError(err); |
|
|
|
this.exit(); |
|
|
|
} |
|
|
|
|
|
|
@ -132,11 +145,11 @@ Test.prototype.run = function () { |
|
|
|
} |
|
|
|
}) |
|
|
|
.catch(function (err) { |
|
|
|
self.assertError = new assert.AssertionError({ |
|
|
|
self._setAssertError(new assert.AssertionError({ |
|
|
|
actual: err, |
|
|
|
message: 'Promise rejected → ' + err, |
|
|
|
operator: 'promise' |
|
|
|
}); |
|
|
|
})); |
|
|
|
|
|
|
|
self.exit(); |
|
|
|
}); |
|
|
@ -147,11 +160,11 @@ Test.prototype.run = function () { |
|
|
|
|
|
|
|
Test.prototype.end = function (err) { |
|
|
|
if (err) { |
|
|
|
this.assertError = new assert.AssertionError({ |
|
|
|
this._setAssertError(new assert.AssertionError({ |
|
|
|
actual: err, |
|
|
|
message: 'Callback called with an error → ' + err, |
|
|
|
operator: 'callback' |
|
|
|
}); |
|
|
|
})); |
|
|
|
|
|
|
|
this.exit(); |
|
|
|
return; |
|
|
@ -174,13 +187,13 @@ Test.prototype.exit = function () { |
|
|
|
// stop infinite timer
|
|
|
|
clearTimeout(this._timeout); |
|
|
|
|
|
|
|
if (!this.assertError && this.planCount !== null && this.planCount !== this.assertCount) { |
|
|
|
this.assertError = new assert.AssertionError({ |
|
|
|
if (this.assertError === undefined && this.planCount !== null && this.planCount !== this.assertCount) { |
|
|
|
this._setAssertError(new assert.AssertionError({ |
|
|
|
actual: this.assertCount, |
|
|
|
expected: this.planCount, |
|
|
|
message: 'Assertion count does not match planned', |
|
|
|
operator: 'plan' |
|
|
|
}); |
|
|
|
})); |
|
|
|
|
|
|
|
this.assertError.stack = this.planStack; |
|
|
|
} |
|
|
@ -189,7 +202,7 @@ Test.prototype.exit = function () { |
|
|
|
this.ended = true; |
|
|
|
|
|
|
|
setImmediate(function () { |
|
|
|
if (self.assertError) { |
|
|
|
if (self.assertError !== undefined) { |
|
|
|
self.promise.reject(self.assertError); |
|
|
|
return; |
|
|
|
} |
|
|
|