feat(admin): 添加用户管理相关文件
添加用户管理视图、API和状态管理文件
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
import {
|
||||
BaseReportGenerator,
|
||||
TestReport,
|
||||
ReportGeneratorOptions,
|
||||
} from './base-report-generator';
|
||||
|
||||
export class JUnitReportGenerator extends BaseReportGenerator {
|
||||
constructor(options: ReportGeneratorOptions) {
|
||||
super(options);
|
||||
}
|
||||
|
||||
getExtension(): string {
|
||||
return 'xml';
|
||||
}
|
||||
|
||||
generate(report: TestReport): string {
|
||||
const xml = this.generateJUnitXML(report);
|
||||
return this.writeToFile(xml);
|
||||
}
|
||||
|
||||
private generateJUnitXML(report: TestReport): string {
|
||||
const xmlHeader = '<?xml version="1.0" encoding="UTF-8"?>\n';
|
||||
const testsuites = this.generateTestSuitesXML(report);
|
||||
return xmlHeader + testsuites;
|
||||
}
|
||||
|
||||
private generateTestSuitesXML(report: TestReport): string {
|
||||
const testsuites = report.testSuites
|
||||
.map(suite => this.generateTestSuiteXML(suite))
|
||||
.join('\n');
|
||||
|
||||
return `<testsuites name="${this.escapeXML(report.reportName)}" tests="${report.totalTests}" failures="${report.totalFailed}" skipped="${report.totalSkipped}" time="${report.totalDuration / 1000}" timestamp="${report.timestamp}">
|
||||
${testsuites}
|
||||
</testsuites>`;
|
||||
}
|
||||
|
||||
private generateTestSuiteXML(suite: any): string {
|
||||
const testcases = suite.tests
|
||||
.map((test: any) => this.generateTestCaseXML(test))
|
||||
.join('\n');
|
||||
|
||||
const failedTests = suite.tests.filter((t: any) => t.status === 'failed');
|
||||
|
||||
return ` <testsuite name="${this.escapeXML(suite.suiteName)}" tests="${suite.tests.length}" failures="${suite.failed}" skipped="${suite.skipped}" time="${suite.duration / 1000}" timestamp="${suite.timestamp}">
|
||||
${testcases}
|
||||
</testsuite>`;
|
||||
}
|
||||
|
||||
private generateTestCaseXML(test: any): string {
|
||||
const testcase = ` <testcase name="${this.escapeXML(test.testName)}" classname="${this.escapeXML(test.testId)}" time="${test.duration / 1000}"`;
|
||||
|
||||
if (test.status === 'skipped') {
|
||||
return `${testcase}>
|
||||
<skipped/>
|
||||
</testcase>`;
|
||||
}
|
||||
|
||||
if (test.status === 'failed') {
|
||||
const failureMessage = test.error
|
||||
? this.escapeXML(test.error)
|
||||
: 'Test failed';
|
||||
const failureDetails = test.stackTrace
|
||||
? this.escapeXML(test.stackTrace)
|
||||
: '';
|
||||
|
||||
return `${testcase}>
|
||||
<failure message="${failureMessage}">${failureDetails}</failure>
|
||||
</testcase>`;
|
||||
}
|
||||
|
||||
return `${testcase}/>`;
|
||||
}
|
||||
|
||||
private escapeXML(str: string): string {
|
||||
return str
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user