@tsdi/unit
Version:
unit testing framework, base on AOP, Ioc container
102 lines (100 loc) • 3.88 kB
JavaScript
import { __decorate, __metadata } from "tslib";
import { Aspect, Around, Joinpoint, JoinpointState, AfterThrowing } from '@tsdi/aop';
import { LoggerAspect } from '@tsdi/logs';
import { TestReport } from '../reports/TestReport';
import { SuiteRunner } from '../runner/SuiteRunner';
import { OldTestRunner } from '../runner/OldTestRunner';
let RunAspect = class RunAspect extends LoggerAspect {
getReport() {
if (!this.report) {
this.report = this.injector.resolve(TestReport);
}
return this.report;
}
beforeError(joinPoint) {
this.getReport().track(joinPoint.throwing);
}
beforeEachError(joinPoint) {
this.getReport().track(joinPoint.throwing);
}
afterEachError(joinPoint) {
this.getReport().track(joinPoint.throwing);
}
afterError(joinPoint) {
this.getReport().track(joinPoint.throwing);
}
logBefore(joinPoint) {
let runner = joinPoint.target;
let desc = joinPoint.args[0];
switch (joinPoint.state) {
case JoinpointState.Before:
this.getReport().addSuite(runner.getBootType() || desc.describe, desc);
break;
case JoinpointState.AfterReturning:
case JoinpointState.AfterThrowing:
this.getReport().setSuiteCompleted(runner.getBootType() || desc.describe);
break;
}
}
logTestCase(joinPoint) {
let desc = joinPoint.args[0];
let suiteDesc = joinPoint.args.length > 1 ? joinPoint.args[1] : {};
let runner = joinPoint.target;
switch (joinPoint.state) {
case JoinpointState.Before:
this.getReport().addCase(runner.getBootType() || suiteDesc.describe, desc);
break;
case JoinpointState.AfterReturning:
case JoinpointState.AfterThrowing:
this.getReport().setCaseCompleted(desc);
break;
}
}
static ρAnn() {
return { "name": "RunAspect", "params": { "beforeError": ["joinPoint"], "beforeEachError": ["joinPoint"], "afterEachError": ["joinPoint"], "afterError": ["joinPoint"], "logBefore": ["joinPoint"], "logTestCase": ["joinPoint"] } };
}
};
__decorate([
AfterThrowing('execution(*.runBefore)'),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Joinpoint]),
__metadata("design:returntype", void 0)
], RunAspect.prototype, "beforeError", null);
__decorate([
AfterThrowing('execution(*.runBeforeEach)'),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Joinpoint]),
__metadata("design:returntype", void 0)
], RunAspect.prototype, "beforeEachError", null);
__decorate([
AfterThrowing('execution(*.runAfterEach)'),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Joinpoint]),
__metadata("design:returntype", void 0)
], RunAspect.prototype, "afterEachError", null);
__decorate([
AfterThrowing('execution(*.runAfter)'),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Joinpoint]),
__metadata("design:returntype", void 0)
], RunAspect.prototype, "afterError", null);
__decorate([
Around('execution(*.runSuite)'),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Joinpoint]),
__metadata("design:returntype", void 0)
], RunAspect.prototype, "logBefore", null);
__decorate([
Around('execution(*.runCase)'),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Joinpoint]),
__metadata("design:returntype", void 0)
], RunAspect.prototype, "logTestCase", null);
RunAspect = __decorate([
Aspect({
within: [SuiteRunner, OldTestRunner],
singleton: true
})
], RunAspect);
export { RunAspect };
//# sourceMappingURL=../sourcemaps/aop/RunAspect.js.map