-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathformat.js
50 lines (42 loc) · 1.62 KB
/
format.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* Formats a size in bytes to a human-readable string (KB or MB)
* @param {number} sizeInBytes - Size in bytes to format
* @returns {string} Formatted size string with units
*/
function formatSize(sizeInBytes) {
const MB_THRESHOLD = 10 * 1024;
if (sizeInBytes >= MB_THRESHOLD) {
return `${(sizeInBytes / (1024 * 1024)).toFixed(2)} MB`;
}
return `${(sizeInBytes / 1024).toFixed(2)} KB`;
}
/**
* Generates a summary of test changes
* @param {Object} comparison - Test comparison results
* @returns {string} Formatted test changes summary
*/
function generateTestChangesSummary(comparison) {
if (!comparison.new.length && !comparison.deleted.length && !comparison.skipped.length) {
return '😟 No changes in tests. 😕';
}
const summaryParts = [];
const { new: newTests, skipped, deleted } = comparison;
if (newTests.length) {
summaryParts.push(`#### ✨ New Tests (${newTests.length})\n${newTests.map((test, i) => `${i + 1}. ${test}`).join('\n')}\n`);
}
if (skipped.length) {
summaryParts.push(`#### ⏭️ Skipped Tests (${skipped.length})\n${skipped.map((test, i) => `${i + 1}. ${test}`).join('\n')}\n`);
}
if (deleted.length) {
summaryParts.push(`#### 🗑️ Deleted Tests (${deleted.length})\n${deleted.map((test, i) => `${i + 1}. ${test}`).join('\n')}`);
}
return `
<details>
<summary>Test Changes Summary ${newTests.length ? `✨${newTests.length} ` : ''}${skipped.length ? `⏭️${skipped.length} ` : ''}${deleted.length ? `🗑️${deleted.length}` : ''}</summary>
${summaryParts.join('\n')}
</details>`;
}
module.exports = {
formatSize,
generateTestChangesSummary
};