Skip to content

Commit

Permalink
V5 conversion (#38)
Browse files Browse the repository at this point in the history
* v5 working updates without screenshots

* working refactor

* finished writing tests
  • Loading branch information
fijijavis authored May 21, 2019
1 parent 508302a commit abed074
Show file tree
Hide file tree
Showing 58 changed files with 3,215 additions and 2,920 deletions.
4 changes: 0 additions & 4 deletions .babelrc

This file was deleted.

4 changes: 2 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"browser": true
},
"env": {
"mocha": true
}
"jest": true
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ screenshots/
phantom.log
wdio-mochawesome-report/
mochawesome-report/
yarn-error.log
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@ install:
- yarn --frozen-lockfile

script:
- yarn test:unit
- yarn build
- yarn hub:start
- yarn test:func
- yarn lint
- yarn test
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 Jim Davis
Copyright (c) 2019 Jim Davis

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
89 changes: 75 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,80 @@ WDIO Mochawesome Reporter
Generates test results in the json formated needed to create [Mochawesome](https://github.com/adamgruber/mochawesome) reports.


## WDIO Version Compatibility

There are breaking changes between WDIO v4 and v5 with how custom reporters work. The chart below shows the versions of this reporter and their WDIO compatibility version.

| WDIO Json Reporter | WDIO |
| ------------------ | ---- |
| <= 2.0.1 | v4 |
| >= 3.0.0 | v5 |


# WDIO v5 Compatibility

** NOTE **
With WDIO v5 the reporter has undergone some major changes. At present there is no mechanism for getting a single combined report. See [Issue 37](https://github.com/fijijavis/wdio-mochawesome-reporter/issues/37) for details.

## Installation

```shell
npm install --save wdio-mochawesome-reporter
* NPM
```bash
npm install wdio-mochawesome-reporter --save-dev
```

A dependency will be added to your `package.json`
* Yarn
```bash
yarn add wdio-mochawesome-reporter --dev
```

```json
{
"dependencies": {
"wdio-mochawesome-reporter": "^1.0.0"
}
}
## Configuration

### Results to STDOUT
```js
reporters: [
'dot',
['mochawesome',{ stdout: true }]
],
```

### Results to File
```js
reporters: [
'dot',
['mochawesome',{
outputDir: './Results'
}]
],
```

### Results to File with custom file name
```js
reporters: [
'dot',
['mochawesome',{
outputDir: './Results',
outputFileFormat: function(opts) {
return `results-${opts.cid}.${opts.capabilities}.json`
}
}]
],
```


# WDIO v4 Compatibility


## Installation

* NPM
```bash
npm install wdio-mochawesome-reporter@^2.0.1 --save
```

* Yarn
```bash
yarn add wdio-json-reporter@^2.0.1 --dev
```

## Using
Expand Down Expand Up @@ -60,15 +120,14 @@ module.exports = {
```



## Mochawesome Report Generator
# Mochawesome Report Generator
To convert the json generated by this package into a Mochawesome report you will need to use the [Mochawesome Report Generator](https://github.com/adamgruber/mochawesome-report-generator).

In summary...

* Add the package to your project
```shell
npm install --save mochawesome-report-generator
yarn add mochawesome-report-generator --dev
```

* Add a script to your package.json to generate the report
Expand All @@ -78,9 +137,11 @@ npm install --save mochawesome-report-generator
},
```
1) `path/to/results.json` = path and name of json file
2) `--reportTitle 'My Project Results' = unique report title
2) `--reportTitle 'My Project Results'` = unique report title

## Version Compatibility
v1.x of ```wdio-mochawesome-reporter``` is compatible with ```2.3.2``` of ```mochawesome-report-generator```

v2.x of ```wdio-mochawesome-reporter``` is compatible with version ```3.1.3``` of ```mochawesome-report-generator```
v2.x of ```wdio-mochawesome-reporter``` is compatible with version ```3.1.5``` of ```mochawesome-report-generator```

v3.x of ```wdio-mochawesome-reporter``` is compatible with version ```3.1.5``` of ```mochawesome-report-generator```
50 changes: 18 additions & 32 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wdio-mochawesome-reporter",
"version": "2.0.1",
"version": "3.0.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",
Expand All @@ -9,21 +9,10 @@
"type": "git",
"url": "git+https://github.com/fijijavis/wdio-mochawesome-reporter.git"
},
"main": "build/reporter.js",
"directories": {
"lib": "./lib"
},
"main": "src/index.js",
"scripts": {
"build": "yarn clean && yarn compile",
"clean": "rm -rf ./build && rm -rf ./screenshots",
"compile": "babel src/ -d build/",
"eslint": "eslint ./src test/",
"hub:start": "phantomjs --webdriver=4444 2>&1 > phantom.log &",
"hub:stop": "ps -eaf | grep -i phantomjs | awk {'print $2'} | xargs kill -9",
"test:unit": "mocha ./src/**/*.spec.js --reporter mochawesome",
"test:func:local": "yarn build && mocha ./test/specs/tests.js",
"test:func": "mocha ./test/specs/tests.js",
"buildreport": "marge --reportDir ./wdio-mochawesome-report/mochawesome ./wdio-mochawesome-report/wdiomochawesome.json"
"lint": "eslint ./src test/",
"test": "jest"
},
"keywords": [
"mochawesome",
Expand All @@ -36,33 +25,30 @@
"url": "https://github.com/fijijavis/wdio-mochawesome-reporter/issues"
},
"dependencies": {
"json-stringify-safe": "^5.0.1",
"mkdirp": "~0.5.1",
"@wdio/reporter": "^5.7.8",
"strip-ansi": "^5.2.0",
"uuid": "~3.0.1"
},
"devDependencies": {
"babel-cli": "~6.24.1",
"babel-core": "~6.25.0",
"babel-eslint": "~7.2.1",
"babel-istanbul": "~0.12.2",
"babel-plugin-add-module-exports": "~0.2.1",
"babel-preset-env": "~1.6.1",
"babel-preset-stage-0": "~6.24.1",
"chai": "~3.5.0",
"del": "~2.2.0",
"eslint": "~4.4.0",
"eslint-config-standard": "~10.2.0",
"eslint-plugin-import": "~2.7.0",
"eslint-plugin-node": "~5.1.0",
"eslint-plugin-promise": "~3.5.0",
"eslint-plugin-standard": "~3.0.1",
"mocha": "~3.4.1",
"mochawesome": "^3.0.3",
"wdio-mocha-framework": "~0.5.12",
"wdio-selenium-standalone-service": "~0.0.8",
"webdriverio": "^4.10.1"
"jest": "^24.8.0",
"jest-matchers": "^20.0.3"
},
"contributors": [
"Jim Davis"
]
],
"peerDependencies": {
"@wdio/cli": "^5.8.4",
"mochawesome-report-generator": "^3.1.5"
},
"jest": {
"testPathIgnorePatterns": [
"./src"
]
}
}
65 changes: 65 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const WDIOReporter = require('@wdio/reporter').default
const Suite = require('./suite')
const Stats = require('./stats')
const Test = require('./test')

class WdioMochawesomeReporter extends WDIOReporter {
constructor (options) {
options = Object.assign(options)
super(options)
}

onRunnerStart (runner) {
this.config = runner.config
this.sanitizedCaps = runner.sanitizedCapabilities
this.sessionId = runner.sessionId
// mochawesome requires this root suite for HTML report generation to work properly
this.results = {
stats: new Stats(runner.start),
suites: new Suite(true, {'title': ''}),
copyrightYear: new Date().getFullYear()
}
}

onSuiteStart (suite) {
this.currSuite = new Suite(false, suite, this.sanitizedCaps)
this.results.stats.incrementSuites()
}

onTestStart (test) {
this.currTest = new Test(test, this.currSuite.uuid)
this.currTest.addSessionContext(this.sessionId)
}

onAfterCommand (cmd) {
const isScreenshotEndpoint = /\/session\/[^/]*\/screenshot/
if (isScreenshotEndpoint.test(cmd.endpoint) && cmd.result.value) {
this.currTest.addScreenshotContext(cmd.result.value)
}
}

onTestEnd (test) {
// skipped tests do not emit the TestStart event
if (!this.currTest) {
this.currTest = new Test(test, this.currSuite.uuid)
}
this.currTest.duration = test._duration
this.currTest.updateResult(test)
this.currTest.context = JSON.stringify(this.currTest.context)
this.currSuite.addTest(this.currTest)
this.results.stats.incrementTests(this.currTest)
}

onSuiteEnd (suite) {
this.currSuite.duration = suite.duration
this.results.suites.addSuite(this.currSuite)
}

onRunnerEnd (runner) {
this.results.stats.end = runner.end
this.results.stats.duration = runner.duration
this.write(JSON.stringify(this.results))
}
}

exports.default = WdioMochawesomeReporter
23 changes: 0 additions & 23 deletions src/map_stats/InitStats.js

This file was deleted.

11 changes: 0 additions & 11 deletions src/map_stats/InitStats.spec.js

This file was deleted.

18 changes: 0 additions & 18 deletions src/map_stats/UpdateStats.js

This file was deleted.

Loading

0 comments on commit abed074

Please sign in to comment.