-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextractData.js
69 lines (54 loc) · 1.85 KB
/
extractData.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* eslint-disable prettier/prettier */
import fs from 'fs'
import path from 'path'
export function extractData(resultPath, testType, buildNumber=process.argv[2], buildLink=process.argv[3]) {
const files = fs.readdirSync(resultPath);
const totalTestRun = files.filter((file) => file.endsWith('.json') && file !== 'executor.json').length;
console.log(totalTestRun)
let passedCount = 0;
let failedCount = 0;
let date;
const baseUrl = 'https://hoa-pham82.github.io/reusable-workflow-sample'
let uri;
files
.filter((file) => file.endsWith('.json'))
.map((file) => {
const filePath = path.join(resultPath, file);
const fileContent = fs.readFileSync(filePath, 'utf-8');
const jsonData = JSON.parse(fileContent);
if (jsonData.status === 'passed') {
passedCount++;
} else if (jsonData.status === 'failed') {
failedCount++;
}
// extract report date
date = new Date(jsonData.start);
const format = new Intl.DateTimeFormat('vi-VN', { year: 'numeric', month: 'short', day: 'numeric' }).format(date);
date = format;
});
if (testType === 'Unit Test') {
uri = "allure-history-ut";
}
else if (testType === 'Android Test') {
uri = "allure-history-android";
}
else {
uri = "allure-history-ios";
}
return {
testType: testType,
totalTestCases: totalTestRun,
totalPass: passedCount,
totalFail: failedCount,
reportLink: `${baseUrl}/${uri}/${buildNumber}`,
reportDate: date,
buildUrl: buildLink
};
}
let data = [
extractData('allure-results-ut', 'Unit Test'),
extractData('allure-results-detox', 'Android Test'),
extractData('allure-results-detox', 'iOS Test'),
];
const jsonData = JSON.stringify(data, null, 2);
fs.writeFileSync('report.json', jsonData, 'utf-8');