Skip to content

Commit

Permalink
Fix report
Browse files Browse the repository at this point in the history
  • Loading branch information
yasserfaraazkhan committed Feb 3, 2025
1 parent ba9dd11 commit b20d3e7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
8 changes: 6 additions & 2 deletions detox/save_report.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,18 @@ const saveReport = async () => {
// Merge all XML reports into one single XML report
const platform = process.env.IOS === 'true' ? 'ios' : 'android';
const combinedFilePath = `${ARTIFACTS_DIR}/${platform}-combined.xml`;

console.log('Combined file path:', combinedFilePath);
console.log('Merfe file arg:', [`${ARTIFACTS_DIR}/${platform}-results*/${platform}-junit*.xml`]);

await mergeFiles(path.join(__dirname, combinedFilePath), [`${ARTIFACTS_DIR}/${platform}-results*/${platform}-junit*.xml`]);
console.log(`Merged, check ${combinedFilePath}`);

// Read XML from a file
const xml = fse.readFileSync(combinedFilePath);
const {testsuites} = convertXmlToJson(xml);
const {testsuites} = convertXmlToJson(xml, platform);

console.log('**************** Tests:', testsuites.tests);
console.log('**************** Tests:', testsuites);

// Generate short summary, write to file and then send report via webhook
const allTests = getAllTests(testsuites);
Expand Down
32 changes: 19 additions & 13 deletions detox/utils/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,30 @@ const {ARTIFACTS_DIR} = require('./constants');

const MAX_FAILED_TITLES = 5;

function convertXmlToJson(xml) {
const platform = process.env.IOS === 'true' ? 'ios' : 'android';
function convertXmlToJson(xml, platform) {
const jsonFile = `${ARTIFACTS_DIR}/${platform}-junit.json`;

// Convert XML to JSON
xml2js.parseString(xml, {mergeAttrs: true}, (err, result) => {
if (err) {
throw err;
}
return new Promise((resolve, reject) => {
// Convert XML to JSON
xml2js.parseString(xml, {mergeAttrs: true}, (parseErr, result) => {
if (parseErr) {
reject(parseErr);
return;
}

// Convert result to a JSON string
const json = JSON.stringify(result, null, 4);
// Convert result to a JSON string
const json = JSON.stringify(result, null, 4);

// Save JSON in a file
fse.writeFileSync(jsonFile, json);
// Save JSON in a file
fse.writeJson(jsonFile, json, (err) => {
if (err) {
reject(err);
return;
}
resolve(readJsonFromFile(jsonFile));
});
});
});

return readJsonFromFile(jsonFile);
}

function getAllTests(testSuites) {
Expand Down

0 comments on commit b20d3e7

Please sign in to comment.