Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .detoxrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = {
$0: 'jest',
config: 'e2e/jest.e2e.config.js',
},
detached: true,
jest: {
setupTimeout: 220000,
teardownTimeout: 60000, // Increase teardown timeout from default 30s to 60s
Expand Down
291 changes: 291 additions & 0 deletions .github/scripts/e2e-merge-detox-junit-reports.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,291 @@
#!/usr/bin/env node

/**
* Merges multiple junit XML reports into a single deduplicated report.
*
* For test cases that appear in multiple reports (retries), keeps only the
* LAST run result based on file timestamp. This means:
* - If a test fails initially but passes on retry, it shows as PASSED
* - If a test passes initially but fails on retry, it shows as FAILED
* - Only the most recent result is included in the final report
*
* This is useful when Detox retries failed tests, creating multiple XML
* files per test run, and we want the final report to reflect the actual
* outcome after all retries.
*
* Process:
* 1) Find all junit-*.xml files in e2e/reports directory
* 2) Parse and group test cases by unique key (suiteName::testName::className)
* 3) Keep only the latest result for each test case (overwrites earlier results)
* 4) Recalculate suite statistics based on deduplicated results
* 5) Write merged report to junit.xml
*/

import { readdir, readFile, writeFile } from 'fs/promises';
import { join } from 'path';
import xml2js from 'xml2js';

const env = {
REPORTS_DIR: process.env.E2E_REPORTS_DIR || './e2e/reports',
OUTPUT_FILE: process.env.E2E_OUTPUT_FILE || 'junit.xml',
};

const xmlParser = new xml2js.Parser();
const xmlBuilder = new xml2js.Builder({
xmldec: { version: '1.0', encoding: 'UTF-8' },
renderOpts: { pretty: true, indent: ' ' },
});

/**
* Extract timestamp from filename (e.g., junit-2025-10-17T12-18-43-667Z.xml)
* @param {string} filename - The filename to extract timestamp from
* @returns {string} Sortable timestamp string
*/
function extractTimestamp(filename) {
const match = filename.match(/junit-(.+)\.xml$/);
return match ? match[1] : '';
}

/**
* Find all junit XML files in the reports directory
* @returns {Promise<string[]>} Sorted array of XML filenames
*/
async function findJUnitXmlFiles() {
try {
const files = await readdir(env.REPORTS_DIR);
const xmlFiles = files
.filter(f => f.startsWith('junit-') && f.endsWith('.xml'))
.sort((a, b) => extractTimestamp(a).localeCompare(extractTimestamp(b)));

return xmlFiles;
} catch (error) {
if (error.code === 'ENOENT') {
console.warn(`⚠️ Reports directory not found: ${env.REPORTS_DIR}`);
return [];
}
throw error;
}
}

/**
* Parse a junit XML file
* @param {string} filePath - Path to the XML file
* @returns {Promise<Object>} Parsed XML data
*/
async function parseJUnitXML(filePath) {
const xmlContent = await readFile(filePath, 'utf-8');
return await xmlParser.parseStringPromise(xmlContent);
}

/**
* Parse all XML files and combine test cases, keeping only the LATEST result for each test
* @returns {Promise<Object|null>} Merged report data or null if no files found
*/
async function parseAndMergeReports() {
console.log('🔍 Scanning for junit XML files...');

const xmlFiles = await findJUnitXmlFiles();

if (xmlFiles.length === 0) {
console.log('⚠️ No junit XML files found to merge');
return null;
}

console.log(`📁 Found ${xmlFiles.length} report file(s):`);
xmlFiles.forEach(f => console.log(` - ${f}`));

// Map to store LATEST result for each test case
// Key: "suiteName::testcaseName::classname"
// Value: { testcase, suiteName, suiteAttrs, timestamp }
const testCaseMap = new Map();
const suitePropertiesMap = new Map();

// Process each XML file in chronological order (earliest to latest)
for (const xmlFile of xmlFiles) {
const filePath = join(env.REPORTS_DIR, xmlFile);
const timestamp = extractTimestamp(xmlFile);

console.log(`\n📄 Processing: ${xmlFile}`);

try {
const parsed = await parseJUnitXML(filePath);

if (!parsed.testsuites || !parsed.testsuites.testsuite) {
console.log(' ⚠️ No test suites found, skipping');
continue;
}

const testsuites = Array.isArray(parsed.testsuites.testsuite)
? parsed.testsuites.testsuite
: [parsed.testsuites.testsuite];

for (const testsuite of testsuites) {
const suiteName = testsuite.$.name;

if (!testsuite.testcase) {
console.log(` ⚠️ Suite "${suiteName}" has no test cases`);
continue;
}

const testcases = Array.isArray(testsuite.testcase)
? testsuite.testcase
: [testsuite.testcase];

console.log(` 📦 Suite: "${suiteName}" (${testcases.length} test(s))`);

for (const testcase of testcases) {
const testName = testcase.$.name;
const className = testcase.$.classname || suiteName;
const key = `${suiteName}::${testName}::${className}`;

const isFailure = !!testcase.failure;
const isError = !!testcase.error;
const isSkipped = !!testcase.skipped;

// Check if we've seen this test before
const existing = testCaseMap.get(key);
const isRetry = !!existing;

// Always keep the LATEST result (overwrite previous)
testCaseMap.set(key, {
testcase,
suiteName,
suiteAttrs: testsuite.$,
timestamp,
});

const statusIcon = isFailure ? '❌' : isError ? '⚠️' : isSkipped ? '⊘' : '✅';
const retryLabel = isRetry ? ' (retry)' : '';
console.log(` ${statusIcon} ${testName}${retryLabel}`);
}

// Track properties (use latest)
if (testsuite.properties) {
suitePropertiesMap.set(suiteName, testsuite.properties);
}
}
} catch (error) {
console.warn(`⚠️ Failed to process ${xmlFile}: ${error.message}`);
continue;
}
}

console.log('\n🔄 Building deduplicated report with latest results...');
console.log(` Total unique test cases: ${testCaseMap.size}`);

// Group test cases by suite name
const suiteMap = new Map();

for (const [key, { testcase, suiteName, suiteAttrs }] of testCaseMap) {
if (!suiteMap.has(suiteName)) {
suiteMap.set(suiteName, {
attrs: suiteAttrs,
testcases: [],
properties: suitePropertiesMap.get(suiteName),
});
}
suiteMap.get(suiteName).testcases.push(testcase);
}

// Build test suites with recalculated counts
const finalTestSuites = [];
let totalTests = 0;
let totalFailures = 0;
let totalErrors = 0;
let totalSkipped = 0;
let totalTime = 0;

for (const [suiteName, { attrs, testcases, properties }] of suiteMap) {
// Recalculate suite statistics based on deduplicated test cases
let suiteFailures = 0;
let suiteErrors = 0;
let suiteSkipped = 0;
let suiteTime = 0;

for (const testcase of testcases) {
if (testcase.failure) suiteFailures++;
if (testcase.error) suiteErrors++;
if (testcase.skipped) suiteSkipped++;
suiteTime += parseFloat(testcase.$.time || '0');
}

const suite = {
$: {
...attrs,
name: suiteName,
tests: testcases.length,
failures: suiteFailures,
errors: suiteErrors,
skipped: suiteSkipped,
time: suiteTime.toFixed(3),
},
testcase: testcases,
};

if (properties) {
suite.properties = properties;
}

finalTestSuites.push(suite);

totalTests += testcases.length;
totalFailures += suiteFailures;
totalErrors += suiteErrors;
totalSkipped += suiteSkipped;
totalTime += suiteTime;
}

// Build final XML structure
const mergedReport = {
testsuites: {
$: {
name: 'jest tests',
tests: totalTests,
failures: totalFailures,
errors: totalErrors,
time: totalTime.toFixed(3),
},
testsuite: finalTestSuites,
},
};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: JUnit Report Missing Skipped Attribute

The root testsuites element in the merged JUnit report is missing the skipped attribute. Although totalSkipped is calculated, it's not included in the final XML output, which creates an inconsistency with individual testsuite elements and deviates from standard JUnit XML format.

Fix in Cursor Fix in Web


console.log('\n📊 Final Report Summary (after deduplication):');
console.log(` Total Test Suites: ${finalTestSuites.length}`);
console.log(` Total Tests: ${totalTests}`);
console.log(` Failures: ${totalFailures}`);
console.log(` Errors: ${totalErrors}`);
console.log(` Skipped: ${totalSkipped}`);
console.log(` Total Time: ${totalTime.toFixed(3)}s`);

return mergedReport;
}

/**
* Main execution
*/
async function main() {
console.log('🚀 Starting JUnit report merge...\n');

const mergedReport = await parseAndMergeReports();

if (!mergedReport) {
console.log('\n⚠️ No reports to merge, skipping output file creation');
process.exit(0);
}

// Convert to XML
const xml = xmlBuilder.buildObject(mergedReport);

// Write merged report
const outputPath = join(env.REPORTS_DIR, env.OUTPUT_FILE);
await writeFile(outputPath, xml, 'utf-8');

console.log(`\n✅ Merged report written to: ${outputPath}`);
console.log('🎉 Merge complete!\n');
}

main().catch((error) => {
console.error('\n❌ Error merging reports:', error);
process.exit(1);
});

17 changes: 8 additions & 9 deletions .github/workflows/run-e2e-regression-tests-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Android E2E Regression Tests

on:
schedule:
- cron: '0 */3 * * *' # Every 3 hours
- cron: '0 */3 * * *' # Every 3 hours
workflow_dispatch:
inputs:
notify_on_pass:
Expand Down Expand Up @@ -41,7 +41,6 @@ jobs:
total_splits: 4
secrets: inherit


regression-confirmations-redesigned-android:
name: 'Confirmations Redesigned Regression (Android) - ${{ matrix.split }}'
needs: [build-android-apks]
Expand Down Expand Up @@ -153,7 +152,7 @@ jobs:
split_number: ${{ matrix.split }}
total_splits: 2
secrets: inherit

regression-ux-android:
name: 'UX Regression (Android) - ${{ matrix.split }}'
needs: [build-android-apks]
Expand Down Expand Up @@ -189,19 +188,19 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download all test results

- name: Download JUnit XML result files
uses: actions/download-artifact@v4
continue-on-error: true
with:
path: all-test-results/
pattern: '*-android-*-test-results'
pattern: '*-android-*-test-junit-results'

- name: Post Test Report
uses: dorny/test-reporter@dc3a92680fcc15842eef52e8c4606ea7ce6bd3f3
with:
name: 'Android E2E Regression Test Results'
path: 'all-test-results/**/*.xml'
path: 'all-test-results/**/junit.xml'
reporter: 'jest-junit'
fail-on-error: false
list-suites: 'failed'
Expand All @@ -212,7 +211,7 @@ jobs:
continue-on-error: true
with:
name: android-merged-test-report
path: all-test-results/**/*.xml
path: all-test-results/**/junit.xml

- name: Generate Test Summary
id: summary
Expand Down Expand Up @@ -257,4 +256,4 @@ jobs:
with:
webhook: ${{ secrets.REGRESSION_E2E_SLACK_WEBHOOK_URL }}
webhook-type: incoming-webhook
payload-file-path: /tmp/slack-payload.json
payload-file-path: /tmp/slack-payload.json
Loading
Loading