Skip to content

Commit

Permalink
Merge pull request #42 from edanca/fix-mergeResults
Browse files Browse the repository at this point in the history
Fix: Including args and customFileName to mergeResults
  • Loading branch information
fijijavis authored Mar 4, 2020
2 parents 4eb9a55 + e143be7 commit 3b11ec3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ to get a single report for ALL test execution. Consider the following:
1) Create a small node script
```javascript
const mergeResults = require('wdio-json-reporter/mergeResults')
mergeResults()
mergeResults('./Results', 'wdio-json-*', 'wdio-custom-filename.json')
```

*Note:* `wdio-custom-filename.json` is optional, is the parameter is not provided the default value is `wdio-merged.json`

2) Call node script from command line and pass 2 arguments

* <RESULTS_DIR>: Directory where results files are written
Expand All @@ -91,6 +93,16 @@ Example:
node mergeResults.json ./Results "wdio-json-*"
```

3) As part of a wdio hook

```js
// Located in your wdio.conf.js file
onComplete: function (exitCode, config, capabilities, results) {
const mergeResults = require('wdio-json-reporter/mergeResults')
mergeResults('./Results', 'results-*', 'wdio-custom-filename.json')
}
```

Upon completion, the merge script will output a single json file named `wdio-merged.json` in the provided <RESULTS_DIR>


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"eslint-plugin-standard": "~3.0.1",
"jest": "^24.3.0"
},
"resolutions":{
"resolutions": {
"braces": "~2.3.0"
},
"contributors": [
Expand Down
11 changes: 6 additions & 5 deletions src/mergeResults.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ const fs = require('fs')
const path = require('path')

const mergeResults = (...args) => {
const dir = process.argv[2]
const filePattern = process.argv[3]
const dir = args[0] || process.argv[2]
const filePattern = args[1] || process.argv[3]
const customFileName = args[2] || process.argv[4]

const rawData = getDataFromFiles(dir, filePattern)
const mergedResults = mergeData(rawData)
writeFile(dir, mergedResults)
writeFile(dir, mergedResults, customFileName)
}

function getDataFromFiles (dir, filePattern) {
Expand Down Expand Up @@ -43,8 +44,8 @@ function mergeData (rawData) {
return mergedResults
}

function writeFile (dir, mergedResults) {
const fileName = 'wdio-merged.json'
function writeFile (dir, mergedResults, customFileName) {
let fileName = customFileName || 'wdio-merged.json'
const filePath = path.join(dir, fileName)
fs.writeFileSync(filePath, JSON.stringify(mergedResults))
}
Expand Down

0 comments on commit 3b11ec3

Please sign in to comment.