html-reporter 7.3.0 → 7.6.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/CHANGELOG.md CHANGED
@@ -2,6 +2,49 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ <a name="7.6.0"></a>
6
+ # [7.6.0](https://github.com/gemini-testing/html-reporter/compare/v7.5.0...v7.6.0) (2021-11-02)
7
+
8
+
9
+ ### Features
10
+
11
+ * added 'root' extension-point ([b7e571a](https://github.com/gemini-testing/html-reporter/commit/b7e571a))
12
+
13
+
14
+
15
+ <a name="7.5.0"></a>
16
+ # [7.5.0](https://github.com/gemini-testing/html-reporter/compare/v7.4.0...v7.5.0) (2021-10-25)
17
+
18
+
19
+ ### Features
20
+
21
+ * add an ability to stop tests directly from GUI ([686e50a](https://github.com/gemini-testing/html-reporter/commit/686e50a))
22
+
23
+
24
+
25
+ <a name="7.4.0"></a>
26
+ # [7.4.0](https://github.com/gemini-testing/html-reporter/compare/v7.3.1...v7.4.0) (2021-10-25)
27
+
28
+
29
+ ### Features
30
+
31
+ * merge all existing tables inside sqlite database ([#404](https://github.com/gemini-testing/html-reporter/issues/404)) ([5c727fd](https://github.com/gemini-testing/html-reporter/commit/5c727fd))
32
+ * **gui:** add ability to use db connection on client side ([#402](https://github.com/gemini-testing/html-reporter/issues/402)) ([8f445e3](https://github.com/gemini-testing/html-reporter/commit/8f445e3))
33
+ * add "result_meta" extension point for html-reporter plugins ([#401](https://github.com/gemini-testing/html-reporter/issues/401)) ([fb52a0a](https://github.com/gemini-testing/html-reporter/commit/fb52a0a))
34
+ * add API with ability to access the database from other plugins ([#400](https://github.com/gemini-testing/html-reporter/issues/400)) ([0e9e97c](https://github.com/gemini-testing/html-reporter/commit/0e9e97c))
35
+
36
+
37
+
38
+ <a name="7.3.1"></a>
39
+ ## [7.3.1](https://github.com/gemini-testing/html-reporter/compare/v7.3.0...v7.3.1) (2021-09-20)
40
+
41
+
42
+ ### Bug Fixes
43
+
44
+ * correct calculation of suites state ([#398](https://github.com/gemini-testing/html-reporter/issues/398)) ([465e293](https://github.com/gemini-testing/html-reporter/commit/465e293))
45
+
46
+
47
+
5
48
  <a name="7.3.0"></a>
6
49
  # [7.3.0](https://github.com/gemini-testing/html-reporter/compare/v7.2.0...v7.3.0) (2021-09-16)
7
50
 
package/README.md CHANGED
@@ -288,8 +288,10 @@ directory.
288
288
  ```
289
289
 
290
290
  Currently, there are extension points:
291
- * `result` - allows to extend each test result; adds `resultId` and `testName` props to the plugin component.
291
+ * `result` - allows to extend each test result; adds `resultId` and `testName` props to the plugin component;
292
+ * `result_meta` - allows to extend meta information of each test result; adds `result` and `testName` props to the plugin component;
292
293
  * `menu-bar` - allows to extend menu bar.
294
+ * `root` - allows to add floating items like modal or popup.
293
295
 
294
296
  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.
295
297
 
@@ -372,7 +374,7 @@ Files that will be created during test execution:
372
374
 
373
375
  ## Additional commands
374
376
 
375
- Additional commands that are added to the tool for which this plugin is connected.
377
+ Additional commands that are added to the hermione.
376
378
 
377
379
  ### gui
378
380
 
@@ -428,9 +430,44 @@ npm run test-func
428
430
 
429
431
  Integration tests run on Chromium in headless mode.
430
432
 
431
- ## Api
433
+ ## API
432
434
 
433
- Html-reporter adds to your tool object with api:
435
+ Html-reporter adds to `hermione` object with its own API.
436
+
437
+ **Properties of the `hermione.htmlReporter` object**
438
+
439
+ Property name | Description
440
+ ------------------------- | -------------
441
+ `events` | Events list for subscription.
442
+ `extraItems` | Items list which will be added to the menu bar.
443
+ `metaInfoExtenders` | Items list which will be added to the meta info.
444
+ `imagesSaver` | Interface to save image into user storage.
445
+ `reportsSaver` | Interface to save sqlite database into user storage.
446
+
447
+ **Available events which are triggered in the main process**
448
+
449
+ Event | Description
450
+ ------------------------- | -------------
451
+ `DATABASE_CREATED` | Will be triggered after sqlite database is created. The handler accepts a database instance. The event is synchronous.
452
+
453
+ ### events
454
+
455
+ Example of a subscription to an event `DATABASE_CREATED` from another hermione-plugin in the main process:
456
+
457
+ ```js
458
+ module.exports = (hermione, opts) => {
459
+ if (!opts.enabled || hermione.isWorker()) {
460
+ return;
461
+ }
462
+
463
+ // `htmlreporter` field is guaranteed to be in the `hermione` object when `INIT` event is emitted
464
+ hermione.on(hermione.events.INIT, () => {
465
+ hermione.htmlReporter.on(hermione.htmlReporter.events.DATABASE_CREATED, (db) => {
466
+ db.prepare(`CREATE TABLE IF NOT EXISTS test1 (foo TEXT, bar TEXT)`).run();
467
+ });
468
+ });
469
+ };
470
+ ```
434
471
 
435
472
  ### addExtraItem
436
473
 
@@ -440,7 +477,7 @@ Adds item to html report as link:
440
477
  @param {String} text of link
441
478
  @param {String} url of link
442
479
 
443
- tool.htmlReporter.addExtraItem('some-text', 'some-url')
480
+ hermione.htmlReporter.addExtraItem('some-text', 'some-url')
444
481
  ```
445
482
 
446
483
  In this case url with link 'some-url' and text 'some-text' will be added to the menu bar.
@@ -450,7 +487,7 @@ In this case url with link 'some-url' and text 'some-text' will be added to the
450
487
  Extend meta-info of each test using passed data:
451
488
 
452
489
  ```js
453
- tool.htmlReporter.addMetaInfoExtender(name, value);
490
+ hermione.htmlReporter.addMetaInfoExtender(name, value);
454
491
  ```
455
492
 
456
493
  * **name** (required) `String` - name of meta info
@@ -458,14 +495,13 @@ tool.htmlReporter.addMetaInfoExtender(name, value);
458
495
 
459
496
  Example:
460
497
  ```js
461
- tool.htmlReporter.addMetaInfoExtender('foo', (data, extraItems) => {
498
+ hermione.htmlReporter.addMetaInfoExtender('foo', (data, extraItems) => {
462
499
  return data.testName + extraItems.platform;
463
500
  });
464
501
  ```
465
502
 
466
503
  In this case a line `suite full name: some-platform` will be added to the meta info of each test.
467
504
 
468
-
469
505
  ### externalStorage
470
506
 
471
507
  You can redefine native api for images or sqlite dbs saving and use your own storage.
@@ -83,23 +83,22 @@ function createTableQuery(tableName, columns) {
83
83
  return `CREATE TABLE IF NOT EXISTS ${tableName} (${formattedColumns})`;
84
84
  }
85
85
 
86
- exports.mergeTablesQueries = (dbPaths) => {
87
- const tablesToMerge = [
88
- DB_SUITES_TABLE_NAME
89
- ];
90
- const mkMergeQuery = (table) => `INSERT OR IGNORE INTO ${table} SELECT * FROM attached.${table}`;
91
- const queries = [].concat(
92
- `PRAGMA page_size = ${DB_MAX_AVAILABLE_PAGE_SIZE}`,
93
- exports.createTablesQuery(),
94
- );
86
+ exports.mergeTables = ({db, dbPaths, getExistingTables = () => {}}) => {
87
+ db.prepare(`PRAGMA page_size = ${DB_MAX_AVAILABLE_PAGE_SIZE}`).run();
95
88
 
96
89
  for (const dbPath of dbPaths) {
97
- queries.push(`ATTACH '${dbPath}' AS attached`);
98
- queries.push.apply(queries, tablesToMerge.map(mkMergeQuery));
99
- queries.push('DETACH attached');
100
- }
90
+ db.prepare(`ATTACH '${dbPath}' AS attached`).run();
91
+
92
+ const getTablesStatement = db.prepare(`SELECT name FROM attached.sqlite_master WHERE type='table'`);
93
+ const tables = getExistingTables(getTablesStatement);
101
94
 
102
- return queries;
95
+ for (const tableName of tables) {
96
+ db.prepare(`CREATE TABLE IF NOT EXISTS ${tableName} AS SELECT * FROM attached.${tableName} LIMIT 0`).run();
97
+ db.prepare(`INSERT OR IGNORE INTO ${tableName} SELECT * FROM attached.${tableName}`).run();
98
+ }
99
+
100
+ db.prepare(`DETACH attached`).run();
101
+ }
103
102
  };
104
103
 
105
104
  exports.compareDatabaseRowsByTimestamp = (row1, row2) => {
@@ -1,4 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  export const RESULT = 'result';
4
+ export const RESULT_META = 'result_meta';
4
5
  export const MENU_BAR = 'menu-bar';
6
+ export const ROOT = 'root';
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ const getSyncEvents = () => ({
4
+ DATABASE_CREATED: 'databaseCreated'
5
+ });
6
+
7
+ const events = getSyncEvents();
8
+ Object.defineProperty(events, 'getSync', {value: getSyncEvents, enumerable: false});
9
+
10
+ module.exports = events;
package/lib/gui/server.js CHANGED
@@ -9,7 +9,6 @@ const {INTERNAL_SERVER_ERROR, OK} = require('http-codes');
9
9
 
10
10
  const App = require('./app');
11
11
  const {MAX_REQUEST_SIZE, KEEP_ALIVE_TIMEOUT, HEADERS_TIMEOUT} = require('./constants/server');
12
- const {IMAGES_PATH, ERROR_DETAILS_PATH} = require('../constants/paths');
13
12
  const {logger, initializeCustomGui, runCustomGuiAction} = require('../server-utils');
14
13
  const initPluginsRoutes = require('./routes/plugins');
15
14
 
@@ -26,9 +25,7 @@ exports.start = async ({paths, hermione, guiApi, configs}) => {
26
25
  server.use(initPluginsRoutes(express.Router(), pluginConfig));
27
26
 
28
27
  server.use(express.static(path.join(__dirname, '../static'), {index: 'gui.html'}));
29
- server.use(express.static(process.cwd()));
30
- server.use(`/${IMAGES_PATH}`, express.static(path.join(process.cwd(), pluginConfig.path, IMAGES_PATH)));
31
- server.use(`/${ERROR_DETAILS_PATH}`, express.static(path.join(process.cwd(), pluginConfig.path, ERROR_DETAILS_PATH)));
28
+ server.use(express.static(path.join(process.cwd(), pluginConfig.path)));
32
29
 
33
30
  server.get('/', (req, res) => res.sendFile(path.join(__dirname, '../static', 'gui.html')));
34
31
 
@@ -113,6 +110,16 @@ exports.start = async ({paths, hermione, guiApi, configs}) => {
113
110
  logger.log('server shutting down');
114
111
  });
115
112
 
113
+ server.post('/stop', (req, res) => {
114
+ try {
115
+ // pass 0 to prevent terminating hermione process
116
+ hermione.halt('Tests were stopped by the user', 0);
117
+ res.sendStatus(OK);
118
+ } catch (e) {
119
+ res.status(INTERNAL_SERVER_ERROR).send(`Error while stopping tests: ${e.message}`);
120
+ }
121
+ });
122
+
116
123
  await app.initialize();
117
124
 
118
125
  const {port, hostname} = options;
@@ -60,12 +60,14 @@ module.exports = class ToolRunner {
60
60
  await mergeDatabasesForReuse(this._reportPath);
61
61
 
62
62
  this._reportBuilder = GuiReportBuilder.create(this._hermione, this._pluginConfig, {reuse: true});
63
+ this._subscribeOnEvents();
64
+
65
+ this._collection = await this._readTests();
66
+
63
67
  await this._reportBuilder.init();
64
68
  await this._reportBuilder.saveStaticFiles();
65
69
 
66
- this._subscribeOnEvents();
67
70
  this._reportBuilder.setApiValues(this._hermione.htmlReporter.values);
68
- this._collection = await this._readTests();
69
71
  await this._handleRunnableCollection();
70
72
  }
71
73
 
@@ -11,8 +11,7 @@ const NestedError = require('nested-error-stacks');
11
11
  const StaticTestsTreeBuilder = require('../../tests-tree-builder/static');
12
12
  const {logger} = require('../../server-utils');
13
13
  const constantFileNames = require('../../constants/file-names');
14
- const {mergeTablesQueries, selectAllSuitesQuery, compareDatabaseRowsByTimestamp} = require('../../common-utils');
15
- const {writeDatabaseUrlsFile} = require('../../server-utils');
14
+ const {mergeTables, selectAllSuitesQuery, compareDatabaseRowsByTimestamp} = require('../../common-utils');
16
15
 
17
16
  exports.formatId = (hash, browserId) => `${hash}/${browserId}`;
18
17
 
@@ -48,26 +47,11 @@ exports.mergeDatabasesForReuse = async (reportPath) => {
48
47
  logger.warn(chalk.yellow(`Merge databases to ${constantFileNames.LOCAL_DATABASE_NAME}`));
49
48
 
50
49
  const mergedDatabase = new Database(mergedDbPath);
51
-
52
- for (const query of mergeTablesQueries(dbPaths)) {
53
- try {
54
- mergedDatabase.prepare(query).run();
55
- } catch (err) {
56
- // TODO: To be able to work with files that have been created before
57
- // TODO: Remove in next versions
58
- if (/no such table/.test(err)) {
59
- console.warn(err);
60
-
61
- continue;
62
- }
63
-
64
- throw err;
65
- }
66
- }
67
-
50
+ mergeTables({db: mergedDatabase, dbPaths, getExistingTables: (statement) => {
51
+ return statement.all().map((table) => table.name);
52
+ }});
68
53
  mergedDatabase.close();
69
54
 
70
- await writeDatabaseUrlsFile(reportPath, [constantFileNames.LOCAL_DATABASE_NAME]);
71
55
  await Promise.all(dbPaths.map(p => fs.remove(p)));
72
56
  };
73
57
 
package/lib/plugin-api.js CHANGED
@@ -1,7 +1,16 @@
1
1
  'use strict';
2
2
 
3
- module.exports = class HtmlReporter {
3
+ const AsyncEmitter = require('gemini-core').events.AsyncEmitter;
4
+ const pluginEvents = require('./constants/plugin-events');
5
+
6
+ module.exports = class HtmlReporter extends AsyncEmitter {
7
+ static create() {
8
+ return new this();
9
+ }
10
+
4
11
  constructor() {
12
+ super();
13
+
5
14
  this._values = {
6
15
  extraItems: {},
7
16
  metaInfoExtenders: {},
@@ -10,6 +19,10 @@ module.exports = class HtmlReporter {
10
19
  };
11
20
  }
12
21
 
22
+ get events() {
23
+ return pluginEvents;
24
+ }
25
+
13
26
  addExtraItem(key, value) {
14
27
  this._values.extraItems[key] = value;
15
28
  }
@@ -23,6 +23,7 @@ module.exports = class StaticReportBuilder {
23
23
  this._pluginConfig = pluginConfig;
24
24
 
25
25
  this._sqliteAdapter = SqliteAdapter.create({
26
+ hermione: this._hermione,
26
27
  reportPath: this._pluginConfig.path,
27
28
  reuse
28
29
  });
@@ -15,7 +15,8 @@ module.exports = class SqliteAdapter {
15
15
  return new SqliteAdapter(...args);
16
16
  }
17
17
 
18
- constructor({reportPath, reuse = false}) {
18
+ constructor({hermione, reportPath, reuse = false}) {
19
+ this._hermione = hermione;
19
20
  this._reportPath = reportPath;
20
21
  this._reuse = reuse;
21
22
  this._db = null;
@@ -39,6 +40,8 @@ module.exports = class SqliteAdapter {
39
40
  debug('db connection opened');
40
41
 
41
42
  createTablesQuery().forEach((query) => this._db.prepare(query).run());
43
+
44
+ this._hermione.htmlReporter.emit(this._hermione.htmlReporter.events.DATABASE_CREATED, this._db);
42
45
  } catch (err) {
43
46
  throw new NestedError(`Error creating database at "${dbPath}"`, err);
44
47
  }
@@ -19,6 +19,7 @@ class GuiControls extends Component {
19
19
  // from store
20
20
  running: PropTypes.bool.isRequired,
21
21
  processing: PropTypes.bool.isRequired,
22
+ stopping: PropTypes.bool.isRequired,
22
23
  autoRun: PropTypes.bool.isRequired,
23
24
  allRootSuiteIds: PropTypes.arrayOf(PropTypes.string).isRequired,
24
25
  failedRootSuiteIds: PropTypes.arrayOf(PropTypes.string).isRequired,
@@ -35,8 +36,7 @@ class GuiControls extends Component {
35
36
  }
36
37
 
37
38
  render() {
38
- const {actions, allRootSuiteIds, failedRootSuiteIds, running, autoRun, processing} = this.props;
39
-
39
+ const {actions, allRootSuiteIds, failedRootSuiteIds, running, autoRun, processing, stopping} = this.props;
40
40
  return (
41
41
  <div className="main-menu container">
42
42
  <CustomGuiControls />
@@ -52,6 +52,11 @@ class GuiControls extends Component {
52
52
  isDisabled={!failedRootSuiteIds.length || processing}
53
53
  handler={this._runFailedTests}
54
54
  />
55
+ <ControlButton
56
+ label="Stop tests"
57
+ isDisabled={!running || stopping}
58
+ handler={actions.stopTests}
59
+ />
55
60
  <AcceptOpenedButton />
56
61
  <CommonControls/>
57
62
  </div>
@@ -66,6 +71,7 @@ export default connect(
66
71
  return {
67
72
  running: state.running,
68
73
  processing: state.processing,
74
+ stopping: state.stopping,
69
75
  autoRun: state.autoRun,
70
76
  allRootSuiteIds: state.tree.suites.allRootIds,
71
77
  failedRootSuiteIds: state.tree.suites.failedRootIds,
@@ -5,6 +5,7 @@ import Notifications from 'reapop';
5
5
  import wybo from 'reapop-theme-wybo';
6
6
  import {bindActionCreators} from 'redux';
7
7
 
8
+ import {ROOT} from '../../constants/extension-points';
8
9
  import * as actions from '../modules/actions';
9
10
  import ControlButtons from './controls/gui-controls';
10
11
  import SkippedList from './skipped-list';
@@ -14,6 +15,7 @@ import MainTree from './main-tree';
14
15
  import CustomScripts from './custom-scripts';
15
16
  import clientEvents from '../../gui/constants/client-events';
16
17
  import FaviconChanger from './favicon-changer';
18
+ import ExtensionPoint from './extension-point';
17
19
 
18
20
  class Gui extends Component {
19
21
  static propTypes = {
@@ -30,6 +32,10 @@ class Gui extends Component {
30
32
  this._subscribeToEvents();
31
33
  }
32
34
 
35
+ componentWillUnmount() {
36
+ this.props.actions.finGuiReport();
37
+ }
38
+
33
39
  _subscribeToEvents() {
34
40
  const {actions} = this.props;
35
41
  const eventSource = new EventSource('/events');
@@ -60,21 +66,28 @@ class Gui extends Component {
60
66
  const {allRootSuiteIds, loading, customScripts} = this.props;
61
67
 
62
68
  if (!allRootSuiteIds.length) {
63
- return (<Loading active={true} />);
69
+ return (
70
+ <Fragment>
71
+ <Notifications theme={wybo}/>
72
+ <Loading active={true} />
73
+ </Fragment>
74
+ );
64
75
  }
65
76
 
66
77
  return (
67
78
  <Fragment>
68
- <CustomScripts scripts={customScripts}/>
69
- <Notifications theme={wybo}/>
70
- <FaviconChanger />
71
- <ControlButtons />
72
- <main className="container">
73
- <SkippedList />
74
- <MainTree />
75
- </main>
76
- <Loading active={loading.active} content={loading.content} />
77
- <ModalContainer />
79
+ <ExtensionPoint name={ROOT}>
80
+ <CustomScripts scripts={customScripts}/>
81
+ <Notifications theme={wybo}/>
82
+ <FaviconChanger />
83
+ <ControlButtons />
84
+ <main className="container">
85
+ <SkippedList />
86
+ <MainTree />
87
+ </main>
88
+ <Loading active={loading.active} content={loading.content} />
89
+ <ModalContainer />
90
+ </ExtensionPoint>
78
91
  </Fragment>
79
92
  );
80
93
  }
@@ -5,6 +5,7 @@ import Notifications from 'reapop';
5
5
  import wybo from 'reapop-theme-wybo';
6
6
  import {bindActionCreators} from 'redux';
7
7
 
8
+ import {ROOT} from '../../constants/extension-points';
8
9
  import * as actions from '../modules/actions';
9
10
  import Loading from './loading';
10
11
  import Header from './header';
@@ -13,6 +14,7 @@ import SkippedList from './skipped-list';
13
14
  import MainTree from './main-tree';
14
15
  import CustomScripts from './custom-scripts';
15
16
  import FaviconChanger from './favicon-changer';
17
+ import ExtensionPoint from './extension-point';
16
18
 
17
19
  class Report extends Component {
18
20
  static propTypes = {
@@ -34,20 +36,27 @@ class Report extends Component {
34
36
  const {allRootSuiteIds, fetchDbDetails} = this.props;
35
37
 
36
38
  if (!allRootSuiteIds.length && !fetchDbDetails.length) {
37
- return (<Loading active={true} />);
39
+ return (
40
+ <Fragment>
41
+ <Notifications theme={wybo}/>
42
+ <Loading active={true} />
43
+ </Fragment>
44
+ );
38
45
  }
39
46
 
40
47
  return (
41
48
  <Fragment>
42
- <CustomScripts scripts={this.props.customScripts}/>
43
- <Notifications theme={wybo} />
44
- <FaviconChanger />
45
- <Header/>
46
- <ControlButtons/>
47
- <main className="container">
48
- <SkippedList />
49
- <MainTree />
50
- </main>
49
+ <ExtensionPoint name={ROOT}>
50
+ <CustomScripts scripts={this.props.customScripts}/>
51
+ <Notifications theme={wybo} />
52
+ <FaviconChanger />
53
+ <Header/>
54
+ <ControlButtons/>
55
+ <main className="container">
56
+ <SkippedList />
57
+ <MainTree />
58
+ </main>
59
+ </ExtensionPoint>
51
60
  </Fragment>
52
61
  );
53
62
  }
@@ -4,6 +4,8 @@ import PropTypes from 'prop-types';
4
4
  import MetaInfo from './meta-info';
5
5
  import Description from './description';
6
6
  import Tabs from './tabs';
7
+ import ExtensionPoint from '../../extension-point';
8
+ import {RESULT_META} from '../../../../constants/extension-points';
7
9
 
8
10
  class Result extends Component {
9
11
  static propTypes = {
@@ -22,7 +24,9 @@ class Result extends Component {
22
24
 
23
25
  return (
24
26
  <Fragment>
25
- <MetaInfo result={result} testName={testName} />
27
+ <ExtensionPoint name={RESULT_META} result={result} testName={testName}>
28
+ <MetaInfo result={result} testName={testName} />
29
+ </ExtensionPoint>
26
30
  {result.description && <Description content={result.description} />}
27
31
  <Tabs result={result} />
28
32
  </Fragment>