Skip to content

Commit

Permalink
test report
Browse files Browse the repository at this point in the history
  • Loading branch information
hoa-pham82 committed Oct 29, 2023
1 parent d6b04a9 commit e5c7d57
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 10 deletions.
32 changes: 22 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,27 @@ jobs:
ref: gh-pages
path: gh-pages

- name: Allure Report action from marketplace - Detox
- name: Generate Allure report for Android
if: success() || failure()
uses: simple-elf/allure-report-action@master
with:
allure_results: allure-results-detox
allure_report: ${{ github.run_number }}-detox
allure_history: allure-history-detox
allure_report: ${{ github.run_number }}-android
allure_history: allure-history-android
keep_reports: 5
gh_pages: gh-pages/allure-history-detox
gh_pages: gh-pages/allure-history-android

- name: Allure Report action from marketplace - UT
- name: Generate Allure report for iOS
if: success() || failure()
uses: simple-elf/allure-report-action@master
with:
allure_results: allure-results-detox
allure_report: ${{ github.run_number }}-ios
allure_history: allure-history-ios
keep_reports: 5
gh_pages: gh-pages/allure-history-ios

- name: Generate Allure report for UT
if: success() || failure()
uses: simple-elf/allure-report-action@master
with:
Expand All @@ -44,18 +54,20 @@ jobs:
keep_reports: 5
gh_pages: gh-pages/allure-history-ut

- name: Display structure of downloaded files
- name: Prepare data for summary page
if: success() || failure()
run: |
pwd && echo '------>' && ls
echo '-----> you see the list of report'
node extractData.js ${{github.run_number}}
- name: Prepare github paging
if: success() || failure()
run: |
mkdir public
cp -r allure-history-ut public
cp -r allure-history-detox public
cp -r allure-history-ut allure-history-android allure-history-ios public
cp report.json index.html script.js public
- name: Deploy report to Github Pages
if: success() || failure()
uses: peaceiris/actions-gh-pages@v2
env:
PERSONAL_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
57 changes: 57 additions & 0 deletions extractData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* eslint-disable prettier/prettier */
import fs from 'fs'
import path from 'path'

export function extractData(resultPath, testType, buildNumber=process.argv[2]) {
const files = fs.readdirSync(resultPath);
const totalTestRun = files.filter((file) => file.endsWith('.json')).length;

let passedCount = 0;
let failedCount = 0;

const baseUrl = 'https://instatruck.github.io/instatruck-driver-app'
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++;
}
});


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}`
};
}


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');
39 changes: 39 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Test Report</title>
<style>
table {
width: 100%;
border-collapse: collapse;
}

th,
td {
border: 1px solid black;
padding: 10px;
text-align: center;
}

th {
background-color: #f2f2f2;
}
</style>
</head>

<body>
<h1>Driver App Test Report</h1>
<table id="testTable">
<tr>
<th>Test Type</th>
<th>Total Test Cases</th>
<th>Total Passed</th>
<th>Total Failed</th>
<th>Report Link</th>
</tr>
</table>
<script src="script.js"></script>
</body>
</html>
25 changes: 25 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* eslint-disable prettier/prettier */

fetch('report.json')
.then(response => response.json())
.then(data => {
// Populate the table with dynamic data
const table = document.getElementById('testTable');

data.forEach(testType => {
const row = table.insertRow();
const columns = ['testType', 'totalTestCases', 'totalPass', 'totalFail', 'reportLink'];

columns.forEach(column => {
const cell = row.insertCell();
if (column === 'reportLink') {
cell.innerHTML = `<a href="${testType[column]}">View Report</a>`;
} else {
cell.textContent = testType[column];
}
});
});
})
.catch(error => {
console.error('Error fetching test data:', error);
});

0 comments on commit e5c7d57

Please sign in to comment.