html-reporter 7.3.1 → 7.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/CHANGELOG.md CHANGED
@@ -2,6 +2,19 @@
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.4.0"></a>
6
+ # [7.4.0](https://github.com/gemini-testing/html-reporter/compare/v7.3.1...v7.4.0) (2021-10-25)
7
+
8
+
9
+ ### Features
10
+
11
+ * 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))
12
+ * **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))
13
+ * 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))
14
+ * 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))
15
+
16
+
17
+
5
18
  <a name="7.3.1"></a>
6
19
  ## [7.3.1](https://github.com/gemini-testing/html-reporter/compare/v7.3.0...v7.3.1) (2021-09-20)
7
20
 
package/README.md CHANGED
@@ -288,7 +288,8 @@ 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.
293
294
 
294
295
  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.
@@ -372,7 +373,7 @@ Files that will be created during test execution:
372
373
 
373
374
  ## Additional commands
374
375
 
375
- Additional commands that are added to the tool for which this plugin is connected.
376
+ Additional commands that are added to the hermione.
376
377
 
377
378
  ### gui
378
379
 
@@ -428,9 +429,44 @@ npm run test-func
428
429
 
429
430
  Integration tests run on Chromium in headless mode.
430
431
 
431
- ## Api
432
+ ## API
432
433
 
433
- Html-reporter adds to your tool object with api:
434
+ Html-reporter adds to `hermione` object with its own API.
435
+
436
+ **Properties of the `hermione.htmlReporter` object**
437
+
438
+ Property name | Description
439
+ ------------------------- | -------------
440
+ `events` | Events list for subscription.
441
+ `extraItems` | Items list which will be added to the menu bar.
442
+ `metaInfoExtenders` | Items list which will be added to the meta info.
443
+ `imagesSaver` | Interface to save image into user storage.
444
+ `reportsSaver` | Interface to save sqlite database into user storage.
445
+
446
+ **Available events which are triggered in the main process**
447
+
448
+ Event | Description
449
+ ------------------------- | -------------
450
+ `DATABASE_CREATED` | Will be triggered after sqlite database is created. The handler accepts a database instance. The event is synchronous.
451
+
452
+ ### events
453
+
454
+ Example of a subscription to an event `DATABASE_CREATED` from another hermione-plugin in the main process:
455
+
456
+ ```js
457
+ module.exports = (hermione, opts) => {
458
+ if (!opts.enabled || hermione.isWorker()) {
459
+ return;
460
+ }
461
+
462
+ // `htmlreporter` field is guaranteed to be in the `hermione` object when `INIT` event is emitted
463
+ hermione.on(hermione.events.INIT, () => {
464
+ hermione.htmlReporter.on(hermione.htmlReporter.events.DATABASE_CREATED, (db) => {
465
+ db.prepare(`CREATE TABLE IF NOT EXISTS test1 (foo TEXT, bar TEXT)`).run();
466
+ });
467
+ });
468
+ };
469
+ ```
434
470
 
435
471
  ### addExtraItem
436
472
 
@@ -440,7 +476,7 @@ Adds item to html report as link:
440
476
  @param {String} text of link
441
477
  @param {String} url of link
442
478
 
443
- tool.htmlReporter.addExtraItem('some-text', 'some-url')
479
+ hermione.htmlReporter.addExtraItem('some-text', 'some-url')
444
480
  ```
445
481
 
446
482
  In this case url with link 'some-url' and text 'some-text' will be added to the menu bar.
@@ -450,7 +486,7 @@ In this case url with link 'some-url' and text 'some-text' will be added to the
450
486
  Extend meta-info of each test using passed data:
451
487
 
452
488
  ```js
453
- tool.htmlReporter.addMetaInfoExtender(name, value);
489
+ hermione.htmlReporter.addMetaInfoExtender(name, value);
454
490
  ```
455
491
 
456
492
  * **name** (required) `String` - name of meta info
@@ -458,14 +494,13 @@ tool.htmlReporter.addMetaInfoExtender(name, value);
458
494
 
459
495
  Example:
460
496
  ```js
461
- tool.htmlReporter.addMetaInfoExtender('foo', (data, extraItems) => {
497
+ hermione.htmlReporter.addMetaInfoExtender('foo', (data, extraItems) => {
462
498
  return data.testName + extraItems.platform;
463
499
  });
464
500
  ```
465
501
 
466
502
  In this case a line `suite full name: some-platform` will be added to the meta info of each test.
467
503
 
468
-
469
504
  ### externalStorage
470
505
 
471
506
  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,5 @@
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';
@@ -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
 
@@ -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
  }
@@ -30,6 +30,10 @@ class Gui extends Component {
30
30
  this._subscribeToEvents();
31
31
  }
32
32
 
33
+ componentWillUnmount() {
34
+ this.props.actions.finGuiReport();
35
+ }
36
+
33
37
  _subscribeToEvents() {
34
38
  const {actions} = this.props;
35
39
  const eventSource = new EventSource('/events');
@@ -60,7 +64,12 @@ class Gui extends Component {
60
64
  const {allRootSuiteIds, loading, customScripts} = this.props;
61
65
 
62
66
  if (!allRootSuiteIds.length) {
63
- return (<Loading active={true} />);
67
+ return (
68
+ <Fragment>
69
+ <Notifications theme={wybo}/>
70
+ <Loading active={true} />
71
+ </Fragment>
72
+ );
64
73
  }
65
74
 
66
75
  return (
@@ -34,7 +34,12 @@ class Report extends Component {
34
34
  const {allRootSuiteIds, fetchDbDetails} = this.props;
35
35
 
36
36
  if (!allRootSuiteIds.length && !fetchDbDetails.length) {
37
- return (<Loading active={true} />);
37
+ return (
38
+ <Fragment>
39
+ <Notifications theme={wybo}/>
40
+ <Loading active={true} />
41
+ </Fragment>
42
+ );
38
43
  }
39
44
 
40
45
  return (
@@ -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>
@@ -9,5 +9,5 @@
9
9
  <link href="gui.min.css" rel="stylesheet"></head>
10
10
  <body class="report">
11
11
  <div id="app"></div>
12
- <script type="text/javascript" src="gui.min.js"></script></body>
12
+ <script type="text/javascript" src="sql-wasm.js"></script><script type="text/javascript" src="gui.min.js"></script></body>
13
13
  </html>