merge test reports

This commit is contained in:
Martin McKeaveney 2022-05-20 01:04:52 +01:00
parent a042af3c86
commit b06e52ee48
1 changed files with 28 additions and 24 deletions

View File

@ -1,8 +1,8 @@
#!/usr/bin/env node #!/usr/bin/env node
const fetch = require("node-fetch") const fetch = require("node-fetch")
const fs = require("fs")
const path = require("path") const path = require("path")
const { merge } = require("mochawesome-merge")
const WEBHOOK_URL = process.env.CYPRESS_WEBHOOK_URL const WEBHOOK_URL = process.env.CYPRESS_WEBHOOK_URL
const OUTCOME = process.env.CYPRESS_OUTCOME const OUTCOME = process.env.CYPRESS_OUTCOME
@ -10,29 +10,32 @@ const DASHBOARD_URL = process.env.CYPRESS_DASHBOARD_URL
const GIT_SHA = process.env.GITHUB_SHA const GIT_SHA = process.env.GITHUB_SHA
const GITHUB_ACTIONS_RUN_URL = process.env.GITHUB_ACTIONS_RUN_URL const GITHUB_ACTIONS_RUN_URL = process.env.GITHUB_ACTIONS_RUN_URL
// read the report file async function generateReport() {
const REPORT_PATH = path.resolve( // read the report file
__dirname, const REPORT_PATH = path.resolve(
"..", __dirname,
"cypress", "..",
"reports", "cypress",
"mocha", "reports",
"mochawesome.json" "mocha",
) "*.json"
const testReport = JSON.parse(fs.readFileSync(REPORT_PATH, "utf-8")) )
const testReport = await merge({ files: [REPORT_PATH] })
return testReport
}
const { async function discordCypressResultsNotification(report) {
suites, const {
tests, suites,
passes, tests,
pending, passes,
failures, pending,
duration, failures,
passPercent, duration,
skipped, passPercent,
} = testReport.stats skipped,
} = report.stats
async function discordCypressResultsNotification() {
const options = { const options = {
method: "POST", method: "POST",
headers: { headers: {
@ -63,7 +66,7 @@ async function discordCypressResultsNotification() {
fields: [ fields: [
{ {
name: "Commit", name: "Commit",
value: GIT_SHA, value: GIT_SHA || "None Supplied",
}, },
{ {
name: "Cypress Dashboard URL", name: "Cypress Dashboard URL",
@ -121,7 +124,8 @@ async function discordCypressResultsNotification() {
} }
async function run() { async function run() {
await discordCypressResultsNotification() const report = await generateReport()
await discordCypressResultsNotification(report)
} }
run() run()