html-reporter 9.3.0 → 9.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,684 +1,684 @@
1
- # html-reporter
2
-
3
- Requires **[hermione](https://github.com/gemini-testing/hermione)@4x**.
4
-
5
- Plugin for [hermione](https://github.com/gemini-testing/hermione) which is intended to aggregate the results of tests running into html report.
6
-
7
- Test result is saved to the [SQLite](https://www.sqlite.org/index.html) database. It means that you can't open local report by 'file://' protocol.
8
- Use gui mode - `npx hermione gui` or start a local server - `npx http-server -p 8080` at terminal from folder where report placed and open page `http://localhost:8080` at browser.
9
-
10
- You can read more about hermione plugins [here](https://github.com/gemini-testing/hermione#plugins).
11
-
12
- ## Installation
13
-
14
- ```bash
15
- npm install html-reporter
16
- ```
17
-
18
- **:warning: Requires Hermione >=2.7.0**
19
-
20
- ## Usage
21
-
22
- Plugin has following configuration:
23
-
24
- * **enabled** (optional) `Boolean` – enable/disable the plugin; by default plugin is enabled
25
- * **path** (optional) `String` - path to directory for saving html report file; by
26
- default html report will be saved into `hermione-report/index.html` inside current work
27
- directory.
28
- * **saveErrorDetails** (optional) `Boolean` – save/don't save error details to json-files (to error-details folder); `false` by default.
29
-
30
- Any plugin of hermione can add error details when throwing an error. Details can help a user to debug a problem in a test. Html-reporter saves these details to a file with name `<hash of suite path>-<browser>_<retry number>_<timestamp>.json` in the error-details folder. Below a stacktrace html-reporter adds the section `Error details` with the link `title` pointing to the json-file. A user can open it in a browser or any IDE.
31
-
32
- How to add error details when throwing an error from a plugin:
33
- ```js
34
- const err = new Error('some error');
35
- err.details = {title: 'description, will be used as url title', data: {} | [] | 'some additional info'};
36
- throw err;
37
- ```
38
-
39
- * **defaultView** (optional) `String` - default view mode. Available values are:
40
-
41
- * `all` - show all tests. Default value.
42
- * `failed` - show only failed tests.
43
-
44
- * **diffMode** (optional) - `String` - default diff mode. Available values are:
45
-
46
- * `3-up` - show all images (expected, actual, diff) in column. Default value;
47
- * `3-up-scaled` - show all images in row (fit into page width);
48
- * `only-diff` - show only diff image;
49
- * `switch` - mode with ability to switch between expected and actual images (use click on mouse in images field to switch);
50
- * `swipe` - mode with ability to move divider between expected and actual images;
51
- * `onion-skin` - mode with ability to change the transparency of actual image.
52
-
53
- * **baseHost** (optional) - `String` - it changes original host for view in the browser; by default original host does not change
54
- * **errorPatterns** (optional) - `Array` - error message patterns are used:
55
-
56
- * to show more understandable information about matched error;
57
- * in 'Group by' mode with selected 'error' key.
58
-
59
- Array elements must be one of the types:
60
-
61
- * `Object` with required fields *name*, *pattern* and optional field *hint* - {*name*: `String`, *pattern*: `String`, *hint*: `String`};
62
- * `String` which will be interpret as *name* and *pattern*.
63
-
64
- When one of error patterns are matched on error message then:
65
-
66
- * *name* of error pattern will be displayed as title of error message and original error message will be hidden under details;
67
- * *hint* of error pattern will be displayed after error *stack* field. Can be specified as html string. For example, `<div>some-useful-hint</div>`.
68
-
69
- In 'Group by' mode with selected 'error' key test will be associated with group if test error matches on group error pattern. New group will be created if test cannot be associated with existing groups.
70
-
71
- * **metaInfoBaseUrls** (optional) `Object` - base paths for making link from Meta-info values. Object option must be Meta-info's key and value must be `String`. For example, {'file': 'base/path'}.
72
- * **saveFormat** (**DEPRECATED**, optional) `String` - allows to specify the format, in which the results will be saved. Available values are:
73
- * `sqlite` - save tests results to Sqlite database. Default value.
74
- * **customGui** (optional) `Object` – allows to specify custom controls for gui-mode and define actions for them. `{}` is default value. Ordinarily custom controls should be split by sections depending on the purposes of the controls. At least one section should be specified.
75
- The structure of the custom-gui object:
76
- ```js
77
- customGui: {
78
- 'choose-any-name-for-the-section-1': [{an object describing a group of controls}, ...],
79
- 'choose-any-name-for-the-section-2': [{an object describing a group of controls}, ...]
80
- }
81
- ```
82
- The keys of customGui-object are any strings describing sections of controls. It is upon a user to choose appropriate names for the sections.
83
- A value of a key should be an array that holds a set of objects describing groups of controls.
84
-
85
- #### customGui-group-object
86
-
87
- An object that describes one group of controls has the following structure:
88
- ```js
89
- {
90
- type: 'specify-type-of-the-controls',
91
- controls: [
92
- {
93
- label: 'specify-label-for-the-control',
94
- value: 'specify-value-of-the-control'
95
- },
96
- {
97
- ...
98
- }
99
- ],
100
- initialize: async ({hermione, ctx}) => {
101
- // here goes your code
102
- // returned value will be ignored
103
- },
104
- action: async ({hermione, ctx, control}) => {
105
- // here goes your code
106
- // returned value will be ignored
107
- }
108
- }
109
- ```
110
-
111
- * **type** (required) `String` – defines the type of controls. Available values are: `button` and `radiobutton`.
112
-
113
- * **controls** (required) `Array` – array of objects that describe controls. Each object should have string fields `label` and `value`. `Label` defines the caption of the control, and `value` – its value.
114
-
115
- * **initialize** (optional) – an async function to be executed at server-side at gui-mode start. Input parameter of this function is an object `{hermione, ctx}`, where `hermione` is an instance of hermione and `ctx` is the reference to the whole [object](#customGui-group-object) the initialize-function is being run for. A value that initialize-function returns will be ignored.
116
-
117
- * **action** (required) – an async function to be executed at server-side when a user clicks a control. Input parameter of this function is an object `{hermione, ctx, control}`, where `hermione` is an instance of hermione, `ctx` is the reference to the whole [object](#customGui-group-object) the action-function is being run for, and `control` points to the control the user clicked. A value that action-function returns will be ignored.
118
-
119
- #### Example: how to add radiobuttons for base url switching in gui-mode
120
- ```js
121
- customGui: {
122
- 'some-meaningful-name-of-section': [
123
- {
124
- type: 'radiobutton',
125
- controls: [
126
- {
127
- label: 'Dev',
128
- value: 'http://localhost/development/'
129
- },
130
- {
131
- label: 'Prod',
132
- value: 'http://localhost/production/'
133
- }
134
- ],
135
- initialize: async ({hermione, ctx}) => {
136
- const {config} = hermione;
137
- const browserIds = config.getBrowserIds();
138
-
139
- if (browserIds.length) {
140
- const {baseUrl} = config.forBrowser(browserIds[0]);
141
-
142
- ctx.controls.forEach((control) => {
143
- control.active = (baseUrl === control.value);
144
- });
145
- }
146
- },
147
- action: async ({hermione, ctx, control}) => {
148
- const {config} = hermione;
149
-
150
- config
151
- .getBrowserIds()
152
- .forEach((browserId) => {
153
- config.forBrowser(browserId).baseUrl = control.value;
154
- });
155
- }
156
- }
157
- ]
158
- }
159
- ```
160
-
161
- * **pluginsEnabled** (optional) `Boolean` - enable html-reporter plugins; `false` by default
162
- * **plugins** (optional) `Array` of html-reporter plugin descriptions; `[]` by default. Allows to extend report with custom UI components (both static and gui-mode) and custom server routes (gui-mode only).
163
-
164
- The structure of the plugin descriptions config:
165
- ```js
166
- plugins: [
167
- {
168
- name: 'plugin-name',
169
- component: 'PluginReactComponentName',
170
- point: 'extension-point-name',
171
- position: 'wrap',
172
- config: { param: 'value'}
173
- },
174
- {
175
- name: 'plugin-name',
176
- component: 'AnotherPluginReactComponentName',
177
- point: 'extension-point-name',
178
- position: 'before'
179
- },
180
- // ...
181
- ]
182
- ```
183
-
184
- , where:
185
-
186
- * **name** (required) `String` - a name of an html-reporter plugin _package_. It expected to be `require`-resolvable from your project.
187
- * **component** (optional) `String` - React component name from the plugin.
188
- * **point** (optional) `String` - html-reporter's extension point name. Sets specific place within the html-reporter UI where to place the specified component. [More on extension points](#extension-points).
189
- * **position** (optional) `String` - specifies the way the component is going to be applied to the html-reporter UI extension point. Possible values are:
190
- * `wrap` - to wrap the extension point UI
191
- * `before` - to place the component before the extension point
192
- * `after` - to place the component after the extension point
193
- * **config** (optional) `Object` - plugin configuration
194
-
195
- A plugin with only **name** specified may be used to redefine existing gui-server middleware.
196
-
197
- A plugin may define more than one component. Each component may be applied to several extension points and/or several times to the same point (with separate config entries). The order of the components application is determined by the config order.
198
-
199
- #### html-reporter plugins
200
-
201
- _[Example plugins](https://github.com/gemini-testing/html-reporter/blob//master/./test/func/html-reporter-plugins) are available in functional tests._
202
-
203
- An html-reporter plugin is an object with some set of React components on its keys and an optional key `reducers` with an array of redux reducers to manage the components state (which are later combined by [`reduce-reducers`](https://github.com/redux-utilities/reduce-reducers)).
204
-
205
- An html-reporter plugin expected to have the following module files in the root of the package: `plugin.js` and/or `middleware.js`.
206
-
207
- ##### plugin.js
208
-
209
- Optional module. The file expected to export an object (or set of named exports) or a function returning such an object or an array with some specific structure.
210
-
211
- It is possible to reuse dependencies of html-reporter within plugins (React, Redux, etc). To do so an array should be exported from the module with the list of needed deps followed by a function with the corresponding deps passed to it and returning the plugin itself:
212
-
213
- ```js
214
- import 'plugin-styles.css';
215
-
216
- export default ['react', function(React, options) {
217
- class PluginComponent extends React.Component {
218
- // Component implementation
219
- }
220
-
221
- return {
222
- PluginComponent,
223
- reducers: []
224
- };
225
- }];
226
- ```
227
-
228
- Plugin styles are expected to be loaded with the `plugin.js` and the file is expected to be a single bundle.
229
-
230
- Exported value of the `plugin.js` should be passed to the `__hermione_html_reporter_register_plugin__`. This could be achieved by either configuring your webpack build to produce corresponding `jsonp` library:
231
-
232
- ```js
233
- // ...
234
- output: {
235
- filename: 'plugin.js',
236
- path: __dirname,
237
- library: '__hermione_html_reporter_register_plugin__',
238
- libraryTarget: 'jsonp'
239
- },
240
- // ...
241
- ```
242
-
243
- or, by passing it explicitly:
244
-
245
- ```js
246
- __hermione_html_reporter_register_plugin__(['react', function(React, options) {
247
- /* ... */
248
- return {PluginComponent};
249
- }]);
250
- ```
251
-
252
- ##### middleware.js
253
-
254
- Optional module. Exports a function accepting an **express** `Router`. The plugin routes are expected to be attached to the router. The router are then attached on the `/plugin-routes/:pluginName/` path:
255
-
256
- ```js
257
- module.exports = function(pluginRouter) {
258
- pluginRouter.get('/plugin-route', function(req, res) {
259
- // route implementation
260
- });
261
- };
262
- ```
263
-
264
- The routes then can be called from the plugin React components defined in the `plugin.js`. For convenience the plugin name is always passed with options when function- or array-returning form is used to export plugin as the function options property `pluginName`:
265
-
266
- ```js
267
- export default ['react', 'axios', function(React, axios, {pluginName, pluginConfig, actions, actionNames, selectors}) {
268
- class PluginComponent extends React.Component {
269
- // ... somewhere inside the component ...
270
- const result = await axios.get(`/plugin-routes/${pluginName}/plugin-route`);
271
- }
272
-
273
- return {
274
- PluginComponent,
275
- reducers: []
276
- };
277
- }
278
- ```
279
-
280
- In the example you can also see another convenient properties:
281
- - `pluginName` - plugin name;
282
- - `pluginConfig` - plugin configuration;
283
- - `actions` - the html-reporter **Redux** actions;
284
- - `actionNames` - the html-reporter action names, that used in **Redux** actions. To be able to subscribe on html-reporter events;
285
- - `selectors` - the memoized html-reporter selectors which created using **reselect** library.
286
-
287
-
288
- Available dependencies:
289
- - `react`
290
- - `redux`
291
- - `react-redux`
292
- - `lodash`
293
- - `prop-types`
294
- - `classnames`
295
- - `semantic-ui-react`
296
- - `react-markdown`
297
- - `reduce-reducers`
298
- - `immer`
299
- - `reselect`
300
- - `axios`
301
-
302
- Available components:
303
- - `components`
304
- - `<Details />` - component which allows users to toggle the display of content.
305
- Example of usage:
306
- ```js
307
- // ... inside your react component
308
- render() {
309
- return <Details
310
- title='Some title'
311
- content='Some content' // content that will appear when you click on the title
312
- extendClassNames='some_class_name' // ability to add own css-classes to component
313
- onClick={() => console.log('clicked')} // ability to add handler
314
- />
315
- }
316
- ```
317
-
318
- , where:
319
-
320
- * **title** (required) `String|JSX.Element` - title that describes information hidden underneath.
321
- * **content** (required) `Function|String|Array<String>|JSX.Element` - content that will appear after click on the title.
322
- * **extendClassNames** (optional) `String|Array<String>` - ability to add own css classes to the component.
323
- * **onClick** (optional) `Function` - handler that will be called when the title is clicked.
324
-
325
- #### Extension points
326
-
327
- Extension points - places within the report UI that are available to extend with React components with the help of [html-reporter plugins](#html-reporter-plugins).
328
-
329
- Each extension point may pass specific props to the plugin components depending on the point. As some plugins may rely on specific placement and hence on such specific props, it is possible to restrict plugin components to specific extension points by specifing static property `point` on such plugin components:
330
-
331
- ```js
332
- class PluginComponent extends React.Component {
333
- static point = 'result';
334
- // ...
335
- }
336
- ```
337
-
338
- Currently, there are extension points:
339
- * `result` - allows to extend each test result; adds `resultId` and `testName` props to the plugin component;
340
- * `result_meta` - allows to extend meta information of each test result; adds `result` and `testName` props to the plugin component;
341
- * `menu-bar` - allows to extend menu bar.
342
- * `root` - allows to add floating items like modal or popup.
343
-
344
- An extension point may be extended by more than one component. In that case order of components application is determined by `plugins` config order. Each following component is applied to all previously composed components at the extension point.
345
-
346
- * **customScripts** (optional) `function[]` - allows to add any scripts on the report html-page. Script will be executed immediately on page render. It can be helpful for adding some metrics or own extra functionality.
347
-
348
- ```js
349
- customScripts: [
350
- function() {console.log('something')},
351
- () => {
352
- const div = document.createElement('div');
353
- div.innerHTML = 'hello';
354
- document.body.prepend(div);
355
- }
356
- ]
357
- ```
358
-
359
- * **yandexMetrika** (optional) `Object` - allows to add [yandex metrika](https://yandex.ru/support/metrica/index.html) to your report. The metrika can help you to get how developers interact with your report and what kind of problems they encounter at that. To start using it, you should create a counter first: see [how to create a counter](https://yandex.ru/support/metrica/general/creating-counter.html). And then in the Yandex.Metrica interface, go to the Settings section (on the Code snippet tab), click Copy and add the copied code to the **customScripts**-field.
360
-
361
- Nested fields:
362
-
363
- * **counterNumber** (optional) `Number` - uniq counter in yandex metrika, used in order to send goals achievement.
364
-
365
- Supported goals (js events), [more info about goals](https://yandex.ru/support/metrica/general/goals.html):
366
-
367
- * **ACCEPT_SCREENSHOT** - click on "Accept" button;
368
- * **ACCEPT_OPENED_SCREENSHOTS** - click on "Accept opened" button.
369
-
370
- Also there is ability to override plugin parameters by CLI options or environment variables
371
- (see [configparser](https://github.com/gemini-testing/configparser)).
372
- Use `html_reporter_` prefix for the environment variables and `--html-reporter-` for the cli options.
373
-
374
- For example you can override `path` option like so:
375
- ```bash
376
- $ html_reporter_path=custom/dir hermione path/to/mytest.js
377
- $ hermione path/to/mytest.js --html-reporter-path custom/dir
378
- ```
379
-
380
- Add plugin to your `hermione` config file:
381
-
382
- ```js
383
- module.exports = {
384
- // ...
385
- plugins: {
386
- 'html-reporter/hermione': {
387
- enabled: true,
388
- path: 'my/hermione-reports',
389
- defaultView: 'all',
390
- baseHost: 'test.com',
391
- errorPatterns: [
392
- 'Parameter .* must be a string',
393
- {
394
- name: 'Cannot read property of undefined',
395
- pattern: 'Cannot read property .* of undefined',
396
- hint: '<div>google it, i dont know how to fix it =(</div>'
397
- }
398
- ]
399
- }
400
- },
401
- //...
402
- }
403
- ```
404
-
405
- ## Data storage format
406
-
407
- How was described at the beginning (see [html-reporter](#html-reporter)) test result is saved to the [SQLite](https://www.sqlite.org/index.html) database.
408
-
409
- Why we use SQLite:
410
-
411
- * serverless, simple to set up and zero configuration is required;
412
- * cross-platform, runs on any operating system;
413
- * single-file, easy to reuse and share report;
414
- * faster than direct filesystem I/O;
415
- * compact and has full-featured SQL implementation.
416
-
417
- Files that will be created during test execution:
418
-
419
- * `sqlite.db` - Sqlite database with tests results
420
- * `data.js` - report's config
421
- * `databaseUrls.json` - absolute or relative URLs to Sqlite databases (`sqlite.db`) or/and URLs to other `databaseUrls.json` (see [merge-reports](#merge-reports))
422
-
423
- ## Additional commands
424
-
425
- Additional commands that are added to the hermione.
426
-
427
- ### gui
428
-
429
- Command that adds ability to effective work with screenshots.
430
-
431
- Example of usage:
432
- ```
433
- npx hermione gui
434
- ```
435
-
436
- ### remove-unused-screens
437
-
438
- Command that adds ability to remove all unused reference images. On first step it looks for screenshots for which there are no tests on the file system. On the second step it looks for screenshots that were not used in a successful test (the result of the tests is taken from the sqlite database). For the correct execution of the second step html-report should exist on the file system and contain the result of the tests. It means you should run tests locally or download report from CI.
439
-
440
- ```
441
- npx hermione remove-unused-screens --help
442
- ```
443
-
444
- shows the following:
445
- ```
446
- Usage: remove-unused-screens [options]
447
-
448
- remove screenshots which were not used when running tests
449
-
450
- Options:
451
-
452
- -p, --pattern <pattern> pattern for searching screenshots on the file system
453
- --skip-questions do not ask questions during execution (default values will be used)
454
- -h, --help output usage information
455
-
456
- Example of usage:
457
- Specify the folder in which all reference screenshots are located:
458
- npx hermione remove-unused-screens -p hermione-screens-folder
459
-
460
- Specify the mask by which all reference screenshots will be found:
461
- npx hermione remove-unused-screens -p 'screens/**/*.png'
462
-
463
- Specify few masks by which all reference screenshots will be found:
464
- npx hermione remove-unused-screens -p 'screens/**/chrome/*.png' -p 'screens/**/firefox/*.png'
465
-
466
- Don't ask me about anything and just delete unused reference screenshots:
467
- npx hermione remove-unused-screens -p 'hermione-screens-folder' --skip-questions
468
- ```
469
-
470
- ### merge-reports
471
-
472
- Command that adds ability to merge reports which are created after running the tests.
473
-
474
- #### When save format is js (default)
475
-
476
- Command takes paths to directories with reports.
477
- It merge "data.js" files into single file and move reports files to destination directory.
478
-
479
- Example of usage:
480
- ```
481
- npx hermione merge-reports src-report-1 src-report-2 -d dest-report
482
- ```
483
-
484
- #### When save format is sqlite
485
-
486
- Command takes paths to databases files or "databaseUrls.json" files from other html reports.
487
- It creates new html report at destination directory with common "databaseUrls.json"
488
- which will contain link to databases files or "databaseUrls.json" files from input parameters.
489
- Databases files will not be copied to destination directory.
490
-
491
- Example of usage:
492
- ```bash
493
- npx hermione merge-reports path-to-database.db path-to-databaseUrls.json -d dest-report --html-reporter-save-format sqlite
494
- ```
495
-
496
- ## Testing
497
-
498
- Run [mocha](http://mochajs.org) tests:
499
- ```bash
500
- npm run test-unit
501
- ```
502
-
503
- Run [eslint](http://eslint.org) codestyle verification
504
- ```bash
505
- npm run lint
506
- ```
507
-
508
- Run [hermione](https://github.com/gemini-testing/hermione) (integration) tests:
509
- ```bash
510
- npm run test-func
511
- ```
512
-
513
- Integration tests run on Chromium in headless mode.
514
-
515
- ## API
516
-
517
- Html-reporter adds to `hermione` object with its own API.
518
-
519
- **Properties of the `hermione.htmlReporter` object**
520
-
521
- Property name | Description
522
- -------------------------- | -------------
523
- `events` | Events list for subscription.
524
- `extraItems` | Items list which will be added to the menu bar.
525
- `metaInfoExtenders` | Items list which will be added to the meta info.
526
- `imagesSaver` | Interface to save image into user storage.
527
- `reportsSaver` | Interface to save sqlite database into user storage.
528
- `downloadDatabases` | Method to download all databases from `databaseUrls.json` file.
529
- `mergeDatabases` | Method to merge passed databases to passed report path.
530
- `getTestsTreeFromDatabase` | Method to get tests tree from passed database.
531
-
532
- **Available events which are triggered in the main process**
533
-
534
- Event | Description
535
- ------------------------- | -------------
536
- `DATABASE_CREATED` | Will be triggered after sqlite database is created. The handler accepts a database instance. The event is synchronous.
537
- `TEST_SCREENSHOTS_SAVED` | Will be triggered after test screenshots were saved. The handler accepts test id and screenshots info. The event is asynchronous, so your handler can return a promise.
538
- `REPORT_SAVED` | Will be triggered after all test files were saved. The event is asynchronous, so your handler can return a promise.
539
-
540
- ### events
541
-
542
- Example of a subscription to an event `DATABASE_CREATED` from another hermione-plugin in the main process:
543
-
544
- ```js
545
- module.exports = (hermione, opts) => {
546
- if (!opts.enabled || hermione.isWorker()) {
547
- return;
548
- }
549
-
550
- // `htmlreporter` field is guaranteed to be in the `hermione` object when `INIT` event is emitted
551
- hermione.on(hermione.events.INIT, () => {
552
- hermione.htmlReporter.on(hermione.htmlReporter.events.DATABASE_CREATED, (db) => {
553
- db.prepare(`CREATE TABLE IF NOT EXISTS test1 (foo TEXT, bar TEXT)`).run();
554
- });
555
- });
556
- };
557
- ```
558
-
559
- Example of a subscription to an event `TEST_SCREENSHOTS_SAVED`:
560
-
561
- ```js
562
- hermione.htmlReporter.on(hermione.htmlReporter.events.TEST_SCREENSHOTS_SAVED, async ({testId, attempt, imagesInfo}) => {
563
- console.log(`Screenshots for test "${testId}" (attempt #${attempt}) were saved:`, imagesInfo);
564
- /* Expected output:
565
- Screenshots for test "Feature Test.chrome-desktop" (attempt #0) were saved:
566
- [
567
- {
568
- stateName: 'plain',
569
- refImg: { path: '...', size: { width: 400, height: 200 } },
570
- status: 'fail',
571
- error: undefined,
572
- diffClusters: [...],
573
- expectedImg: { path: '...', size: { width: 400, height: 200 } }
574
- actualImg: { path: '...', size: { width: 400, height: 200 } }
575
- diffImg: { path: '...', size: { width: 400, height: 200 } }
576
- }
577
- ]
578
- */
579
- });
580
- ```
581
-
582
- Example of a subscription to an event `REPORT_SAVED`:
583
- ```js
584
- hermione.htmlReporter.on(hermione.htmlReporter.events.REPORT_SAVED, async ({reportPath}) => {
585
- await uploadDirToS3(reportPath);
586
- });
587
- ```
588
-
589
- ### addExtraItem
590
-
591
- Adds item to html report as link:
592
-
593
- ```js
594
- @param {String} text of link
595
- @param {String} url of link
596
-
597
- hermione.htmlReporter.addExtraItem('some-text', 'some-url')
598
- ```
599
-
600
- In this case url with link 'some-url' and text 'some-text' will be added to the menu bar.
601
-
602
- ### addMetaInfoExtender
603
-
604
- Extend meta-info of each test using passed data:
605
-
606
- ```js
607
- hermione.htmlReporter.addMetaInfoExtender(name, value);
608
- ```
609
-
610
- * **name** (required) `String` - name of meta info
611
- * **value** (required) `Function` - handler to which `data` (`Object` with `testName` field) and `extraItems` are passed
612
-
613
- Example:
614
- ```js
615
- hermione.htmlReporter.addMetaInfoExtender('foo', (data, extraItems) => {
616
- return data.testName + extraItems.platform;
617
- });
618
- ```
619
-
620
- In this case a line `suite full name: some-platform` will be added to the meta info of each test.
621
-
622
- ### externalStorage
623
-
624
- You can redefine native api for images or sqlite dbs saving and use your own storage.
625
-
626
- #### images
627
-
628
- Example:
629
- ```js
630
- const MyStorage = require('my-storage');
631
- const myStorage = new MyStorage();
632
-
633
- module.exports = (hermione, opts) => {
634
- hermione.on(hermione.events.INIT, async () => {
635
- hermione.htmlReporter.imagesSaver = {
636
- /**
637
- * Save image to your storage. Function can be asynchronous or synchronous. It have to return path or url of saved image.
638
- * @property {String} localFilePath – image path on your filesystem
639
- * @param {Object} options
640
- * @param {String} options.destPath – path to image in html-report
641
- * @param {String} options.reportDir - path to your html-report dir
642
- * @returns {String} path or url
643
- */
644
- saveImg: async (localFilePath, options) => {
645
- const {destPath, reportDir} = options;
646
- const imageUrl = await myStorage.save(localFilePath, destPath, reportDir)
647
- // ...
648
-
649
- return imageUrl;
650
- }
651
- }
652
- });
653
- };
654
- ```
655
-
656
- #### sqlite dbs
657
-
658
- Example:
659
- ```js
660
- const MyStorage = require('my-storage');
661
- const myStorage = new MyStorage();
662
-
663
- module.exports = (hermione, opts) => {
664
- hermione.on(hermione.events.INIT, async () => {
665
- hermione.htmlReporter.reportsSaver = {
666
- /**
667
- * Save sqlite db to your storage. Function can be asynchronous or synchronous. It have to return path or url of saved sqlite db.
668
- * @property {String} localFilePath – sqlite db path on your filesystem
669
- * @param {Object} options
670
- * @param {String} options.destPath – path to sqlite db in html-report
671
- * @param {String} options.reportDir - path to your html-report dir
672
- * @returns {String} path or url
673
- */
674
- saveReportData: async (localFilePath, options) => {
675
- const {destPath, reportDir} = options;
676
- const dbUrl = await myStorage.save(localFilePath, destPath, reportDir)
677
- // ...
678
-
679
- return dbUrl;
680
- }
681
- }
682
- });
683
- };
684
- ```
1
+ # html-reporter
2
+
3
+ Requires **[hermione](https://github.com/gemini-testing/hermione)@4x**.
4
+
5
+ Plugin for [hermione](https://github.com/gemini-testing/hermione) which is intended to aggregate the results of tests running into html report.
6
+
7
+ Test result is saved to the [SQLite](https://www.sqlite.org/index.html) database. It means that you can't open local report by 'file://' protocol.
8
+ Use gui mode - `npx hermione gui` or start a local server - `npx http-server -p 8080` at terminal from folder where report placed and open page `http://localhost:8080` at browser.
9
+
10
+ You can read more about hermione plugins [here](https://github.com/gemini-testing/hermione#plugins).
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ npm install html-reporter
16
+ ```
17
+
18
+ **:warning: Requires Hermione >=2.7.0**
19
+
20
+ ## Usage
21
+
22
+ Plugin has following configuration:
23
+
24
+ * **enabled** (optional) `Boolean` – enable/disable the plugin; by default plugin is enabled
25
+ * **path** (optional) `String` - path to directory for saving html report file; by
26
+ default html report will be saved into `hermione-report/index.html` inside current work
27
+ directory.
28
+ * **saveErrorDetails** (optional) `Boolean` – save/don't save error details to json-files (to error-details folder); `false` by default.
29
+
30
+ Any plugin of hermione can add error details when throwing an error. Details can help a user to debug a problem in a test. Html-reporter saves these details to a file with name `<hash of suite path>-<browser>_<retry number>_<timestamp>.json` in the error-details folder. Below a stacktrace html-reporter adds the section `Error details` with the link `title` pointing to the json-file. A user can open it in a browser or any IDE.
31
+
32
+ How to add error details when throwing an error from a plugin:
33
+ ```js
34
+ const err = new Error('some error');
35
+ err.details = {title: 'description, will be used as url title', data: {} | [] | 'some additional info'};
36
+ throw err;
37
+ ```
38
+
39
+ * **defaultView** (optional) `String` - default view mode. Available values are:
40
+
41
+ * `all` - show all tests. Default value.
42
+ * `failed` - show only failed tests.
43
+
44
+ * **diffMode** (optional) - `String` - default diff mode. Available values are:
45
+
46
+ * `3-up` - show all images (expected, actual, diff) in column. Default value;
47
+ * `3-up-scaled` - show all images in row (fit into page width);
48
+ * `only-diff` - show only diff image;
49
+ * `switch` - mode with ability to switch between expected and actual images (use click on mouse in images field to switch);
50
+ * `swipe` - mode with ability to move divider between expected and actual images;
51
+ * `onion-skin` - mode with ability to change the transparency of actual image.
52
+
53
+ * **baseHost** (optional) - `String` - it changes original host for view in the browser; by default original host does not change
54
+ * **errorPatterns** (optional) - `Array` - error message patterns are used:
55
+
56
+ * to show more understandable information about matched error;
57
+ * in 'Group by' mode with selected 'error' key.
58
+
59
+ Array elements must be one of the types:
60
+
61
+ * `Object` with required fields *name*, *pattern* and optional field *hint* - {*name*: `String`, *pattern*: `String`, *hint*: `String`};
62
+ * `String` which will be interpret as *name* and *pattern*.
63
+
64
+ When one of error patterns are matched on error message then:
65
+
66
+ * *name* of error pattern will be displayed as title of error message and original error message will be hidden under details;
67
+ * *hint* of error pattern will be displayed after error *stack* field. Can be specified as html string. For example, `<div>some-useful-hint</div>`.
68
+
69
+ In 'Group by' mode with selected 'error' key test will be associated with group if test error matches on group error pattern. New group will be created if test cannot be associated with existing groups.
70
+
71
+ * **metaInfoBaseUrls** (optional) `Object` - base paths for making link from Meta-info values. Object option must be Meta-info's key and value must be `String`. For example, {'file': 'base/path'}.
72
+ * **saveFormat** (**DEPRECATED**, optional) `String` - allows to specify the format, in which the results will be saved. Available values are:
73
+ * `sqlite` - save tests results to Sqlite database. Default value.
74
+ * **customGui** (optional) `Object` – allows to specify custom controls for gui-mode and define actions for them. `{}` is default value. Ordinarily custom controls should be split by sections depending on the purposes of the controls. At least one section should be specified.
75
+ The structure of the custom-gui object:
76
+ ```js
77
+ customGui: {
78
+ 'choose-any-name-for-the-section-1': [{an object describing a group of controls}, ...],
79
+ 'choose-any-name-for-the-section-2': [{an object describing a group of controls}, ...]
80
+ }
81
+ ```
82
+ The keys of customGui-object are any strings describing sections of controls. It is upon a user to choose appropriate names for the sections.
83
+ A value of a key should be an array that holds a set of objects describing groups of controls.
84
+
85
+ #### customGui-group-object
86
+
87
+ An object that describes one group of controls has the following structure:
88
+ ```js
89
+ {
90
+ type: 'specify-type-of-the-controls',
91
+ controls: [
92
+ {
93
+ label: 'specify-label-for-the-control',
94
+ value: 'specify-value-of-the-control'
95
+ },
96
+ {
97
+ ...
98
+ }
99
+ ],
100
+ initialize: async ({hermione, ctx}) => {
101
+ // here goes your code
102
+ // returned value will be ignored
103
+ },
104
+ action: async ({hermione, ctx, control}) => {
105
+ // here goes your code
106
+ // returned value will be ignored
107
+ }
108
+ }
109
+ ```
110
+
111
+ * **type** (required) `String` – defines the type of controls. Available values are: `button` and `radiobutton`.
112
+
113
+ * **controls** (required) `Array` – array of objects that describe controls. Each object should have string fields `label` and `value`. `Label` defines the caption of the control, and `value` – its value.
114
+
115
+ * **initialize** (optional) – an async function to be executed at server-side at gui-mode start. Input parameter of this function is an object `{hermione, ctx}`, where `hermione` is an instance of hermione and `ctx` is the reference to the whole [object](#customGui-group-object) the initialize-function is being run for. A value that initialize-function returns will be ignored.
116
+
117
+ * **action** (required) – an async function to be executed at server-side when a user clicks a control. Input parameter of this function is an object `{hermione, ctx, control}`, where `hermione` is an instance of hermione, `ctx` is the reference to the whole [object](#customGui-group-object) the action-function is being run for, and `control` points to the control the user clicked. A value that action-function returns will be ignored.
118
+
119
+ #### Example: how to add radiobuttons for base url switching in gui-mode
120
+ ```js
121
+ customGui: {
122
+ 'some-meaningful-name-of-section': [
123
+ {
124
+ type: 'radiobutton',
125
+ controls: [
126
+ {
127
+ label: 'Dev',
128
+ value: 'http://localhost/development/'
129
+ },
130
+ {
131
+ label: 'Prod',
132
+ value: 'http://localhost/production/'
133
+ }
134
+ ],
135
+ initialize: async ({hermione, ctx}) => {
136
+ const {config} = hermione;
137
+ const browserIds = config.getBrowserIds();
138
+
139
+ if (browserIds.length) {
140
+ const {baseUrl} = config.forBrowser(browserIds[0]);
141
+
142
+ ctx.controls.forEach((control) => {
143
+ control.active = (baseUrl === control.value);
144
+ });
145
+ }
146
+ },
147
+ action: async ({hermione, ctx, control}) => {
148
+ const {config} = hermione;
149
+
150
+ config
151
+ .getBrowserIds()
152
+ .forEach((browserId) => {
153
+ config.forBrowser(browserId).baseUrl = control.value;
154
+ });
155
+ }
156
+ }
157
+ ]
158
+ }
159
+ ```
160
+
161
+ * **pluginsEnabled** (optional) `Boolean` - enable html-reporter plugins; `false` by default
162
+ * **plugins** (optional) `Array` of html-reporter plugin descriptions; `[]` by default. Allows to extend report with custom UI components (both static and gui-mode) and custom server routes (gui-mode only).
163
+
164
+ The structure of the plugin descriptions config:
165
+ ```js
166
+ plugins: [
167
+ {
168
+ name: 'plugin-name',
169
+ component: 'PluginReactComponentName',
170
+ point: 'extension-point-name',
171
+ position: 'wrap',
172
+ config: { param: 'value'}
173
+ },
174
+ {
175
+ name: 'plugin-name',
176
+ component: 'AnotherPluginReactComponentName',
177
+ point: 'extension-point-name',
178
+ position: 'before'
179
+ },
180
+ // ...
181
+ ]
182
+ ```
183
+
184
+ , where:
185
+
186
+ * **name** (required) `String` - a name of an html-reporter plugin _package_. It expected to be `require`-resolvable from your project.
187
+ * **component** (optional) `String` - React component name from the plugin.
188
+ * **point** (optional) `String` - html-reporter's extension point name. Sets specific place within the html-reporter UI where to place the specified component. [More on extension points](#extension-points).
189
+ * **position** (optional) `String` - specifies the way the component is going to be applied to the html-reporter UI extension point. Possible values are:
190
+ * `wrap` - to wrap the extension point UI
191
+ * `before` - to place the component before the extension point
192
+ * `after` - to place the component after the extension point
193
+ * **config** (optional) `Object` - plugin configuration
194
+
195
+ A plugin with only **name** specified may be used to redefine existing gui-server middleware.
196
+
197
+ A plugin may define more than one component. Each component may be applied to several extension points and/or several times to the same point (with separate config entries). The order of the components application is determined by the config order.
198
+
199
+ #### html-reporter plugins
200
+
201
+ _[Example plugins](https://github.com/gemini-testing/html-reporter/blob//master/./test/func/html-reporter-plugins) are available in functional tests._
202
+
203
+ An html-reporter plugin is an object with some set of React components on its keys and an optional key `reducers` with an array of redux reducers to manage the components state (which are later combined by [`reduce-reducers`](https://github.com/redux-utilities/reduce-reducers)).
204
+
205
+ An html-reporter plugin expected to have the following module files in the root of the package: `plugin.js` and/or `middleware.js`.
206
+
207
+ ##### plugin.js
208
+
209
+ Optional module. The file expected to export an object (or set of named exports) or a function returning such an object or an array with some specific structure.
210
+
211
+ It is possible to reuse dependencies of html-reporter within plugins (React, Redux, etc). To do so an array should be exported from the module with the list of needed deps followed by a function with the corresponding deps passed to it and returning the plugin itself:
212
+
213
+ ```js
214
+ import 'plugin-styles.css';
215
+
216
+ export default ['react', function(React, options) {
217
+ class PluginComponent extends React.Component {
218
+ // Component implementation
219
+ }
220
+
221
+ return {
222
+ PluginComponent,
223
+ reducers: []
224
+ };
225
+ }];
226
+ ```
227
+
228
+ Plugin styles are expected to be loaded with the `plugin.js` and the file is expected to be a single bundle.
229
+
230
+ Exported value of the `plugin.js` should be passed to the `__hermione_html_reporter_register_plugin__`. This could be achieved by either configuring your webpack build to produce corresponding `jsonp` library:
231
+
232
+ ```js
233
+ // ...
234
+ output: {
235
+ filename: 'plugin.js',
236
+ path: __dirname,
237
+ library: '__hermione_html_reporter_register_plugin__',
238
+ libraryTarget: 'jsonp'
239
+ },
240
+ // ...
241
+ ```
242
+
243
+ or, by passing it explicitly:
244
+
245
+ ```js
246
+ __hermione_html_reporter_register_plugin__(['react', function(React, options) {
247
+ /* ... */
248
+ return {PluginComponent};
249
+ }]);
250
+ ```
251
+
252
+ ##### middleware.js
253
+
254
+ Optional module. Exports a function accepting an **express** `Router`. The plugin routes are expected to be attached to the router. The router are then attached on the `/plugin-routes/:pluginName/` path:
255
+
256
+ ```js
257
+ module.exports = function(pluginRouter) {
258
+ pluginRouter.get('/plugin-route', function(req, res) {
259
+ // route implementation
260
+ });
261
+ };
262
+ ```
263
+
264
+ The routes then can be called from the plugin React components defined in the `plugin.js`. For convenience the plugin name is always passed with options when function- or array-returning form is used to export plugin as the function options property `pluginName`:
265
+
266
+ ```js
267
+ export default ['react', 'axios', function(React, axios, {pluginName, pluginConfig, actions, actionNames, selectors}) {
268
+ class PluginComponent extends React.Component {
269
+ // ... somewhere inside the component ...
270
+ const result = await axios.get(`/plugin-routes/${pluginName}/plugin-route`);
271
+ }
272
+
273
+ return {
274
+ PluginComponent,
275
+ reducers: []
276
+ };
277
+ }
278
+ ```
279
+
280
+ In the example you can also see another convenient properties:
281
+ - `pluginName` - plugin name;
282
+ - `pluginConfig` - plugin configuration;
283
+ - `actions` - the html-reporter **Redux** actions;
284
+ - `actionNames` - the html-reporter action names, that used in **Redux** actions. To be able to subscribe on html-reporter events;
285
+ - `selectors` - the memoized html-reporter selectors which created using **reselect** library.
286
+
287
+
288
+ Available dependencies:
289
+ - `react`
290
+ - `redux`
291
+ - `react-redux`
292
+ - `lodash`
293
+ - `prop-types`
294
+ - `classnames`
295
+ - `semantic-ui-react`
296
+ - `react-markdown`
297
+ - `reduce-reducers`
298
+ - `immer`
299
+ - `reselect`
300
+ - `axios`
301
+
302
+ Available components:
303
+ - `components`
304
+ - `<Details />` - component which allows users to toggle the display of content.
305
+ Example of usage:
306
+ ```js
307
+ // ... inside your react component
308
+ render() {
309
+ return <Details
310
+ title='Some title'
311
+ content='Some content' // content that will appear when you click on the title
312
+ extendClassNames='some_class_name' // ability to add own css-classes to component
313
+ onClick={() => console.log('clicked')} // ability to add handler
314
+ />
315
+ }
316
+ ```
317
+
318
+ , where:
319
+
320
+ * **title** (required) `String|JSX.Element` - title that describes information hidden underneath.
321
+ * **content** (required) `Function|String|Array<String>|JSX.Element` - content that will appear after click on the title.
322
+ * **extendClassNames** (optional) `String|Array<String>` - ability to add own css classes to the component.
323
+ * **onClick** (optional) `Function` - handler that will be called when the title is clicked.
324
+
325
+ #### Extension points
326
+
327
+ Extension points - places within the report UI that are available to extend with React components with the help of [html-reporter plugins](#html-reporter-plugins).
328
+
329
+ Each extension point may pass specific props to the plugin components depending on the point. As some plugins may rely on specific placement and hence on such specific props, it is possible to restrict plugin components to specific extension points by specifing static property `point` on such plugin components:
330
+
331
+ ```js
332
+ class PluginComponent extends React.Component {
333
+ static point = 'result';
334
+ // ...
335
+ }
336
+ ```
337
+
338
+ Currently, there are extension points:
339
+ * `result` - allows to extend each test result; adds `resultId` and `testName` props to the plugin component;
340
+ * `result_meta` - allows to extend meta information of each test result; adds `result` and `testName` props to the plugin component;
341
+ * `menu-bar` - allows to extend menu bar.
342
+ * `root` - allows to add floating items like modal or popup.
343
+
344
+ An extension point may be extended by more than one component. In that case order of components application is determined by `plugins` config order. Each following component is applied to all previously composed components at the extension point.
345
+
346
+ * **customScripts** (optional) `function[]` - allows to add any scripts on the report html-page. Script will be executed immediately on page render. It can be helpful for adding some metrics or own extra functionality.
347
+
348
+ ```js
349
+ customScripts: [
350
+ function() {console.log('something')},
351
+ () => {
352
+ const div = document.createElement('div');
353
+ div.innerHTML = 'hello';
354
+ document.body.prepend(div);
355
+ }
356
+ ]
357
+ ```
358
+
359
+ * **yandexMetrika** (optional) `Object` - allows to add [yandex metrika](https://yandex.ru/support/metrica/index.html) to your report. The metrika can help you to get how developers interact with your report and what kind of problems they encounter at that. To start using it, you should create a counter first: see [how to create a counter](https://yandex.ru/support/metrica/general/creating-counter.html). And then in the Yandex.Metrica interface, go to the Settings section (on the Code snippet tab), click Copy and add the copied code to the **customScripts**-field.
360
+
361
+ Nested fields:
362
+
363
+ * **counterNumber** (optional) `Number` - uniq counter in yandex metrika, used in order to send goals achievement.
364
+
365
+ Supported goals (js events), [more info about goals](https://yandex.ru/support/metrica/general/goals.html):
366
+
367
+ * **ACCEPT_SCREENSHOT** - click on "Accept" button;
368
+ * **ACCEPT_OPENED_SCREENSHOTS** - click on "Accept opened" button.
369
+
370
+ Also there is ability to override plugin parameters by CLI options or environment variables
371
+ (see [configparser](https://github.com/gemini-testing/configparser)).
372
+ Use `html_reporter_` prefix for the environment variables and `--html-reporter-` for the cli options.
373
+
374
+ For example you can override `path` option like so:
375
+ ```bash
376
+ $ html_reporter_path=custom/dir hermione path/to/mytest.js
377
+ $ hermione path/to/mytest.js --html-reporter-path custom/dir
378
+ ```
379
+
380
+ Add plugin to your `hermione` config file:
381
+
382
+ ```js
383
+ module.exports = {
384
+ // ...
385
+ plugins: {
386
+ 'html-reporter/hermione': {
387
+ enabled: true,
388
+ path: 'my/hermione-reports',
389
+ defaultView: 'all',
390
+ baseHost: 'test.com',
391
+ errorPatterns: [
392
+ 'Parameter .* must be a string',
393
+ {
394
+ name: 'Cannot read property of undefined',
395
+ pattern: 'Cannot read property .* of undefined',
396
+ hint: '<div>google it, i dont know how to fix it =(</div>'
397
+ }
398
+ ]
399
+ }
400
+ },
401
+ //...
402
+ }
403
+ ```
404
+
405
+ ## Data storage format
406
+
407
+ How was described at the beginning (see [html-reporter](#html-reporter)) test result is saved to the [SQLite](https://www.sqlite.org/index.html) database.
408
+
409
+ Why we use SQLite:
410
+
411
+ * serverless, simple to set up and zero configuration is required;
412
+ * cross-platform, runs on any operating system;
413
+ * single-file, easy to reuse and share report;
414
+ * faster than direct filesystem I/O;
415
+ * compact and has full-featured SQL implementation.
416
+
417
+ Files that will be created during test execution:
418
+
419
+ * `sqlite.db` - Sqlite database with tests results
420
+ * `data.js` - report's config
421
+ * `databaseUrls.json` - absolute or relative URLs to Sqlite databases (`sqlite.db`) or/and URLs to other `databaseUrls.json` (see [merge-reports](#merge-reports))
422
+
423
+ ## Additional commands
424
+
425
+ Additional commands that are added to the hermione.
426
+
427
+ ### gui
428
+
429
+ Command that adds ability to effective work with screenshots.
430
+
431
+ Example of usage:
432
+ ```
433
+ npx hermione gui
434
+ ```
435
+
436
+ ### remove-unused-screens
437
+
438
+ Command that adds ability to remove all unused reference images. On first step it looks for screenshots for which there are no tests on the file system. On the second step it looks for screenshots that were not used in a successful test (the result of the tests is taken from the sqlite database). For the correct execution of the second step html-report should exist on the file system and contain the result of the tests. It means you should run tests locally or download report from CI.
439
+
440
+ ```
441
+ npx hermione remove-unused-screens --help
442
+ ```
443
+
444
+ shows the following:
445
+ ```
446
+ Usage: remove-unused-screens [options]
447
+
448
+ remove screenshots which were not used when running tests
449
+
450
+ Options:
451
+
452
+ -p, --pattern <pattern> pattern for searching screenshots on the file system
453
+ --skip-questions do not ask questions during execution (default values will be used)
454
+ -h, --help output usage information
455
+
456
+ Example of usage:
457
+ Specify the folder in which all reference screenshots are located:
458
+ npx hermione remove-unused-screens -p hermione-screens-folder
459
+
460
+ Specify the mask by which all reference screenshots will be found:
461
+ npx hermione remove-unused-screens -p 'screens/**/*.png'
462
+
463
+ Specify few masks by which all reference screenshots will be found:
464
+ npx hermione remove-unused-screens -p 'screens/**/chrome/*.png' -p 'screens/**/firefox/*.png'
465
+
466
+ Don't ask me about anything and just delete unused reference screenshots:
467
+ npx hermione remove-unused-screens -p 'hermione-screens-folder' --skip-questions
468
+ ```
469
+
470
+ ### merge-reports
471
+
472
+ Command that adds ability to merge reports which are created after running the tests.
473
+
474
+ #### When save format is js (default)
475
+
476
+ Command takes paths to directories with reports.
477
+ It merge "data.js" files into single file and move reports files to destination directory.
478
+
479
+ Example of usage:
480
+ ```
481
+ npx hermione merge-reports src-report-1 src-report-2 -d dest-report
482
+ ```
483
+
484
+ #### When save format is sqlite
485
+
486
+ Command takes paths to databases files or "databaseUrls.json" files from other html reports.
487
+ It creates new html report at destination directory with common "databaseUrls.json"
488
+ which will contain link to databases files or "databaseUrls.json" files from input parameters.
489
+ Databases files will not be copied to destination directory.
490
+
491
+ Example of usage:
492
+ ```bash
493
+ npx hermione merge-reports path-to-database.db path-to-databaseUrls.json -d dest-report --html-reporter-save-format sqlite
494
+ ```
495
+
496
+ ## Testing
497
+
498
+ Run [mocha](http://mochajs.org) tests:
499
+ ```bash
500
+ npm run test-unit
501
+ ```
502
+
503
+ Run [eslint](http://eslint.org) codestyle verification
504
+ ```bash
505
+ npm run lint
506
+ ```
507
+
508
+ Run [hermione](https://github.com/gemini-testing/hermione) (integration) tests:
509
+ ```bash
510
+ npm run test-func
511
+ ```
512
+
513
+ Integration tests run on Chromium in headless mode.
514
+
515
+ ## API
516
+
517
+ Html-reporter adds to `hermione` object with its own API.
518
+
519
+ **Properties of the `hermione.htmlReporter` object**
520
+
521
+ Property name | Description
522
+ -------------------------- | -------------
523
+ `events` | Events list for subscription.
524
+ `extraItems` | Items list which will be added to the menu bar.
525
+ `metaInfoExtenders` | Items list which will be added to the meta info.
526
+ `imagesSaver` | Interface to save image into user storage.
527
+ `reportsSaver` | Interface to save sqlite database into user storage.
528
+ `downloadDatabases` | Method to download all databases from `databaseUrls.json` file.
529
+ `mergeDatabases` | Method to merge passed databases to passed report path.
530
+ `getTestsTreeFromDatabase` | Method to get tests tree from passed database.
531
+
532
+ **Available events which are triggered in the main process**
533
+
534
+ Event | Description
535
+ ------------------------- | -------------
536
+ `DATABASE_CREATED` | Will be triggered after sqlite database is created. The handler accepts a database instance. The event is synchronous.
537
+ `TEST_SCREENSHOTS_SAVED` | Will be triggered after test screenshots were saved. The handler accepts test id and screenshots info. The event is asynchronous, so your handler can return a promise.
538
+ `REPORT_SAVED` | Will be triggered after all test files were saved. The event is asynchronous, so your handler can return a promise.
539
+
540
+ ### events
541
+
542
+ Example of a subscription to an event `DATABASE_CREATED` from another hermione-plugin in the main process:
543
+
544
+ ```js
545
+ module.exports = (hermione, opts) => {
546
+ if (!opts.enabled || hermione.isWorker()) {
547
+ return;
548
+ }
549
+
550
+ // `htmlreporter` field is guaranteed to be in the `hermione` object when `INIT` event is emitted
551
+ hermione.on(hermione.events.INIT, () => {
552
+ hermione.htmlReporter.on(hermione.htmlReporter.events.DATABASE_CREATED, (db) => {
553
+ db.prepare(`CREATE TABLE IF NOT EXISTS test1 (foo TEXT, bar TEXT)`).run();
554
+ });
555
+ });
556
+ };
557
+ ```
558
+
559
+ Example of a subscription to an event `TEST_SCREENSHOTS_SAVED`:
560
+
561
+ ```js
562
+ hermione.htmlReporter.on(hermione.htmlReporter.events.TEST_SCREENSHOTS_SAVED, async ({testId, attempt, imagesInfo}) => {
563
+ console.log(`Screenshots for test "${testId}" (attempt #${attempt}) were saved:`, imagesInfo);
564
+ /* Expected output:
565
+ Screenshots for test "Feature Test.chrome-desktop" (attempt #0) were saved:
566
+ [
567
+ {
568
+ stateName: 'plain',
569
+ refImg: { path: '...', size: { width: 400, height: 200 } },
570
+ status: 'fail',
571
+ error: undefined,
572
+ diffClusters: [...],
573
+ expectedImg: { path: '...', size: { width: 400, height: 200 } }
574
+ actualImg: { path: '...', size: { width: 400, height: 200 } }
575
+ diffImg: { path: '...', size: { width: 400, height: 200 } }
576
+ }
577
+ ]
578
+ */
579
+ });
580
+ ```
581
+
582
+ Example of a subscription to an event `REPORT_SAVED`:
583
+ ```js
584
+ hermione.htmlReporter.on(hermione.htmlReporter.events.REPORT_SAVED, async ({reportPath}) => {
585
+ await uploadDirToS3(reportPath);
586
+ });
587
+ ```
588
+
589
+ ### addExtraItem
590
+
591
+ Adds item to html report as link:
592
+
593
+ ```js
594
+ @param {String} text of link
595
+ @param {String} url of link
596
+
597
+ hermione.htmlReporter.addExtraItem('some-text', 'some-url')
598
+ ```
599
+
600
+ In this case url with link 'some-url' and text 'some-text' will be added to the menu bar.
601
+
602
+ ### addMetaInfoExtender
603
+
604
+ Extend meta-info of each test using passed data:
605
+
606
+ ```js
607
+ hermione.htmlReporter.addMetaInfoExtender(name, value);
608
+ ```
609
+
610
+ * **name** (required) `String` - name of meta info
611
+ * **value** (required) `Function` - handler to which `data` (`Object` with `testName` field) and `extraItems` are passed
612
+
613
+ Example:
614
+ ```js
615
+ hermione.htmlReporter.addMetaInfoExtender('foo', (data, extraItems) => {
616
+ return data.testName + extraItems.platform;
617
+ });
618
+ ```
619
+
620
+ In this case a line `suite full name: some-platform` will be added to the meta info of each test.
621
+
622
+ ### externalStorage
623
+
624
+ You can redefine native api for images or sqlite dbs saving and use your own storage.
625
+
626
+ #### images
627
+
628
+ Example:
629
+ ```js
630
+ const MyStorage = require('my-storage');
631
+ const myStorage = new MyStorage();
632
+
633
+ module.exports = (hermione, opts) => {
634
+ hermione.on(hermione.events.INIT, async () => {
635
+ hermione.htmlReporter.imagesSaver = {
636
+ /**
637
+ * Save image to your storage. Function can be asynchronous or synchronous. It have to return path or url of saved image.
638
+ * @property {String} localFilePath – image path on your filesystem
639
+ * @param {Object} options
640
+ * @param {String} options.destPath – path to image in html-report
641
+ * @param {String} options.reportDir - path to your html-report dir
642
+ * @returns {String} path or url
643
+ */
644
+ saveImg: async (localFilePath, options) => {
645
+ const {destPath, reportDir} = options;
646
+ const imageUrl = await myStorage.save(localFilePath, destPath, reportDir)
647
+ // ...
648
+
649
+ return imageUrl;
650
+ }
651
+ }
652
+ });
653
+ };
654
+ ```
655
+
656
+ #### sqlite dbs
657
+
658
+ Example:
659
+ ```js
660
+ const MyStorage = require('my-storage');
661
+ const myStorage = new MyStorage();
662
+
663
+ module.exports = (hermione, opts) => {
664
+ hermione.on(hermione.events.INIT, async () => {
665
+ hermione.htmlReporter.reportsSaver = {
666
+ /**
667
+ * Save sqlite db to your storage. Function can be asynchronous or synchronous. It have to return path or url of saved sqlite db.
668
+ * @property {String} localFilePath – sqlite db path on your filesystem
669
+ * @param {Object} options
670
+ * @param {String} options.destPath – path to sqlite db in html-report
671
+ * @param {String} options.reportDir - path to your html-report dir
672
+ * @returns {String} path or url
673
+ */
674
+ saveReportData: async (localFilePath, options) => {
675
+ const {destPath, reportDir} = options;
676
+ const dbUrl = await myStorage.save(localFilePath, destPath, reportDir)
677
+ // ...
678
+
679
+ return dbUrl;
680
+ }
681
+ }
682
+ });
683
+ };
684
+ ```