ortoni-report 4.0.0 → 4.0.2-beta.0
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/dist/chunk-45EJSEX2.mjs +632 -0
- package/dist/chunk-75EAJL2U.mjs +632 -0
- package/dist/chunk-FGIYOFIC.mjs +632 -0
- package/dist/chunk-FHKWBHU6.mjs +633 -0
- package/dist/chunk-GLICR3VS.mjs +637 -0
- package/dist/chunk-HFO6XSKC.mjs +633 -0
- package/dist/chunk-HOZD6YIV.mjs +634 -0
- package/dist/chunk-IJO2YIFE.mjs +637 -0
- package/dist/chunk-INS3E7E6.mjs +638 -0
- package/dist/chunk-JEIWNUQY.mjs +632 -0
- package/dist/chunk-JPLAGYR7.mjs +632 -0
- package/dist/chunk-NM6ULN2O.mjs +632 -0
- package/dist/chunk-OZS6QIJS.mjs +638 -0
- package/dist/chunk-P57227VN.mjs +633 -0
- package/dist/chunk-QMTRYN5N.js +635 -0
- package/dist/chunk-TI33PMMQ.mjs +639 -0
- package/dist/chunk-Z5NBP5TS.mjs +635 -0
- package/dist/cli/cli.cjs +678 -0
- package/dist/cli/cli.d.cts +1 -0
- package/dist/cli/cli.js +580 -11
- package/dist/cli/cli.mjs +62 -5
- package/dist/ortoni-report.cjs +2134 -0
- package/dist/ortoni-report.d.cts +111 -0
- package/dist/ortoni-report.d.mts +1 -0
- package/dist/ortoni-report.d.ts +1 -0
- package/dist/ortoni-report.js +24 -4
- package/dist/ortoni-report.mjs +43 -567
- package/package.json +1 -1
package/dist/cli/cli.js
CHANGED
|
@@ -30,7 +30,7 @@ var import_commander = require("commander");
|
|
|
30
30
|
var import_express = __toESM(require("express"));
|
|
31
31
|
var import_path = __toESM(require("path"));
|
|
32
32
|
var import_child_process = require("child_process");
|
|
33
|
-
function startReportServer(reportFolder, reportFilename, port = 2004,
|
|
33
|
+
function startReportServer(reportFolder, reportFilename, port = 2004, open2) {
|
|
34
34
|
const app = (0, import_express.default)();
|
|
35
35
|
app.use(import_express.default.static(reportFolder));
|
|
36
36
|
app.get("/", (_req, res) => {
|
|
@@ -47,7 +47,7 @@ function startReportServer(reportFolder, reportFilename, port = 2004, open) {
|
|
|
47
47
|
`Server is running at http://localhost:${port}
|
|
48
48
|
Press Ctrl+C to stop.`
|
|
49
49
|
);
|
|
50
|
-
if (
|
|
50
|
+
if (open2 === "always" || open2 === "on-failure") {
|
|
51
51
|
try {
|
|
52
52
|
openBrowser(`http://localhost:${port}`);
|
|
53
53
|
} catch (error) {
|
|
@@ -88,19 +88,588 @@ function openBrowser(url) {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
// src/cli/cli.ts
|
|
91
|
-
var
|
|
92
|
-
var
|
|
91
|
+
var fs2 = __toESM(require("fs"));
|
|
92
|
+
var path3 = __toESM(require("path"));
|
|
93
|
+
|
|
94
|
+
// src/helpers/databaseManager.ts
|
|
95
|
+
var import_sqlite = require("sqlite");
|
|
96
|
+
var import_sqlite3 = __toESM(require("sqlite3"));
|
|
97
|
+
|
|
98
|
+
// src/utils/utils.ts
|
|
99
|
+
function formatDateLocal(dateInput) {
|
|
100
|
+
const date = typeof dateInput === "string" ? new Date(dateInput) : dateInput;
|
|
101
|
+
const options = {
|
|
102
|
+
year: "numeric",
|
|
103
|
+
month: "short",
|
|
104
|
+
day: "2-digit",
|
|
105
|
+
hour: "2-digit",
|
|
106
|
+
minute: "2-digit",
|
|
107
|
+
hour12: true,
|
|
108
|
+
timeZoneName: "short"
|
|
109
|
+
// or "Asia/Kolkata"
|
|
110
|
+
};
|
|
111
|
+
return new Intl.DateTimeFormat(void 0, options).format(date);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// src/helpers/databaseManager.ts
|
|
115
|
+
var DatabaseManager = class {
|
|
116
|
+
constructor() {
|
|
117
|
+
this.db = null;
|
|
118
|
+
}
|
|
119
|
+
async initialize(dbPath) {
|
|
120
|
+
try {
|
|
121
|
+
this.db = await (0, import_sqlite.open)({
|
|
122
|
+
filename: dbPath,
|
|
123
|
+
driver: import_sqlite3.default.Database
|
|
124
|
+
});
|
|
125
|
+
await this.createTables();
|
|
126
|
+
await this.createIndexes();
|
|
127
|
+
} catch (error) {
|
|
128
|
+
console.error("OrtoniReport: Error initializing database:", error);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
async createTables() {
|
|
132
|
+
if (!this.db) {
|
|
133
|
+
console.error("OrtoniReport: Database not initialized");
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
try {
|
|
137
|
+
await this.db.exec(`
|
|
138
|
+
CREATE TABLE IF NOT EXISTS test_runs (
|
|
139
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
140
|
+
run_date TEXT
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
CREATE TABLE IF NOT EXISTS test_results (
|
|
144
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
145
|
+
run_id INTEGER,
|
|
146
|
+
test_id TEXT,
|
|
147
|
+
status TEXT,
|
|
148
|
+
duration INTEGER, -- store duration as raw ms
|
|
149
|
+
error_message TEXT,
|
|
150
|
+
FOREIGN KEY (run_id) REFERENCES test_runs (id)
|
|
151
|
+
);
|
|
152
|
+
`);
|
|
153
|
+
} catch (error) {
|
|
154
|
+
console.error("OrtoniReport: Error creating tables:", error);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
async createIndexes() {
|
|
158
|
+
if (!this.db) {
|
|
159
|
+
console.error("OrtoniReport: Database not initialized");
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
try {
|
|
163
|
+
await this.db.exec(`
|
|
164
|
+
CREATE INDEX IF NOT EXISTS idx_test_id ON test_results (test_id);
|
|
165
|
+
CREATE INDEX IF NOT EXISTS idx_run_id ON test_results (run_id);
|
|
166
|
+
`);
|
|
167
|
+
} catch (error) {
|
|
168
|
+
console.error("OrtoniReport: Error creating indexes:", error);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
async saveTestRun() {
|
|
172
|
+
if (!this.db) {
|
|
173
|
+
console.error("OrtoniReport: Database not initialized");
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
try {
|
|
177
|
+
const runDate = (/* @__PURE__ */ new Date()).toISOString();
|
|
178
|
+
const { lastID } = await this.db.run(
|
|
179
|
+
`
|
|
180
|
+
INSERT INTO test_runs (run_date)
|
|
181
|
+
VALUES (?)
|
|
182
|
+
`,
|
|
183
|
+
[runDate]
|
|
184
|
+
);
|
|
185
|
+
return lastID;
|
|
186
|
+
} catch (error) {
|
|
187
|
+
console.error("OrtoniReport: Error saving test run:", error);
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
async saveTestResults(runId, results) {
|
|
192
|
+
if (!this.db) {
|
|
193
|
+
console.error("OrtoniReport: Database not initialized");
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
try {
|
|
197
|
+
await this.db.exec("BEGIN TRANSACTION;");
|
|
198
|
+
const stmt = await this.db.prepare(`
|
|
199
|
+
INSERT INTO test_results (run_id, test_id, status, duration, error_message)
|
|
200
|
+
VALUES (?, ?, ?, ?, ?)
|
|
201
|
+
`);
|
|
202
|
+
for (const result of results) {
|
|
203
|
+
await stmt.run([
|
|
204
|
+
runId,
|
|
205
|
+
`${result.filePath}:${result.projectName}:${result.title}`,
|
|
206
|
+
result.status,
|
|
207
|
+
result.duration,
|
|
208
|
+
// store raw ms
|
|
209
|
+
result.errors.join("\n")
|
|
210
|
+
]);
|
|
211
|
+
}
|
|
212
|
+
await stmt.finalize();
|
|
213
|
+
await this.db.exec("COMMIT;");
|
|
214
|
+
} catch (error) {
|
|
215
|
+
await this.db.exec("ROLLBACK;");
|
|
216
|
+
console.error("OrtoniReport: Error saving test results:", error);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
async getTestHistory(testId, limit = 10) {
|
|
220
|
+
if (!this.db) {
|
|
221
|
+
console.error("OrtoniReport: Database not initialized");
|
|
222
|
+
return [];
|
|
223
|
+
}
|
|
224
|
+
try {
|
|
225
|
+
const results = await this.db.all(
|
|
226
|
+
`
|
|
227
|
+
SELECT tr.status, tr.duration, tr.error_message, trun.run_date
|
|
228
|
+
FROM test_results tr
|
|
229
|
+
JOIN test_runs trun ON tr.run_id = trun.id
|
|
230
|
+
WHERE tr.test_id = ?
|
|
231
|
+
ORDER BY trun.run_date DESC
|
|
232
|
+
LIMIT ?
|
|
233
|
+
`,
|
|
234
|
+
[testId, limit]
|
|
235
|
+
);
|
|
236
|
+
return results.map((result) => ({
|
|
237
|
+
...result,
|
|
238
|
+
run_date: formatDateLocal(result.run_date)
|
|
239
|
+
}));
|
|
240
|
+
} catch (error) {
|
|
241
|
+
console.error("OrtoniReport: Error getting test history:", error);
|
|
242
|
+
return [];
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
async close() {
|
|
246
|
+
if (this.db) {
|
|
247
|
+
try {
|
|
248
|
+
await this.db.close();
|
|
249
|
+
} catch (error) {
|
|
250
|
+
console.error("OrtoniReport: Error closing database:", error);
|
|
251
|
+
} finally {
|
|
252
|
+
this.db = null;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
async getSummaryData() {
|
|
257
|
+
if (!this.db) {
|
|
258
|
+
console.error("OrtoniReport: Database not initialized");
|
|
259
|
+
return {
|
|
260
|
+
totalRuns: 0,
|
|
261
|
+
totalTests: 0,
|
|
262
|
+
passed: 0,
|
|
263
|
+
failed: 0,
|
|
264
|
+
passRate: 0,
|
|
265
|
+
avgDuration: 0
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
try {
|
|
269
|
+
const summary = await this.db.get(`
|
|
270
|
+
SELECT
|
|
271
|
+
(SELECT COUNT(*) FROM test_runs) as totalRuns,
|
|
272
|
+
(SELECT COUNT(*) FROM test_results) as totalTests,
|
|
273
|
+
(SELECT COUNT(*) FROM test_results WHERE status = 'passed') as passed,
|
|
274
|
+
(SELECT COUNT(*) FROM test_results WHERE status = 'failed') as failed,
|
|
275
|
+
(SELECT AVG(duration) FROM test_results) as avgDuration
|
|
276
|
+
`);
|
|
277
|
+
const passRate = summary.totalTests ? (summary.passed / summary.totalTests * 100).toFixed(2) : 0;
|
|
278
|
+
return {
|
|
279
|
+
totalRuns: summary.totalRuns,
|
|
280
|
+
totalTests: summary.totalTests,
|
|
281
|
+
passed: summary.passed,
|
|
282
|
+
failed: summary.failed,
|
|
283
|
+
passRate: parseFloat(passRate.toString()),
|
|
284
|
+
avgDuration: Math.round(summary.avgDuration || 0)
|
|
285
|
+
// raw ms avg
|
|
286
|
+
};
|
|
287
|
+
} catch (error) {
|
|
288
|
+
console.error("OrtoniReport: Error getting summary data:", error);
|
|
289
|
+
return {
|
|
290
|
+
totalRuns: 0,
|
|
291
|
+
totalTests: 0,
|
|
292
|
+
passed: 0,
|
|
293
|
+
failed: 0,
|
|
294
|
+
passRate: 0,
|
|
295
|
+
avgDuration: 0
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
async getTrends(limit = 100) {
|
|
300
|
+
if (!this.db) {
|
|
301
|
+
console.error("OrtoniReport: Database not initialized");
|
|
302
|
+
return [];
|
|
303
|
+
}
|
|
304
|
+
try {
|
|
305
|
+
const rows = await this.db.all(
|
|
306
|
+
`
|
|
307
|
+
SELECT trun.run_date,
|
|
308
|
+
SUM(CASE WHEN tr.status = 'passed' THEN 1 ELSE 0 END) AS passed,
|
|
309
|
+
SUM(CASE WHEN tr.status = 'failed' THEN 1 ELSE 0 END) AS failed,
|
|
310
|
+
AVG(tr.duration) AS avg_duration
|
|
311
|
+
FROM test_results tr
|
|
312
|
+
JOIN test_runs trun ON tr.run_id = trun.id
|
|
313
|
+
GROUP BY trun.run_date
|
|
314
|
+
ORDER BY trun.run_date DESC
|
|
315
|
+
LIMIT ?
|
|
316
|
+
`,
|
|
317
|
+
[limit]
|
|
318
|
+
);
|
|
319
|
+
return rows.reverse().map((row) => ({
|
|
320
|
+
...row,
|
|
321
|
+
run_date: formatDateLocal(row.run_date),
|
|
322
|
+
avg_duration: Math.round(row.avg_duration || 0)
|
|
323
|
+
// raw ms avg
|
|
324
|
+
}));
|
|
325
|
+
} catch (error) {
|
|
326
|
+
console.error("OrtoniReport: Error getting trends data:", error);
|
|
327
|
+
return [];
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
async getFlakyTests(limit = 10) {
|
|
331
|
+
if (!this.db) {
|
|
332
|
+
console.error("OrtoniReport: Database not initialized");
|
|
333
|
+
return [];
|
|
334
|
+
}
|
|
335
|
+
try {
|
|
336
|
+
return await this.db.all(
|
|
337
|
+
`
|
|
338
|
+
SELECT
|
|
339
|
+
test_id,
|
|
340
|
+
COUNT(*) AS total,
|
|
341
|
+
SUM(CASE WHEN status = 'flaky' THEN 1 ELSE 0 END) AS flaky,
|
|
342
|
+
AVG(duration) AS avg_duration
|
|
343
|
+
FROM test_results
|
|
344
|
+
GROUP BY test_id
|
|
345
|
+
HAVING flaky > 0
|
|
346
|
+
ORDER BY flaky DESC
|
|
347
|
+
LIMIT ?
|
|
348
|
+
`,
|
|
349
|
+
[limit]
|
|
350
|
+
);
|
|
351
|
+
} catch (error) {
|
|
352
|
+
console.error("OrtoniReport: Error getting flaky tests:", error);
|
|
353
|
+
return [];
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
async getSlowTests(limit = 10) {
|
|
357
|
+
if (!this.db) {
|
|
358
|
+
console.error("OrtoniReport: Database not initialized");
|
|
359
|
+
return [];
|
|
360
|
+
}
|
|
361
|
+
try {
|
|
362
|
+
const rows = await this.db.all(
|
|
363
|
+
`
|
|
364
|
+
SELECT
|
|
365
|
+
test_id,
|
|
366
|
+
AVG(duration) AS avg_duration
|
|
367
|
+
FROM test_results
|
|
368
|
+
GROUP BY test_id
|
|
369
|
+
ORDER BY avg_duration DESC
|
|
370
|
+
LIMIT ?
|
|
371
|
+
`,
|
|
372
|
+
[limit]
|
|
373
|
+
);
|
|
374
|
+
return rows.map((row) => ({
|
|
375
|
+
test_id: row.test_id,
|
|
376
|
+
avg_duration: Math.round(row.avg_duration || 0)
|
|
377
|
+
// raw ms avg
|
|
378
|
+
}));
|
|
379
|
+
} catch (error) {
|
|
380
|
+
console.error("OrtoniReport: Error getting slow tests:", error);
|
|
381
|
+
return [];
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
// src/utils/groupProjects.ts
|
|
387
|
+
function groupResults(config, results) {
|
|
388
|
+
if (config.showProject) {
|
|
389
|
+
const groupedResults = results.reduce((acc, result, index) => {
|
|
390
|
+
const testId = `${result.filePath}:${result.projectName}:${result.title}`;
|
|
391
|
+
const key = `${testId}-${result.key}-${result.retryAttemptCount}`;
|
|
392
|
+
const { filePath, suite, projectName } = result;
|
|
393
|
+
acc[filePath] = acc[filePath] || {};
|
|
394
|
+
acc[filePath][suite] = acc[filePath][suite] || {};
|
|
395
|
+
acc[filePath][suite][projectName] = acc[filePath][suite][projectName] || [];
|
|
396
|
+
acc[filePath][suite][projectName].push({ ...result, index, testId, key });
|
|
397
|
+
return acc;
|
|
398
|
+
}, {});
|
|
399
|
+
return groupedResults;
|
|
400
|
+
} else {
|
|
401
|
+
const groupedResults = results.reduce((acc, result, index) => {
|
|
402
|
+
const testId = `${result.filePath}:${result.projectName}:${result.title}`;
|
|
403
|
+
const key = `${testId}-${result.key}-${result.retryAttemptCount}`;
|
|
404
|
+
const { filePath, suite } = result;
|
|
405
|
+
acc[filePath] = acc[filePath] || {};
|
|
406
|
+
acc[filePath][suite] = acc[filePath][suite] || [];
|
|
407
|
+
acc[filePath][suite].push({ ...result, index, testId, key });
|
|
408
|
+
return acc;
|
|
409
|
+
}, {});
|
|
410
|
+
return groupedResults;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// src/helpers/HTMLGenerator.ts
|
|
415
|
+
var HTMLGenerator = class {
|
|
416
|
+
constructor(ortoniConfig, dbManager) {
|
|
417
|
+
this.ortoniConfig = ortoniConfig;
|
|
418
|
+
this.dbManager = dbManager;
|
|
419
|
+
}
|
|
420
|
+
async generateFinalReport(filteredResults, totalDuration, results, projectSet) {
|
|
421
|
+
const data = await this.prepareReportData(
|
|
422
|
+
filteredResults,
|
|
423
|
+
totalDuration,
|
|
424
|
+
results,
|
|
425
|
+
projectSet
|
|
426
|
+
);
|
|
427
|
+
return data;
|
|
428
|
+
}
|
|
429
|
+
async getReportData() {
|
|
430
|
+
return {
|
|
431
|
+
summary: await this.dbManager.getSummaryData(),
|
|
432
|
+
trends: await this.dbManager.getTrends(),
|
|
433
|
+
flakyTests: await this.dbManager.getFlakyTests(),
|
|
434
|
+
slowTests: await this.dbManager.getSlowTests()
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
async prepareReportData(filteredResults, totalDuration, results, projectSet) {
|
|
438
|
+
const totalTests = filteredResults.length;
|
|
439
|
+
const passedTests = results.filter((r) => r.status === "passed").length;
|
|
440
|
+
const flakyTests = results.filter((r) => r.status === "flaky").length;
|
|
441
|
+
const failed = filteredResults.filter(
|
|
442
|
+
(r) => r.status === "failed" || r.status === "timedOut"
|
|
443
|
+
).length;
|
|
444
|
+
const successRate = ((passedTests + flakyTests) / totalTests * 100).toFixed(2);
|
|
445
|
+
const allTags = /* @__PURE__ */ new Set();
|
|
446
|
+
results.forEach(
|
|
447
|
+
(result) => result.testTags.forEach((tag) => allTags.add(tag))
|
|
448
|
+
);
|
|
449
|
+
const projectResults = this.calculateProjectResults(
|
|
450
|
+
filteredResults,
|
|
451
|
+
results,
|
|
452
|
+
projectSet
|
|
453
|
+
);
|
|
454
|
+
const lastRunDate = (/* @__PURE__ */ new Date()).toLocaleString();
|
|
455
|
+
const testHistories = await Promise.all(
|
|
456
|
+
results.map(async (result) => {
|
|
457
|
+
const testId = `${result.filePath}:${result.projectName}:${result.title}`;
|
|
458
|
+
const history = await this.dbManager.getTestHistory(testId);
|
|
459
|
+
return {
|
|
460
|
+
testId,
|
|
461
|
+
history
|
|
462
|
+
};
|
|
463
|
+
})
|
|
464
|
+
);
|
|
465
|
+
return {
|
|
466
|
+
summary: {
|
|
467
|
+
overAllResult: {
|
|
468
|
+
pass: passedTests,
|
|
469
|
+
fail: failed,
|
|
470
|
+
skip: results.filter((r) => r.status === "skipped").length,
|
|
471
|
+
retry: results.filter((r) => r.retryAttemptCount).length,
|
|
472
|
+
flaky: flakyTests,
|
|
473
|
+
total: filteredResults.length
|
|
474
|
+
},
|
|
475
|
+
successRate,
|
|
476
|
+
lastRunDate,
|
|
477
|
+
totalDuration,
|
|
478
|
+
stats: this.extractProjectStats(projectResults)
|
|
479
|
+
},
|
|
480
|
+
testResult: {
|
|
481
|
+
tests: groupResults(this.ortoniConfig, results),
|
|
482
|
+
testHistories,
|
|
483
|
+
allTags: Array.from(allTags),
|
|
484
|
+
set: projectSet
|
|
485
|
+
},
|
|
486
|
+
userConfig: {
|
|
487
|
+
projectName: this.ortoniConfig.projectName,
|
|
488
|
+
authorName: this.ortoniConfig.authorName,
|
|
489
|
+
type: this.ortoniConfig.testType,
|
|
490
|
+
title: this.ortoniConfig.title
|
|
491
|
+
},
|
|
492
|
+
userMeta: {
|
|
493
|
+
meta: this.ortoniConfig.meta
|
|
494
|
+
},
|
|
495
|
+
preferences: {
|
|
496
|
+
logo: this.ortoniConfig.logo || void 0,
|
|
497
|
+
showProject: this.ortoniConfig.showProject || false
|
|
498
|
+
},
|
|
499
|
+
analytics: {
|
|
500
|
+
reportData: await this.getReportData()
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
calculateProjectResults(filteredResults, results, projectSet) {
|
|
505
|
+
return Array.from(projectSet).map((projectName) => {
|
|
506
|
+
const projectTests = filteredResults.filter(
|
|
507
|
+
(r) => r.projectName === projectName
|
|
508
|
+
);
|
|
509
|
+
const allProjectTests = results.filter(
|
|
510
|
+
(r) => r.projectName === projectName
|
|
511
|
+
);
|
|
512
|
+
return {
|
|
513
|
+
projectName,
|
|
514
|
+
passedTests: projectTests.filter((r) => r.status === "passed").length,
|
|
515
|
+
failedTests: projectTests.filter(
|
|
516
|
+
(r) => r.status === "failed" || r.status === "timedOut"
|
|
517
|
+
).length,
|
|
518
|
+
skippedTests: allProjectTests.filter((r) => r.status === "skipped").length,
|
|
519
|
+
retryTests: allProjectTests.filter((r) => r.retryAttemptCount).length,
|
|
520
|
+
flakyTests: allProjectTests.filter((r) => r.status === "flaky").length,
|
|
521
|
+
totalTests: projectTests.length
|
|
522
|
+
};
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
extractProjectStats(projectResults) {
|
|
526
|
+
return {
|
|
527
|
+
projectNames: projectResults.map((result) => result.projectName),
|
|
528
|
+
totalTests: projectResults.map((result) => result.totalTests),
|
|
529
|
+
passedTests: projectResults.map((result) => result.passedTests),
|
|
530
|
+
failedTests: projectResults.map((result) => result.failedTests),
|
|
531
|
+
skippedTests: projectResults.map((result) => result.skippedTests),
|
|
532
|
+
retryTests: projectResults.map((result) => result.retryTests),
|
|
533
|
+
flakyTests: projectResults.map((result) => result.flakyTests)
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
|
|
538
|
+
// src/helpers/fileManager.ts
|
|
539
|
+
var import_fs = __toESM(require("fs"));
|
|
540
|
+
var import_path2 = __toESM(require("path"));
|
|
541
|
+
var FileManager = class {
|
|
542
|
+
constructor(folderPath) {
|
|
543
|
+
this.folderPath = folderPath;
|
|
544
|
+
}
|
|
545
|
+
ensureReportDirectory() {
|
|
546
|
+
const ortoniDataFolder = import_path2.default.join(this.folderPath, "ortoni-data");
|
|
547
|
+
if (!import_fs.default.existsSync(this.folderPath)) {
|
|
548
|
+
import_fs.default.mkdirSync(this.folderPath, { recursive: true });
|
|
549
|
+
} else {
|
|
550
|
+
if (import_fs.default.existsSync(ortoniDataFolder)) {
|
|
551
|
+
import_fs.default.rmSync(ortoniDataFolder, { recursive: true, force: true });
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
writeReportFile(filename, data) {
|
|
556
|
+
const templatePath = import_path2.default.join(__dirname, "..", "index.html");
|
|
557
|
+
console.log("temp path - " + templatePath);
|
|
558
|
+
let html = import_fs.default.readFileSync(templatePath, "utf-8");
|
|
559
|
+
const reportJSON = JSON.stringify({
|
|
560
|
+
data
|
|
561
|
+
});
|
|
562
|
+
html = html.replace("__ORTONI_TEST_REPORTDATA__", reportJSON);
|
|
563
|
+
import_fs.default.writeFileSync(filename, html);
|
|
564
|
+
return filename;
|
|
565
|
+
}
|
|
566
|
+
writeRawFile(filename, data) {
|
|
567
|
+
const outputPath = import_path2.default.join(process.cwd(), this.folderPath, filename);
|
|
568
|
+
import_fs.default.mkdirSync(import_path2.default.dirname(outputPath), { recursive: true });
|
|
569
|
+
const content = typeof data === "string" ? data : JSON.stringify(data, null, 2);
|
|
570
|
+
import_fs.default.writeFileSync(outputPath, content, "utf-8");
|
|
571
|
+
return outputPath;
|
|
572
|
+
}
|
|
573
|
+
copyTraceViewerAssets(skip) {
|
|
574
|
+
if (skip) return;
|
|
575
|
+
const traceViewerFolder = import_path2.default.join(
|
|
576
|
+
require.resolve("playwright-core"),
|
|
577
|
+
"..",
|
|
578
|
+
"lib",
|
|
579
|
+
"vite",
|
|
580
|
+
"traceViewer"
|
|
581
|
+
);
|
|
582
|
+
const traceViewerTargetFolder = import_path2.default.join(this.folderPath, "trace");
|
|
583
|
+
const traceViewerAssetsTargetFolder = import_path2.default.join(
|
|
584
|
+
traceViewerTargetFolder,
|
|
585
|
+
"assets"
|
|
586
|
+
);
|
|
587
|
+
import_fs.default.mkdirSync(traceViewerAssetsTargetFolder, { recursive: true });
|
|
588
|
+
for (const file of import_fs.default.readdirSync(traceViewerFolder)) {
|
|
589
|
+
if (file.endsWith(".map") || file.includes("watch") || file.includes("assets"))
|
|
590
|
+
continue;
|
|
591
|
+
import_fs.default.copyFileSync(
|
|
592
|
+
import_path2.default.join(traceViewerFolder, file),
|
|
593
|
+
import_path2.default.join(traceViewerTargetFolder, file)
|
|
594
|
+
);
|
|
595
|
+
}
|
|
596
|
+
const assetsFolder = import_path2.default.join(traceViewerFolder, "assets");
|
|
597
|
+
for (const file of import_fs.default.readdirSync(assetsFolder)) {
|
|
598
|
+
if (file.endsWith(".map") || file.includes("xtermModule")) continue;
|
|
599
|
+
import_fs.default.copyFileSync(
|
|
600
|
+
import_path2.default.join(assetsFolder, file),
|
|
601
|
+
import_path2.default.join(traceViewerAssetsTargetFolder, file)
|
|
602
|
+
);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
};
|
|
606
|
+
|
|
607
|
+
// src/cli/cli.ts
|
|
93
608
|
import_commander.program.version("2.0.9").description("Ortoni Playwright Test Report CLI");
|
|
94
|
-
import_commander.program.command("show-report").description("Open the generated Ortoni report").option(
|
|
609
|
+
import_commander.program.command("show-report").description("Open the generated Ortoni report").option(
|
|
610
|
+
"-d, --dir <path>",
|
|
611
|
+
"Path to the folder containing the report",
|
|
612
|
+
"ortoni-report"
|
|
613
|
+
).option(
|
|
614
|
+
"-f, --file <filename>",
|
|
615
|
+
"Name of the report file",
|
|
616
|
+
"ortoni-report.html"
|
|
617
|
+
).option("-p, --port <port>", "Port to run the server", "2004").action((options) => {
|
|
95
618
|
const projectRoot = process.cwd();
|
|
96
|
-
const folderPath =
|
|
97
|
-
const filePath =
|
|
619
|
+
const folderPath = path3.resolve(projectRoot, options.dir);
|
|
620
|
+
const filePath = path3.resolve(folderPath, options.file);
|
|
98
621
|
const port = parseInt(options.port) || 2004;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
622
|
+
if (!fs2.existsSync(filePath)) {
|
|
623
|
+
console.error(
|
|
624
|
+
`\u274C Error: The file "${filePath}" does not exist in "${folderPath}".`
|
|
625
|
+
);
|
|
102
626
|
process.exit(1);
|
|
103
627
|
}
|
|
104
|
-
startReportServer(folderPath,
|
|
628
|
+
startReportServer(folderPath, path3.basename(filePath), port, "always");
|
|
629
|
+
});
|
|
630
|
+
import_commander.program.command("merge-shards").description("Merge sharded reports into one final report").option(
|
|
631
|
+
"-d, --dir <path>",
|
|
632
|
+
"Path to the folder containing shard files",
|
|
633
|
+
"ortoni-report"
|
|
634
|
+
).option("-f, --file <filename>", "Output report file", "ortoni-report.html").action(async (options) => {
|
|
635
|
+
const projectRoot = process.cwd();
|
|
636
|
+
const folderPath = path3.resolve(projectRoot, options.dir);
|
|
637
|
+
console.log("folder - " + folderPath);
|
|
638
|
+
console.log(`Merging shard files in folder: ${folderPath}`);
|
|
639
|
+
const filePath = path3.resolve(folderPath, options.file);
|
|
640
|
+
const shardFiles = fs2.readdirSync(folderPath).filter((f) => f.startsWith("ortoni-shard-") && f.endsWith(".json"));
|
|
641
|
+
if (shardFiles.length === 0) {
|
|
642
|
+
console.error("\u274C No shard files found to merge.");
|
|
643
|
+
process.exit(1);
|
|
644
|
+
}
|
|
645
|
+
let allResults = [];
|
|
646
|
+
let projectSet = /* @__PURE__ */ new Set();
|
|
647
|
+
let totalDuration = 0;
|
|
648
|
+
for (const file of shardFiles) {
|
|
649
|
+
const shardData = JSON.parse(
|
|
650
|
+
fs2.readFileSync(path3.join(folderPath, file), "utf-8")
|
|
651
|
+
);
|
|
652
|
+
allResults.push(...shardData.results);
|
|
653
|
+
shardData.projectSet.forEach((p) => projectSet.add(p));
|
|
654
|
+
totalDuration += shardData.duration;
|
|
655
|
+
}
|
|
656
|
+
const dbManager = new DatabaseManager();
|
|
657
|
+
await dbManager.initialize(
|
|
658
|
+
path3.join(folderPath, "ortoni-data-history.sqlite")
|
|
659
|
+
);
|
|
660
|
+
const runId = await dbManager.saveTestRun();
|
|
661
|
+
if (typeof runId === "number") {
|
|
662
|
+
await dbManager.saveTestResults(runId, allResults);
|
|
663
|
+
}
|
|
664
|
+
const htmlGenerator = new HTMLGenerator({}, dbManager);
|
|
665
|
+
const finalReportData = await htmlGenerator.generateFinalReport(
|
|
666
|
+
allResults.filter((r) => r.status !== "skipped"),
|
|
667
|
+
totalDuration,
|
|
668
|
+
allResults,
|
|
669
|
+
projectSet
|
|
670
|
+
);
|
|
671
|
+
const fileManager = new FileManager(folderPath);
|
|
672
|
+
const outputPath = fileManager.writeReportFile(filePath, finalReportData);
|
|
673
|
+
console.log(`\u2705 Final merged report generated at ${outputPath}`);
|
|
105
674
|
});
|
|
106
675
|
import_commander.program.parse(process.argv);
|
package/dist/cli/cli.mjs
CHANGED
|
@@ -1,23 +1,80 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
+
DatabaseManager,
|
|
4
|
+
FileManager,
|
|
5
|
+
HTMLGenerator,
|
|
3
6
|
startReportServer
|
|
4
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-JEIWNUQY.mjs";
|
|
5
8
|
|
|
6
9
|
// src/cli/cli.ts
|
|
7
10
|
import { program } from "commander";
|
|
8
11
|
import * as fs from "fs";
|
|
9
12
|
import * as path from "path";
|
|
10
13
|
program.version("2.0.9").description("Ortoni Playwright Test Report CLI");
|
|
11
|
-
program.command("show-report").description("Open the generated Ortoni report").option(
|
|
14
|
+
program.command("show-report").description("Open the generated Ortoni report").option(
|
|
15
|
+
"-d, --dir <path>",
|
|
16
|
+
"Path to the folder containing the report",
|
|
17
|
+
"ortoni-report"
|
|
18
|
+
).option(
|
|
19
|
+
"-f, --file <filename>",
|
|
20
|
+
"Name of the report file",
|
|
21
|
+
"ortoni-report.html"
|
|
22
|
+
).option("-p, --port <port>", "Port to run the server", "2004").action((options) => {
|
|
12
23
|
const projectRoot = process.cwd();
|
|
13
24
|
const folderPath = path.resolve(projectRoot, options.dir);
|
|
14
25
|
const filePath = path.resolve(folderPath, options.file);
|
|
15
26
|
const port = parseInt(options.port) || 2004;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
27
|
+
if (!fs.existsSync(filePath)) {
|
|
28
|
+
console.error(
|
|
29
|
+
`\u274C Error: The file "${filePath}" does not exist in "${folderPath}".`
|
|
30
|
+
);
|
|
19
31
|
process.exit(1);
|
|
20
32
|
}
|
|
21
33
|
startReportServer(folderPath, path.basename(filePath), port, "always");
|
|
22
34
|
});
|
|
35
|
+
program.command("merge-shards").description("Merge sharded reports into one final report").option(
|
|
36
|
+
"-d, --dir <path>",
|
|
37
|
+
"Path to the folder containing shard files",
|
|
38
|
+
"ortoni-report"
|
|
39
|
+
).option("-f, --file <filename>", "Output report file", "ortoni-report.html").action(async (options) => {
|
|
40
|
+
const projectRoot = process.cwd();
|
|
41
|
+
const folderPath = path.resolve(projectRoot, options.dir);
|
|
42
|
+
console.log("folder - " + folderPath);
|
|
43
|
+
console.log(`Merging shard files in folder: ${folderPath}`);
|
|
44
|
+
const filePath = path.resolve(folderPath, options.file);
|
|
45
|
+
const shardFiles = fs.readdirSync(folderPath).filter((f) => f.startsWith("ortoni-shard-") && f.endsWith(".json"));
|
|
46
|
+
if (shardFiles.length === 0) {
|
|
47
|
+
console.error("\u274C No shard files found to merge.");
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
let allResults = [];
|
|
51
|
+
let projectSet = /* @__PURE__ */ new Set();
|
|
52
|
+
let totalDuration = 0;
|
|
53
|
+
for (const file of shardFiles) {
|
|
54
|
+
const shardData = JSON.parse(
|
|
55
|
+
fs.readFileSync(path.join(folderPath, file), "utf-8")
|
|
56
|
+
);
|
|
57
|
+
allResults.push(...shardData.results);
|
|
58
|
+
shardData.projectSet.forEach((p) => projectSet.add(p));
|
|
59
|
+
totalDuration += shardData.duration;
|
|
60
|
+
}
|
|
61
|
+
const dbManager = new DatabaseManager();
|
|
62
|
+
await dbManager.initialize(
|
|
63
|
+
path.join(folderPath, "ortoni-data-history.sqlite")
|
|
64
|
+
);
|
|
65
|
+
const runId = await dbManager.saveTestRun();
|
|
66
|
+
if (typeof runId === "number") {
|
|
67
|
+
await dbManager.saveTestResults(runId, allResults);
|
|
68
|
+
}
|
|
69
|
+
const htmlGenerator = new HTMLGenerator({}, dbManager);
|
|
70
|
+
const finalReportData = await htmlGenerator.generateFinalReport(
|
|
71
|
+
allResults.filter((r) => r.status !== "skipped"),
|
|
72
|
+
totalDuration,
|
|
73
|
+
allResults,
|
|
74
|
+
projectSet
|
|
75
|
+
);
|
|
76
|
+
const fileManager = new FileManager(folderPath);
|
|
77
|
+
const outputPath = fileManager.writeReportFile(filePath, finalReportData);
|
|
78
|
+
console.log(`\u2705 Final merged report generated at ${outputPath}`);
|
|
79
|
+
});
|
|
23
80
|
program.parse(process.argv);
|