Skip to content

Commit

Permalink
Merge pull request #18 from stephen/master
Browse files Browse the repository at this point in the history
Add options for printing to stdout and ignoring epilogue
  • Loading branch information
fijijavis authored Oct 30, 2017
2 parents b6f34d0 + 0b800a0 commit becbb45
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
36 changes: 33 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,36 @@ module.exports = {
};
```

You can also choose to send the reporter output to stdout instead of writing to a file:

```js
// wdio.conf.js
module.exports = {
// ...
reporters: ['json'],
reporterOptions: {
useStdout: true
},
// ...
};
```

If you do not want to print out the mocha epilogue (i.e. `1 passing (5.2s)`), you can suppress it:

```js
// wdio.conf.js
module.exports = {
// ...
reporters: ['json'],
reporterOptions: {
suppressEpilogue: true
},
// ...
};
```



## Sample Output
```
{
Expand Down Expand Up @@ -184,7 +214,7 @@ module.exports = {
"duration": 5374,
"state": "fail",
"error": "element (#not-a-real-element) still not visible after 5000ms",
"errorType": "CommandError",
"errorType": "CommandError",
"standardError": "CommandError: element (#not-a-real-element) still not visible after 5000ms\n at Object.Future.wait (/node_modules/fibers/future.js:449:15)\n at Object.waitForVisible (/node_modules/wdio-sync/build/index.js:345:27)\n at Object.create.searchForStores.value (/PageObjects/some.page.js:15:17)\n at Context.<anonymous> (/Tests/sample.spec.js:64:25)\n at /node_modules/wdio-sync/build/index.js:579:24\n - - - - -\n at elements(\"#not-a-real-element\") - isVisible.js:49:17\n at isVisible(\"#not-a-real-element\") - waitForVisible.js:40:22"
}
],
Expand All @@ -197,8 +227,8 @@ module.exports = {
"associatedSuite": "sample test suite number 2"
}
]
}
]
}
]
}
```

Expand Down
8 changes: 7 additions & 1 deletion lib/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class JsonReporter extends events.EventEmitter {
if(options.combined) {
this.combineJsons(resultJsons);
}
epilogue.call(baseReporter)
if (!options.suppressEpilogue){
epilogue.call(baseReporter)
}
})
}

Expand Down Expand Up @@ -163,6 +165,10 @@ class JsonReporter extends events.EventEmitter {
}

write (json, browserName, cid) {
if (this.options.useStdout) {
return console.log(JSON.stringify(json));
}

if (!this.options || typeof this.options.outputDir !== 'string') {
return console.log(`Cannot write json report: empty or invalid 'outputDir'.`)
}
Expand Down

0 comments on commit becbb45

Please sign in to comment.