Skip to content

Commit

Permalink
merge cypress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardogiorato committed Aug 11, 2021
1 parent e2b238f commit 88a2d1f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
"scripts": {
"dev": "cypress open",
"test": "cypress run",
"merge": "jrm ./report.xml \"./report/*.xml\""
"merge": "yarn ts-node ./src/merge-cypress-xml.ts"
},
"devDependencies": {
"cypress": "^8.2.0",
"@types/node": "^15.14.0",
"ts-node": "^10.2.0",
"typescript": "^4.3.5"
},
"dependencies": {
"junit-report-merger": "^3.0.0"
"cypress": "^8.2.0",
"junit-report-merger": "^3.0.0",
"xml-js": "^1.6.11"
}
}
27 changes: 27 additions & 0 deletions src/merge-cypress-xml.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as fs from "fs";
import { execSync } from "child_process";
import * as convert from "xml-js";

const reportDir = "report";

const reportFilenames = fs.readdirSync(reportDir);

reportFilenames.forEach((reportFilename) => {
const reportFilePath = "./" + reportDir + "/" + reportFilename;
const reportXml = fs.readFileSync(reportFilePath, "utf8");

const reportJson = JSON.parse(
convert.xml2json(reportXml, { ignoreComment: true, compact: true })
);
const cypressTestsuites = reportJson.testsuites.testsuite;
if (cypressTestsuites && cypressTestsuites.length > 1) {
reportJson.testsuites.testsuite.shift();
}
const newReportXml = convert.json2xml(JSON.stringify(reportJson), {
compact: true,
ignoreComment: true,
});
fs.writeFileSync(reportFilePath, newReportXml);
});

execSync("jrm ./report.xml ./" + reportDir + "/*.xml");
12 changes: 5 additions & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress"]
},
"include": ["**/*.ts"]
}
"compilerOptions": {
"types": ["node", "cypress"],
"typeRoots": ["./node_modules/@types"]
}
}

0 comments on commit 88a2d1f

Please sign in to comment.