Skip to content

Commit f6fd56c

Browse files
committed
update docs
1 parent ff47c8b commit f6fd56c

File tree

3 files changed

+59
-18
lines changed

3 files changed

+59
-18
lines changed

Diff for: README.md

+59-18
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ To start, the actual report generation has been moved out into its own package,
3333

3434
###Sample Report
3535

36-
<img src="./docs/marge-report-1.0.0.png" alt="Mochawesome Report" width="75%" />
37-
<img src="./docs/marge-report-menu-1.0.0.png" alt="Mochawesome Report Menu" width="75%" />
36+
<img src="./docs/marge-report-1.0.1.png" alt="Mochawesome Report" width="75%" />
37+
<img src="./docs/marge-report-menu-1.0.1.png" alt="Mochawesome Report Menu" width="75%" />
3838

3939
###Browser Support
4040
Tested to work in Chrome. *Should* work in any modern web browser including IE9+.
@@ -85,7 +85,7 @@ The two main files to be aware of are:
8585

8686

8787
##Options
88-
Mochawesome supports options via environment variables or passed in to mocha via `--reporter-options`.
88+
Mochawesome supports options via environment variables or passed directly to mocha.
8989

9090
Option Name | Type | Default | Description
9191
:---------- | :--- | :------ | :----------
@@ -104,42 +104,83 @@ Option Name | Type | Default | Description
104104
**Options passed in will take precedence over environment variables.**
105105

106106
####Environment variables
107+
Options can be set via environment variable. To do this you must prefix the variable with `MOCHAWESOME_` and then uppercase the variable name.
107108
```bash
108109
$ export MOCHAWESOME_REPORTDIR=customReportDir
109-
$ export MOCHAWESOME_REPORTFILENAME=customReportFilename
110-
$ export MOCHAWESOME_REPORTTITLE=customReportTitle
111-
$ export MOCHAWESOME_REPORTPAGETITLE=customReportPageTitle
112110
$ export MOCHAWESOME_INLINEASSETS=true
113111
$ export MOCHAWESOME_AUTOOPEN=true
114-
$ export MOCHAWESOME_ENABLECHARTS=false
115-
$ export MOCHAWESOME_ENABLECODE=false
116-
$ export MOCHAWESOME_QUIET=true
117112
```
118113

119114
####Mocha options
115+
You can pass comma-separated options to the reporter via mocha's `--reporter-options` flag.
120116
```bash
121-
$ mocha test.js --reporter mochawesome --reporter-options reportDir=customReportDir,reportFilename=customReportFilename,reportTitle=customReportTitle,reportPageTitle=customReportPageTitle,inlineAssets=true,autoOpen=true,enableCharts=false,enableTestCode=false,quiet=true
117+
$ mocha test.js --reporter mochawesome --reporter-options reportDir=customReportDir,reportFilename=customReportFilename
122118
```
119+
Options can be passed in programatically as well:
123120

124121
```js
125122
var mocha = new Mocha({
126123
reporter: 'mochawesome',
127124
reporterOptions: {
128125
reportDir: 'customReportDir',
129126
reportFilename: 'customReportFilename',
130-
reportTitle: 'customReportTitle',
131-
reportPageTitle: 'customReportPageTitle',
132-
inlineAssets: true,
133-
autoOpen: false,
134-
enableCharts: true,
135-
enableTestCode: true,
136-
quiet: true
127+
enableCharts: false
137128
}
138129
});
139130
```
140131

141132
##Adding Test Context
142-
One of the more request features has been the ability to display additional information about a test within the report. As of version 2.0.0 this is now possible. **TODO: Fill in how to do it**
133+
One of the more request features has been the ability to display additional information about a test within the report. As of version 2.0.0 this is now possible with the `addContext` helper method. This method will add extra information to the test object that will then be displayed inside the report.
134+
135+
###addContext(testObj, context)
136+
137+
param | type | description
138+
:---- | :--- | :----------
139+
testObj | object | The test object
140+
context | string\|object | The context to be added to the test
141+
142+
**Context as a string**
143+
144+
Simple strings will be displayed as is. If you pass a URL, the reporter will attempt to turn it into a link. If the URL links to an image, it will be shown inline.
145+
146+
**Context as an object**
147+
148+
Context passed as an object must adhere to the following shape:
149+
```js
150+
{
151+
title: 'some title' // must be a string
152+
value: {} // can be anything
153+
}
154+
```
155+
156+
####Example
157+
*When using the `addContext` helper, you cannot use an arrow function in your `it` statement because your `this` value will not be the test object.*
158+
```js
159+
const addContext = require('mochawesome/addContext');
160+
161+
describe('test suite', function () {
162+
it('should add context', function () {
163+
// context can be a simple string
164+
addContext(this, 'simple string');
165+
166+
// context can be a url and the report will create a link
167+
addContext(this, 'http://www.url.com/pathname');
168+
169+
// context can be an image url and the report will show it inline
170+
addContext(this, 'http://www.url.com/screenshot-maybe.jpg');
171+
172+
// context can be an object with title and value properties
173+
addContext(this, {
174+
title: 'expected output',
175+
value: {
176+
a: 1,
177+
b: '2',
178+
c: 'd'
179+
}
180+
});
181+
})
182+
});
183+
```
143184

144185
[1]: http://visionmedia.github.io/mocha/
145186
[2]: https://github.com/adamgruber/mochawesome-report-generator

Diff for: docs/marge-report-1.0.1.png

509 KB
Loading

Diff for: docs/marge-report-menu-1.0.1.png

329 KB
Loading

0 commit comments

Comments
 (0)