-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* create script to merge files * add documentation and change util export to make it more friendly to use * version bump
- Loading branch information
Showing
4 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// make mergeResults available at the root | ||
module.exports = require('./src/mergeResults') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "wdio-mochawesome-reporter", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"description": "A WebdriverIO plugin. Generates json results in Mochawesome format.", | ||
"author": "Jim Davis <[email protected]>", | ||
"homepage": "https://github.com/fijijavis/wdio-mochawesome-reporter.git#readme", | ||
|
@@ -10,6 +10,10 @@ | |
"url": "git+https://github.com/fijijavis/wdio-mochawesome-reporter.git" | ||
}, | ||
"main": "src/index.js", | ||
"files": [ | ||
"src", | ||
"mergeResults.js" | ||
], | ||
"scripts": { | ||
"lint": "eslint ./src test/", | ||
"test": "jest" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
const mergeResults = (...args) => { | ||
const dir = process.argv[2] | ||
const filePattern = process.argv[3] | ||
|
||
const rawData = getDataFromFiles(dir, filePattern) | ||
const mergedResults = mergeData(rawData) | ||
writeFile(dir, mergedResults) | ||
} | ||
|
||
function getDataFromFiles (dir, filePattern) { | ||
const fileNames = fs.readdirSync(dir).filter(file => file.match(filePattern)) | ||
const data = [] | ||
|
||
fileNames.forEach(fileName => { | ||
data.push(JSON.parse(fs.readFileSync(`${dir}/${fileName}`))) | ||
}) | ||
|
||
return data | ||
} | ||
|
||
function mergeData (rawData) { | ||
let mergedResults | ||
rawData.forEach(data => { | ||
if (mergedResults === undefined) { | ||
// use the first result so that we have the right shape for the mochawesome report generator | ||
mergedResults = {} | ||
Object.assign(mergedResults, data) | ||
} else { | ||
// increment stats totals | ||
mergedResults.stats.suites += data.stats.suites | ||
mergedResults.stats.tests += data.stats.tests | ||
mergedResults.stats.passes += data.stats.passes | ||
mergedResults.stats.pending += data.stats.pending | ||
mergedResults.stats.failures += data.stats.failures | ||
mergedResults.stats.duration += data.stats.duration | ||
mergedResults.stats.testsRegistered += data.stats.testsRegistered | ||
mergedResults.stats.skipped += data.stats.skipped | ||
mergedResults.stats.hasSkipped = mergedResults.stats.skipped > 0 | ||
mergedResults.stats.passPercent = mergedResults.stats.tests === 0 ? 0 : Math.round((mergedResults.stats.passes / mergedResults.stats.tests) * 100) | ||
mergedResults.stats.pendingPercent = mergedResults.stats.tests === 0 ? 0 : Math.round((mergedResults.stats.pending / mergedResults.stats.tests) * 100) | ||
|
||
// add suites | ||
data.suites.suites.forEach(suite => { | ||
mergedResults.suites.suites.push(suite) | ||
}) | ||
} | ||
}) | ||
return mergedResults | ||
} | ||
|
||
function writeFile (dir, mergedResults) { | ||
const fileName = 'wdio-ma-merged.json' | ||
const filePath = path.join(dir, fileName) | ||
fs.writeFileSync(filePath, JSON.stringify(mergedResults)) | ||
} | ||
|
||
module.exports = mergeResults |