@tsdi/unit
Version:
unit testing framework, base on AOP, Ioc container
110 lines (108 loc) • 4.88 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RunAspect = void 0;
var tslib_1 = require("tslib");
var aop_1 = require("@tsdi/aop");
var logs_1 = require("@tsdi/logs");
var TestReport_1 = require("../reports/TestReport");
var SuiteRunner_1 = require("../runner/SuiteRunner");
var OldTestRunner_1 = require("../runner/OldTestRunner");
var RunAspect = /** @class */ (function (_super) {
tslib_1.__extends(RunAspect, _super);
function RunAspect() {
return _super !== null && _super.apply(this, arguments) || this;
}
RunAspect.prototype.getReport = function () {
if (!this.report) {
this.report = this.injector.resolve(TestReport_1.TestReport);
}
return this.report;
};
RunAspect.prototype.beforeError = function (joinPoint) {
this.getReport().track(joinPoint.throwing);
};
RunAspect.prototype.beforeEachError = function (joinPoint) {
this.getReport().track(joinPoint.throwing);
};
RunAspect.prototype.afterEachError = function (joinPoint) {
this.getReport().track(joinPoint.throwing);
};
RunAspect.prototype.afterError = function (joinPoint) {
this.getReport().track(joinPoint.throwing);
};
RunAspect.prototype.logBefore = function (joinPoint) {
var runner = joinPoint.target;
var desc = joinPoint.args[0];
switch (joinPoint.state) {
case aop_1.JoinpointState.Before:
this.getReport().addSuite(runner.getBootType() || desc.describe, desc);
break;
case aop_1.JoinpointState.AfterReturning:
case aop_1.JoinpointState.AfterThrowing:
this.getReport().setSuiteCompleted(runner.getBootType() || desc.describe);
break;
}
};
RunAspect.prototype.logTestCase = function (joinPoint) {
var desc = joinPoint.args[0];
var suiteDesc = joinPoint.args.length > 1 ? joinPoint.args[1] : {};
var runner = joinPoint.target;
switch (joinPoint.state) {
case aop_1.JoinpointState.Before:
this.getReport().addCase(runner.getBootType() || suiteDesc.describe, desc);
break;
case aop_1.JoinpointState.AfterReturning:
case aop_1.JoinpointState.AfterThrowing:
this.getReport().setCaseCompleted(desc);
break;
}
};
RunAspect.ρAnn = function () {
return { "name": "RunAspect", "params": { "beforeError": ["joinPoint"], "beforeEachError": ["joinPoint"], "afterEachError": ["joinPoint"], "afterError": ["joinPoint"], "logBefore": ["joinPoint"], "logTestCase": ["joinPoint"] } };
};
tslib_1.__decorate([
aop_1.AfterThrowing('execution(*.runBefore)'),
tslib_1.__metadata("design:type", Function),
tslib_1.__metadata("design:paramtypes", [aop_1.Joinpoint]),
tslib_1.__metadata("design:returntype", void 0)
], RunAspect.prototype, "beforeError", null);
tslib_1.__decorate([
aop_1.AfterThrowing('execution(*.runBeforeEach)'),
tslib_1.__metadata("design:type", Function),
tslib_1.__metadata("design:paramtypes", [aop_1.Joinpoint]),
tslib_1.__metadata("design:returntype", void 0)
], RunAspect.prototype, "beforeEachError", null);
tslib_1.__decorate([
aop_1.AfterThrowing('execution(*.runAfterEach)'),
tslib_1.__metadata("design:type", Function),
tslib_1.__metadata("design:paramtypes", [aop_1.Joinpoint]),
tslib_1.__metadata("design:returntype", void 0)
], RunAspect.prototype, "afterEachError", null);
tslib_1.__decorate([
aop_1.AfterThrowing('execution(*.runAfter)'),
tslib_1.__metadata("design:type", Function),
tslib_1.__metadata("design:paramtypes", [aop_1.Joinpoint]),
tslib_1.__metadata("design:returntype", void 0)
], RunAspect.prototype, "afterError", null);
tslib_1.__decorate([
aop_1.Around('execution(*.runSuite)'),
tslib_1.__metadata("design:type", Function),
tslib_1.__metadata("design:paramtypes", [aop_1.Joinpoint]),
tslib_1.__metadata("design:returntype", void 0)
], RunAspect.prototype, "logBefore", null);
tslib_1.__decorate([
aop_1.Around('execution(*.runCase)'),
tslib_1.__metadata("design:type", Function),
tslib_1.__metadata("design:paramtypes", [aop_1.Joinpoint]),
tslib_1.__metadata("design:returntype", void 0)
], RunAspect.prototype, "logTestCase", null);
RunAspect = tslib_1.__decorate([
aop_1.Aspect({
within: [SuiteRunner_1.SuiteRunner, OldTestRunner_1.OldTestRunner],
singleton: true
})
], RunAspect);
return RunAspect;
}(logs_1.LoggerAspect));
exports.RunAspect = RunAspect;
//# sourceMappingURL=../sourcemaps/aop/RunAspect.js.map