monocart-reporter 2.3.0 → 2.3.2

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
@@ -2,6 +2,7 @@
2
2
 
3
3
  [![](https://img.shields.io/npm/v/monocart-reporter)](https://www.npmjs.com/package/monocart-reporter)
4
4
  [![](https://badgen.net/npm/dw/monocart-reporter)](https://www.npmjs.com/package/monocart-reporter)
5
+ ![](https://img.shields.io/librariesio/github/cenfun/monocart-reporter)
5
6
  ![](https://img.shields.io/github/license/cenfun/monocart-reporter)
6
7
  ![](https://img.shields.io/github/actions/workflow/status/cenfun/monocart-reporter/static.yml)
7
8
 
@@ -568,7 +569,8 @@ module.exports = {
568
569
  ```
569
570
 
570
571
  ## Metadata
571
- * add `metadata` to config
572
+ > All metadata will be listed in the report in a key/value format.
573
+ - Global level `metadata`
572
574
  ```js
573
575
  // playwright.config.js
574
576
  module.exports = {
@@ -590,19 +592,59 @@ module.exports = {
590
592
  ]
591
593
  };
592
594
  ```
593
- * collect metadata in global setup
595
+
596
+ - Project level `metadata`
597
+ ```js
598
+ // playwright.config.js
599
+ module.exports = {
600
+ projects: [
601
+ {
602
+ name: 'Desktop Chromium',
603
+ use: {
604
+ browserName: 'chromium'
605
+ },
606
+ metadata: {
607
+ projectData: 'project level metadata',
608
+ owner: 'PO',
609
+ link: 'https://github.com/cenfun/monocart-reporter'
610
+ }
611
+ }
612
+ ]
613
+ }
614
+ ```
615
+
616
+ - Collect metadata in [global setup or teardown](https://playwright.dev/docs/test-global-setup-teardown)
594
617
  ```js
595
618
  // ./common/global-setup.js
596
619
  import { chromium } from '@playwright/test';
597
620
  export default async (config) => {
598
621
  const metadata = config.metadata;
599
- // collect data and save to metadata
622
+ // collect data and save to global metadata
600
623
  const browser = await chromium.launch();
601
624
  const chromiumVersion = await browser.version();
602
625
  metadata.chromiumVersion = chromiumVersion;
603
626
  };
604
627
  ```
605
628
 
629
+ - Collect metadata in a test
630
+ > Playwright Test runs tests in [parallel](https://playwright.dev/docs/test-parallel) with isolate test data by default, so we need to utilize [global state management](#global-state-management) to collect metadata in a test.
631
+
632
+ - Enable global state, see [Setup Global State](#setup-global-state)
633
+ - Update global state in a test
634
+ ```js
635
+ const { test } = require('@playwright/test');
636
+ const { useState } = require('monocart-reporter');
637
+
638
+ const state = useState({
639
+ // port: 8130
640
+ });
641
+
642
+ test('test metadata url', async ({ page }) => {
643
+ const url = await page.evaluate(() => window.location.href);
644
+ await state.set('url', url);
645
+ });
646
+ ```
647
+
606
648
  ## Trend Chart
607
649
  > Note: The trend chart requires historical data generally stored in the server database. There is a serverless solution which is connecting and collecting historical trend data from previous report data before test every time.
608
650
  - If a report is generated in the same place every time, you can simply connect the data with the report JSON path (the data is not 100% safe if there is any runtime error, the previous output dir will be empty by Playwright but the reporter processing not finish)