ortoni-report 4.0.2 → 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +5 -0
- package/dist/helpers/HTMLGenerator.d.ts +89 -0
- package/dist/helpers/HTMLGenerator.js +163 -0
- package/dist/helpers/databaseManager.d.ts +35 -0
- package/dist/helpers/databaseManager.js +268 -0
- package/dist/helpers/fileManager.d.ts +8 -0
- package/dist/helpers/fileManager.js +60 -0
- package/dist/helpers/markdownConverter.d.ts +1 -0
- package/dist/helpers/markdownConverter.js +14 -0
- package/dist/helpers/resultProcessor.d.ts +10 -0
- package/dist/helpers/resultProcessor.js +60 -0
- package/dist/helpers/serverManager.d.ts +6 -0
- package/dist/helpers/serverManager.js +15 -0
- package/dist/helpers/templateLoader.d.ts +15 -0
- package/dist/helpers/templateLoader.js +88 -0
- package/dist/index.html +2 -2
- package/dist/mergeData.d.ts +13 -0
- package/dist/mergeData.js +182 -0
- package/dist/ortoni-report.js +1 -1
- package/dist/ortoni-report.mjs +1 -1
- package/dist/types/reporterConfig.d.ts +86 -0
- package/dist/types/reporterConfig.js +1 -0
- package/dist/types/testResults.d.ts +31 -0
- package/dist/types/testResults.js +1 -0
- package/dist/utils/attachFiles.d.ts +4 -0
- package/dist/utils/attachFiles.js +87 -0
- package/dist/utils/expressServer.d.ts +1 -0
- package/dist/utils/expressServer.js +61 -0
- package/dist/utils/groupProjects.d.ts +3 -0
- package/dist/utils/groupProjects.js +30 -0
- package/dist/utils/utils.d.ts +15 -0
- package/dist/utils/utils.js +84 -0
- package/package.json +1 -1
- package/readme.md +1 -1
package/changelog.md
CHANGED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { TestResultData } from "../types/testResults";
|
|
2
|
+
import { OrtoniReportConfig } from "../types/reporterConfig";
|
|
3
|
+
import { DatabaseManager } from "./databaseManager";
|
|
4
|
+
export declare class HTMLGenerator {
|
|
5
|
+
private ortoniConfig;
|
|
6
|
+
private dbManager?;
|
|
7
|
+
constructor(ortoniConfig: OrtoniReportConfig, dbManager?: DatabaseManager);
|
|
8
|
+
generateFinalReport(filteredResults: TestResultData[], totalDuration: number, results: TestResultData[], projectSet: Set<string>): Promise<{
|
|
9
|
+
summary: {
|
|
10
|
+
overAllResult: {
|
|
11
|
+
pass: number;
|
|
12
|
+
fail: number;
|
|
13
|
+
skip: number;
|
|
14
|
+
retry: number;
|
|
15
|
+
flaky: number;
|
|
16
|
+
total: number;
|
|
17
|
+
};
|
|
18
|
+
successRate: string;
|
|
19
|
+
lastRunDate: string;
|
|
20
|
+
totalDuration: number;
|
|
21
|
+
stats: {
|
|
22
|
+
projectNames: string[];
|
|
23
|
+
totalTests: number[];
|
|
24
|
+
passedTests: number[];
|
|
25
|
+
failedTests: number[];
|
|
26
|
+
skippedTests: number[];
|
|
27
|
+
retryTests: number[];
|
|
28
|
+
flakyTests: number[];
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
testResult: {
|
|
32
|
+
tests: any;
|
|
33
|
+
testHistories: {
|
|
34
|
+
testId: string;
|
|
35
|
+
history: any[];
|
|
36
|
+
}[];
|
|
37
|
+
allTags: string[];
|
|
38
|
+
set: Set<string>;
|
|
39
|
+
};
|
|
40
|
+
userConfig: {
|
|
41
|
+
projectName: string;
|
|
42
|
+
authorName: string;
|
|
43
|
+
type: string;
|
|
44
|
+
title: string;
|
|
45
|
+
};
|
|
46
|
+
userMeta: {
|
|
47
|
+
meta: Record<string, string>;
|
|
48
|
+
};
|
|
49
|
+
preferences: {
|
|
50
|
+
logo: string;
|
|
51
|
+
showProject: boolean;
|
|
52
|
+
};
|
|
53
|
+
analytics: {
|
|
54
|
+
reportData: {
|
|
55
|
+
summary: {};
|
|
56
|
+
trends: {};
|
|
57
|
+
flakyTests: any[];
|
|
58
|
+
slowTests: any[];
|
|
59
|
+
note: string;
|
|
60
|
+
} | {
|
|
61
|
+
summary: {};
|
|
62
|
+
trends: {};
|
|
63
|
+
flakyTests: any[];
|
|
64
|
+
slowTests: any[];
|
|
65
|
+
note?: undefined;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
}>;
|
|
69
|
+
/**
|
|
70
|
+
* Return safe analytics/report data.
|
|
71
|
+
* If no dbManager is provided, return empty defaults and a note explaining why.
|
|
72
|
+
*/
|
|
73
|
+
getReportData(): Promise<{
|
|
74
|
+
summary: {};
|
|
75
|
+
trends: {};
|
|
76
|
+
flakyTests: any[];
|
|
77
|
+
slowTests: any[];
|
|
78
|
+
note: string;
|
|
79
|
+
} | {
|
|
80
|
+
summary: {};
|
|
81
|
+
trends: {};
|
|
82
|
+
flakyTests: any[];
|
|
83
|
+
slowTests: any[];
|
|
84
|
+
note?: undefined;
|
|
85
|
+
}>;
|
|
86
|
+
private prepareReportData;
|
|
87
|
+
private calculateProjectResults;
|
|
88
|
+
private extractProjectStats;
|
|
89
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { groupResults } from "../utils/groupProjects";
|
|
2
|
+
export class HTMLGenerator {
|
|
3
|
+
constructor(ortoniConfig, dbManager) {
|
|
4
|
+
this.ortoniConfig = ortoniConfig;
|
|
5
|
+
this.dbManager = dbManager; // may be undefined in CI or when saveHistory=false
|
|
6
|
+
}
|
|
7
|
+
async generateFinalReport(filteredResults, totalDuration, results, projectSet) {
|
|
8
|
+
const data = await this.prepareReportData(filteredResults, totalDuration, results, projectSet);
|
|
9
|
+
return data;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Return safe analytics/report data.
|
|
13
|
+
* If no dbManager is provided, return empty defaults and a note explaining why.
|
|
14
|
+
*/
|
|
15
|
+
async getReportData() {
|
|
16
|
+
if (!this.dbManager) {
|
|
17
|
+
return {
|
|
18
|
+
summary: {},
|
|
19
|
+
trends: {},
|
|
20
|
+
flakyTests: [],
|
|
21
|
+
slowTests: [],
|
|
22
|
+
note: "Test history/trends are unavailable (saveHistory disabled or DB not initialized).",
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const [summary, trends, flakyTests, slowTests] = await Promise.all([
|
|
27
|
+
this.dbManager.getSummaryData
|
|
28
|
+
? this.dbManager.getSummaryData()
|
|
29
|
+
: Promise.resolve({}),
|
|
30
|
+
this.dbManager.getTrends
|
|
31
|
+
? this.dbManager.getTrends()
|
|
32
|
+
: Promise.resolve({}),
|
|
33
|
+
this.dbManager.getFlakyTests
|
|
34
|
+
? this.dbManager.getFlakyTests()
|
|
35
|
+
: Promise.resolve([]),
|
|
36
|
+
this.dbManager.getSlowTests
|
|
37
|
+
? this.dbManager.getSlowTests()
|
|
38
|
+
: Promise.resolve([]),
|
|
39
|
+
]);
|
|
40
|
+
return {
|
|
41
|
+
summary: summary ?? {},
|
|
42
|
+
trends: trends ?? {},
|
|
43
|
+
flakyTests: flakyTests ?? [],
|
|
44
|
+
slowTests: slowTests ?? [],
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
console.warn("HTMLGenerator: failed to read analytics from DB, continuing without history.", err);
|
|
49
|
+
return {
|
|
50
|
+
summary: {},
|
|
51
|
+
trends: {},
|
|
52
|
+
flakyTests: [],
|
|
53
|
+
slowTests: [],
|
|
54
|
+
note: "Test history/trends could not be loaded due to a DB error.",
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async prepareReportData(filteredResults, totalDuration, results, projectSet) {
|
|
59
|
+
const totalTests = filteredResults.length;
|
|
60
|
+
const passedTests = results.filter((r) => r.status === "passed").length;
|
|
61
|
+
const flakyTests = results.filter((r) => r.status === "flaky").length;
|
|
62
|
+
const failed = filteredResults.filter((r) => r.status === "failed" || r.status === "timedOut").length;
|
|
63
|
+
const successRate = totalTests === 0
|
|
64
|
+
? "0.00"
|
|
65
|
+
: (((passedTests + flakyTests) / totalTests) * 100).toFixed(2);
|
|
66
|
+
const allTags = new Set();
|
|
67
|
+
results.forEach((result) => (result.testTags || []).forEach((tag) => allTags.add(tag)));
|
|
68
|
+
const projectResults = this.calculateProjectResults(filteredResults, results, projectSet);
|
|
69
|
+
const lastRunDate = new Date().toLocaleString();
|
|
70
|
+
// Fetch per-test histories only if DB manager exists; otherwise return empty history arrays.
|
|
71
|
+
const testHistories = await Promise.all(results.map(async (result) => {
|
|
72
|
+
const testId = `${result.filePath}:${result.projectName}:${result.title}`;
|
|
73
|
+
if (!this.dbManager || !this.dbManager.getTestHistory) {
|
|
74
|
+
return {
|
|
75
|
+
testId,
|
|
76
|
+
history: [],
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
const history = await this.dbManager.getTestHistory(testId);
|
|
81
|
+
return {
|
|
82
|
+
testId,
|
|
83
|
+
history: history ?? [],
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
// If a single test history fails, return empty history for that test and continue
|
|
88
|
+
console.warn(`HTMLGenerator: failed to read history for ${testId}`, err);
|
|
89
|
+
return {
|
|
90
|
+
testId,
|
|
91
|
+
history: [],
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}));
|
|
95
|
+
// Fetch analytics/reportData using the safe getter (this will handle missing DB)
|
|
96
|
+
const reportData = await this.getReportData();
|
|
97
|
+
return {
|
|
98
|
+
summary: {
|
|
99
|
+
overAllResult: {
|
|
100
|
+
pass: passedTests,
|
|
101
|
+
fail: failed,
|
|
102
|
+
skip: results.filter((r) => r.status === "skipped").length,
|
|
103
|
+
retry: results.filter((r) => r.retryAttemptCount).length,
|
|
104
|
+
flaky: flakyTests,
|
|
105
|
+
total: filteredResults.length,
|
|
106
|
+
},
|
|
107
|
+
successRate,
|
|
108
|
+
lastRunDate,
|
|
109
|
+
totalDuration,
|
|
110
|
+
stats: this.extractProjectStats(projectResults),
|
|
111
|
+
},
|
|
112
|
+
testResult: {
|
|
113
|
+
tests: groupResults(this.ortoniConfig, results),
|
|
114
|
+
testHistories,
|
|
115
|
+
allTags: Array.from(allTags),
|
|
116
|
+
set: projectSet,
|
|
117
|
+
},
|
|
118
|
+
userConfig: {
|
|
119
|
+
projectName: this.ortoniConfig.projectName,
|
|
120
|
+
authorName: this.ortoniConfig.authorName,
|
|
121
|
+
type: this.ortoniConfig.testType,
|
|
122
|
+
title: this.ortoniConfig.title,
|
|
123
|
+
},
|
|
124
|
+
userMeta: {
|
|
125
|
+
meta: this.ortoniConfig.meta,
|
|
126
|
+
},
|
|
127
|
+
preferences: {
|
|
128
|
+
logo: this.ortoniConfig.logo || undefined,
|
|
129
|
+
showProject: this.ortoniConfig.showProject || false,
|
|
130
|
+
},
|
|
131
|
+
analytics: {
|
|
132
|
+
reportData: reportData,
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
calculateProjectResults(filteredResults, results, projectSet) {
|
|
137
|
+
return Array.from(projectSet).map((projectName) => {
|
|
138
|
+
const projectTests = filteredResults.filter((r) => r.projectName === projectName);
|
|
139
|
+
const allProjectTests = results.filter((r) => r.projectName === projectName);
|
|
140
|
+
return {
|
|
141
|
+
projectName,
|
|
142
|
+
passedTests: projectTests.filter((r) => r.status === "passed").length,
|
|
143
|
+
failedTests: projectTests.filter((r) => r.status === "failed" || r.status === "timedOut").length,
|
|
144
|
+
skippedTests: allProjectTests.filter((r) => r.status === "skipped")
|
|
145
|
+
.length,
|
|
146
|
+
retryTests: allProjectTests.filter((r) => r.retryAttemptCount).length,
|
|
147
|
+
flakyTests: allProjectTests.filter((r) => r.status === "flaky").length,
|
|
148
|
+
totalTests: projectTests.length,
|
|
149
|
+
};
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
extractProjectStats(projectResults) {
|
|
153
|
+
return {
|
|
154
|
+
projectNames: projectResults.map((result) => result.projectName),
|
|
155
|
+
totalTests: projectResults.map((result) => result.totalTests),
|
|
156
|
+
passedTests: projectResults.map((result) => result.passedTests),
|
|
157
|
+
failedTests: projectResults.map((result) => result.failedTests),
|
|
158
|
+
skippedTests: projectResults.map((result) => result.skippedTests),
|
|
159
|
+
retryTests: projectResults.map((result) => result.retryTests),
|
|
160
|
+
flakyTests: projectResults.map((result) => result.flakyTests),
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { TestResultData } from "../types/testResults";
|
|
2
|
+
export declare class DatabaseManager {
|
|
3
|
+
private db;
|
|
4
|
+
initialize(dbPath: string): Promise<void>;
|
|
5
|
+
private createTables;
|
|
6
|
+
private createIndexes;
|
|
7
|
+
saveTestRun(): Promise<number | null>;
|
|
8
|
+
saveTestResults(runId: number, results: TestResultData[]): Promise<void>;
|
|
9
|
+
getTestHistory(testId: string, limit?: number): Promise<any[]>;
|
|
10
|
+
close(): Promise<void>;
|
|
11
|
+
getSummaryData(): Promise<{
|
|
12
|
+
totalRuns: number;
|
|
13
|
+
totalTests: number;
|
|
14
|
+
passed: number;
|
|
15
|
+
failed: number;
|
|
16
|
+
passRate: number;
|
|
17
|
+
avgDuration: number;
|
|
18
|
+
}>;
|
|
19
|
+
getTrends(limit?: number): Promise<{
|
|
20
|
+
run_date: string;
|
|
21
|
+
passed: number;
|
|
22
|
+
failed: number;
|
|
23
|
+
avg_duration: number;
|
|
24
|
+
}[]>;
|
|
25
|
+
getFlakyTests(limit?: number): Promise<{
|
|
26
|
+
test_id: string;
|
|
27
|
+
total: number;
|
|
28
|
+
flaky: number;
|
|
29
|
+
avg_duration: number;
|
|
30
|
+
}[]>;
|
|
31
|
+
getSlowTests(limit?: number): Promise<{
|
|
32
|
+
test_id: string;
|
|
33
|
+
avg_duration: number;
|
|
34
|
+
}[]>;
|
|
35
|
+
}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { open } from "sqlite";
|
|
2
|
+
import sqlite3 from "sqlite3";
|
|
3
|
+
import { formatDateLocal } from "../utils/utils";
|
|
4
|
+
export class DatabaseManager {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.db = null;
|
|
7
|
+
}
|
|
8
|
+
async initialize(dbPath) {
|
|
9
|
+
try {
|
|
10
|
+
this.db = await open({
|
|
11
|
+
filename: dbPath,
|
|
12
|
+
driver: sqlite3.Database,
|
|
13
|
+
});
|
|
14
|
+
await this.createTables();
|
|
15
|
+
await this.createIndexes();
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
console.error("OrtoniReport: Error initializing database:", error);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async createTables() {
|
|
22
|
+
if (!this.db) {
|
|
23
|
+
console.error("OrtoniReport: Database not initialized");
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
await this.db.exec(`
|
|
28
|
+
CREATE TABLE IF NOT EXISTS test_runs (
|
|
29
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
30
|
+
run_date TEXT
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
CREATE TABLE IF NOT EXISTS test_results (
|
|
34
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
35
|
+
run_id INTEGER,
|
|
36
|
+
test_id TEXT,
|
|
37
|
+
status TEXT,
|
|
38
|
+
duration INTEGER, -- store duration as raw ms
|
|
39
|
+
error_message TEXT,
|
|
40
|
+
FOREIGN KEY (run_id) REFERENCES test_runs (id)
|
|
41
|
+
);
|
|
42
|
+
`);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
console.error("OrtoniReport: Error creating tables:", error);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async createIndexes() {
|
|
49
|
+
if (!this.db) {
|
|
50
|
+
console.error("OrtoniReport: Database not initialized");
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
await this.db.exec(`
|
|
55
|
+
CREATE INDEX IF NOT EXISTS idx_test_id ON test_results (test_id);
|
|
56
|
+
CREATE INDEX IF NOT EXISTS idx_run_id ON test_results (run_id);
|
|
57
|
+
`);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
console.error("OrtoniReport: Error creating indexes:", error);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async saveTestRun() {
|
|
64
|
+
if (!this.db) {
|
|
65
|
+
console.error("OrtoniReport: Database not initialized");
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
const runDate = new Date().toISOString();
|
|
70
|
+
const { lastID } = await this.db.run(`
|
|
71
|
+
INSERT INTO test_runs (run_date)
|
|
72
|
+
VALUES (?)
|
|
73
|
+
`, [runDate]);
|
|
74
|
+
return lastID;
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
console.error("OrtoniReport: Error saving test run:", error);
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async saveTestResults(runId, results) {
|
|
82
|
+
if (!this.db) {
|
|
83
|
+
console.error("OrtoniReport: Database not initialized");
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
await this.db.exec("BEGIN TRANSACTION;");
|
|
88
|
+
const stmt = await this.db.prepare(`
|
|
89
|
+
INSERT INTO test_results (run_id, test_id, status, duration, error_message)
|
|
90
|
+
VALUES (?, ?, ?, ?, ?)
|
|
91
|
+
`);
|
|
92
|
+
for (const result of results) {
|
|
93
|
+
await stmt.run([
|
|
94
|
+
runId,
|
|
95
|
+
`${result.filePath}:${result.projectName}:${result.title}`,
|
|
96
|
+
result.status,
|
|
97
|
+
result.duration,
|
|
98
|
+
result.errors.join("\n"),
|
|
99
|
+
]);
|
|
100
|
+
}
|
|
101
|
+
await stmt.finalize();
|
|
102
|
+
await this.db.exec("COMMIT;");
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
await this.db.exec("ROLLBACK;");
|
|
106
|
+
console.error("OrtoniReport: Error saving test results:", error);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async getTestHistory(testId, limit = 10) {
|
|
110
|
+
if (!this.db) {
|
|
111
|
+
console.error("OrtoniReport: Database not initialized");
|
|
112
|
+
return [];
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
const results = await this.db.all(`
|
|
116
|
+
SELECT tr.status, tr.duration, tr.error_message, trun.run_date
|
|
117
|
+
FROM test_results tr
|
|
118
|
+
JOIN test_runs trun ON tr.run_id = trun.id
|
|
119
|
+
WHERE tr.test_id = ?
|
|
120
|
+
ORDER BY trun.run_date DESC
|
|
121
|
+
LIMIT ?
|
|
122
|
+
`, [testId, limit]);
|
|
123
|
+
return results.map((result) => ({
|
|
124
|
+
...result,
|
|
125
|
+
run_date: formatDateLocal(result.run_date),
|
|
126
|
+
}));
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
console.error("OrtoniReport: Error getting test history:", error);
|
|
130
|
+
return [];
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
async close() {
|
|
134
|
+
if (this.db) {
|
|
135
|
+
try {
|
|
136
|
+
await this.db.close();
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
console.error("OrtoniReport: Error closing database:", error);
|
|
140
|
+
}
|
|
141
|
+
finally {
|
|
142
|
+
this.db = null;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
async getSummaryData() {
|
|
147
|
+
if (!this.db) {
|
|
148
|
+
console.error("OrtoniReport: Database not initialized");
|
|
149
|
+
return {
|
|
150
|
+
totalRuns: 0,
|
|
151
|
+
totalTests: 0,
|
|
152
|
+
passed: 0,
|
|
153
|
+
failed: 0,
|
|
154
|
+
passRate: 0,
|
|
155
|
+
avgDuration: 0,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
try {
|
|
159
|
+
const summary = await this.db.get(`
|
|
160
|
+
SELECT
|
|
161
|
+
(SELECT COUNT(*) FROM test_runs) as totalRuns,
|
|
162
|
+
(SELECT COUNT(*) FROM test_results) as totalTests,
|
|
163
|
+
(SELECT COUNT(*) FROM test_results WHERE status = 'passed') as passed,
|
|
164
|
+
(SELECT COUNT(*) FROM test_results WHERE status = 'failed') as failed,
|
|
165
|
+
(SELECT AVG(duration) FROM test_results) as avgDuration
|
|
166
|
+
`);
|
|
167
|
+
const passRate = summary.totalTests
|
|
168
|
+
? ((summary.passed / summary.totalTests) * 100).toFixed(2)
|
|
169
|
+
: 0;
|
|
170
|
+
return {
|
|
171
|
+
totalRuns: summary.totalRuns,
|
|
172
|
+
totalTests: summary.totalTests,
|
|
173
|
+
passed: summary.passed,
|
|
174
|
+
failed: summary.failed,
|
|
175
|
+
passRate: parseFloat(passRate.toString()),
|
|
176
|
+
avgDuration: Math.round(summary.avgDuration || 0), // raw ms avg
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
console.error("OrtoniReport: Error getting summary data:", error);
|
|
181
|
+
return {
|
|
182
|
+
totalRuns: 0,
|
|
183
|
+
totalTests: 0,
|
|
184
|
+
passed: 0,
|
|
185
|
+
failed: 0,
|
|
186
|
+
passRate: 0,
|
|
187
|
+
avgDuration: 0,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
async getTrends(limit = 100) {
|
|
192
|
+
if (!this.db) {
|
|
193
|
+
console.error("OrtoniReport: Database not initialized");
|
|
194
|
+
return [];
|
|
195
|
+
}
|
|
196
|
+
try {
|
|
197
|
+
const rows = await this.db.all(`
|
|
198
|
+
SELECT trun.run_date,
|
|
199
|
+
SUM(CASE WHEN tr.status = 'passed' THEN 1 ELSE 0 END) AS passed,
|
|
200
|
+
SUM(CASE WHEN tr.status = 'failed' THEN 1 ELSE 0 END) AS failed,
|
|
201
|
+
AVG(tr.duration) AS avg_duration
|
|
202
|
+
FROM test_results tr
|
|
203
|
+
JOIN test_runs trun ON tr.run_id = trun.id
|
|
204
|
+
GROUP BY trun.run_date
|
|
205
|
+
ORDER BY trun.run_date DESC
|
|
206
|
+
LIMIT ?
|
|
207
|
+
`, [limit]);
|
|
208
|
+
return rows.reverse().map((row) => ({
|
|
209
|
+
...row,
|
|
210
|
+
run_date: formatDateLocal(row.run_date),
|
|
211
|
+
avg_duration: Math.round(row.avg_duration || 0), // raw ms avg
|
|
212
|
+
}));
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
console.error("OrtoniReport: Error getting trends data:", error);
|
|
216
|
+
return [];
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
async getFlakyTests(limit = 10) {
|
|
220
|
+
if (!this.db) {
|
|
221
|
+
console.error("OrtoniReport: Database not initialized");
|
|
222
|
+
return [];
|
|
223
|
+
}
|
|
224
|
+
try {
|
|
225
|
+
return await this.db.all(`
|
|
226
|
+
SELECT
|
|
227
|
+
test_id,
|
|
228
|
+
COUNT(*) AS total,
|
|
229
|
+
SUM(CASE WHEN status = 'flaky' THEN 1 ELSE 0 END) AS flaky,
|
|
230
|
+
AVG(duration) AS avg_duration
|
|
231
|
+
FROM test_results
|
|
232
|
+
GROUP BY test_id
|
|
233
|
+
HAVING flaky > 0
|
|
234
|
+
ORDER BY flaky DESC
|
|
235
|
+
LIMIT ?
|
|
236
|
+
`, [limit]);
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
console.error("OrtoniReport: Error getting flaky tests:", error);
|
|
240
|
+
return [];
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
async getSlowTests(limit = 10) {
|
|
244
|
+
if (!this.db) {
|
|
245
|
+
console.error("OrtoniReport: Database not initialized");
|
|
246
|
+
return [];
|
|
247
|
+
}
|
|
248
|
+
try {
|
|
249
|
+
const rows = await this.db.all(`
|
|
250
|
+
SELECT
|
|
251
|
+
test_id,
|
|
252
|
+
AVG(duration) AS avg_duration
|
|
253
|
+
FROM test_results
|
|
254
|
+
GROUP BY test_id
|
|
255
|
+
ORDER BY avg_duration DESC
|
|
256
|
+
LIMIT ?
|
|
257
|
+
`, [limit]);
|
|
258
|
+
return rows.map((row) => ({
|
|
259
|
+
test_id: row.test_id,
|
|
260
|
+
avg_duration: Math.round(row.avg_duration || 0), // raw ms avg
|
|
261
|
+
}));
|
|
262
|
+
}
|
|
263
|
+
catch (error) {
|
|
264
|
+
console.error("OrtoniReport: Error getting slow tests:", error);
|
|
265
|
+
return [];
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare class FileManager {
|
|
2
|
+
private folderPath;
|
|
3
|
+
constructor(folderPath: string);
|
|
4
|
+
ensureReportDirectory(): void;
|
|
5
|
+
writeReportFile(filename: string, data: unknown): Promise<string>;
|
|
6
|
+
writeRawFile(filename: string, data: unknown): string;
|
|
7
|
+
copyTraceViewerAssets(skip: boolean): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { readBundledTemplate } from "./templateLoader";
|
|
4
|
+
export class FileManager {
|
|
5
|
+
constructor(folderPath) {
|
|
6
|
+
this.folderPath = folderPath;
|
|
7
|
+
}
|
|
8
|
+
ensureReportDirectory() {
|
|
9
|
+
const ortoniDataFolder = path.join(this.folderPath, "ortoni-data");
|
|
10
|
+
if (!fs.existsSync(this.folderPath)) {
|
|
11
|
+
fs.mkdirSync(this.folderPath, { recursive: true });
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
if (fs.existsSync(ortoniDataFolder)) {
|
|
15
|
+
fs.rmSync(ortoniDataFolder, { recursive: true, force: true });
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
async writeReportFile(filename, data) {
|
|
20
|
+
let html = await readBundledTemplate();
|
|
21
|
+
// let html = fs.readFileSync(templatePath, "utf-8");
|
|
22
|
+
const reportJSON = JSON.stringify({
|
|
23
|
+
data,
|
|
24
|
+
});
|
|
25
|
+
html = html.replace("__ORTONI_TEST_REPORTDATA__", reportJSON);
|
|
26
|
+
const outputPath = path.join(process.cwd(), this.folderPath, filename);
|
|
27
|
+
fs.writeFileSync(outputPath, html);
|
|
28
|
+
return outputPath;
|
|
29
|
+
}
|
|
30
|
+
writeRawFile(filename, data) {
|
|
31
|
+
const outputPath = path.join(process.cwd(), this.folderPath, filename);
|
|
32
|
+
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
|
|
33
|
+
const content = typeof data === "string" ? data : JSON.stringify(data, null, 2);
|
|
34
|
+
fs.writeFileSync(outputPath, content, "utf-8");
|
|
35
|
+
return outputPath;
|
|
36
|
+
}
|
|
37
|
+
copyTraceViewerAssets(skip) {
|
|
38
|
+
if (skip)
|
|
39
|
+
return;
|
|
40
|
+
const traceViewerFolder = path.join(require.resolve("playwright-core"), "..", "lib", "vite", "traceViewer");
|
|
41
|
+
const traceViewerTargetFolder = path.join(this.folderPath, "trace");
|
|
42
|
+
const traceViewerAssetsTargetFolder = path.join(traceViewerTargetFolder, "assets");
|
|
43
|
+
fs.mkdirSync(traceViewerAssetsTargetFolder, { recursive: true });
|
|
44
|
+
// Copy main trace viewer files
|
|
45
|
+
for (const file of fs.readdirSync(traceViewerFolder)) {
|
|
46
|
+
if (file.endsWith(".map") ||
|
|
47
|
+
file.includes("watch") ||
|
|
48
|
+
file.includes("assets"))
|
|
49
|
+
continue;
|
|
50
|
+
fs.copyFileSync(path.join(traceViewerFolder, file), path.join(traceViewerTargetFolder, file));
|
|
51
|
+
}
|
|
52
|
+
// Copy assets
|
|
53
|
+
const assetsFolder = path.join(traceViewerFolder, "assets");
|
|
54
|
+
for (const file of fs.readdirSync(assetsFolder)) {
|
|
55
|
+
if (file.endsWith(".map") || file.includes("xtermModule"))
|
|
56
|
+
continue;
|
|
57
|
+
fs.copyFileSync(path.join(assetsFolder, file), path.join(traceViewerAssetsTargetFolder, file));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function convertMarkdownToHtml(markdownPath: string, htmlOutputPath: string): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { marked } from "marked";
|
|
3
|
+
export function convertMarkdownToHtml(markdownPath, htmlOutputPath) {
|
|
4
|
+
const hasMarkdown = fs.existsSync(markdownPath);
|
|
5
|
+
const markdownContent = hasMarkdown
|
|
6
|
+
? fs.readFileSync(markdownPath, "utf-8")
|
|
7
|
+
: "";
|
|
8
|
+
const markdownHtml = hasMarkdown ? marked(markdownContent) : "";
|
|
9
|
+
const drawerHtml = `${markdownHtml || ""}`;
|
|
10
|
+
fs.writeFileSync(htmlOutputPath, drawerHtml.trim(), "utf-8");
|
|
11
|
+
if (hasMarkdown) {
|
|
12
|
+
fs.unlinkSync(markdownPath);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TestCase, TestResult } from "@playwright/test/reporter";
|
|
2
|
+
import { TestResultData } from "../types/testResults";
|
|
3
|
+
import { OrtoniReportConfig } from "../types/reporterConfig";
|
|
4
|
+
export declare class TestResultProcessor {
|
|
5
|
+
private ansiToHtml;
|
|
6
|
+
private projectRoot;
|
|
7
|
+
constructor(projectRoot: string);
|
|
8
|
+
processTestResult(test: TestCase, result: TestResult, projectSet: Set<string>, ortoniConfig: OrtoniReportConfig): TestResultData;
|
|
9
|
+
private processSteps;
|
|
10
|
+
}
|