monocart-reporter 1.6.15 → 1.6.17

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
@@ -24,6 +24,7 @@
24
24
  * [Metadata](#metadata)
25
25
  * [Trend Chart](#trend-chart)
26
26
  * [Attach Code Coverage Report](#attach-code-coverage-report)
27
+ * [Attach Network Report](#attach-network-report)
27
28
  * [Merge Shard Reports](#merge-shard-reports)
28
29
  * [onEnd hook](#onend-hook)
29
30
  - [Send Email](#send-email)
@@ -150,7 +151,7 @@ The report will be displayed in a `Tree Grid`. The `columns` function is used to
150
151
  - `width` (Number) Column width
151
152
  - `minWidth`, `maxWidth` (Number) Default to 81 ~ 300
152
153
  - `styleMap` (Object, String) Column style (css)
153
- - `formatter` (Function) [column formatter](#custom-formatter), arguments: value, rowItem, columnItem, cellNode
154
+ - `formatter` (Function) [column formatter](#custom-formatter). Arguments: value, rowItem, columnItem, cellNode
154
155
  - `sortable` (Boolean) Column sortable when click column header name
155
156
  - `resizable` (Boolean) Column width resizable
156
157
  - `searchable` (Boolean) Specifies whether the column is searchable
@@ -254,7 +255,7 @@ module.exports = {
254
255
  ```
255
256
 
256
257
  ## Data Collection Visitor
257
- The `visitor` function will be executed for each row item (suite, case and step), the arguments are:
258
+ The `visitor` function will be executed for each row item (suite, case and step). Arguments:
258
259
  - `data` data item (suite/case/step) for reporter, you can override some of its properties or add more
259
260
  - `metadata` original data object from Playwright test, could be one of [Suite](https://playwright.dev/docs/api/class-suite), [TestCase](https://playwright.dev/docs/api/class-testcase) or [TestStep](https://playwright.dev/docs/api/class-teststep)
260
261
  - `collect` only one self collection for now: `collect.comments(parserOptions)` and parser options following:
@@ -525,14 +526,26 @@ module.exports = {
525
526
  ```
526
527
 
527
528
  ## Attach Code Coverage Report
528
- Using `MonocartReporter.attachCoverageReport()` API to generate coverage report during the test. There are 2 supported data inputs: `V8` and `istanbul` (see example: [coverage.spec.js](https://github.com/cenfun/monocart-reporter-test/blob/main/tests/coverage/coverage.spec.js))
529
- - [V8](https://playwright.dev/docs/api/class-coverage) (Chromium-based only) Simply take V8 coverage with `startJSCoverage` and `stopJSCoverage`, then [converts](https://github.com/istanbuljs/v8-to-istanbul) from v8 coverage format to istanbul's coverage format, finally generate istanbul report. It works with any code format, but it will not be expected if your code is minified.
529
+ Using `MonocartReporter.attachCoverageReport(data, testInfo, options)` API to generate coverage report during the test. Arguments:
530
+ - `data` There are 2 supported data inputs `Istanbul` (Object) or `V8` (Array)
531
+ - `testInfo` see [TestInfo](https://playwright.dev/docs/api/class-testinfo)
532
+ - `options` (Object)
533
+ - `watermarks` By default, watermarks of Istanbul see [here](https://github.com/istanbuljs/istanbuljs/tree/master/packages/istanbul-lib-report) (Object), watermarks of V8 is `[50, 80]` (Array)
534
+ - `toIstanbul` (Boolean) for V8 data conversion
535
+
536
+ (see example: [report-coverage.spec.js](https://github.com/cenfun/monocart-reporter/blob/main/tests/report-coverage/report-coverage.spec.js))
537
+
538
+ - [Istanbul](https://github.com/istanbuljs) Requires your source code is instrumented. Usually we can use the tool [babel-plugin-istanbul](https://github.com/istanbuljs/babel-plugin-istanbul) to build instrumenting code. (see example: [webpack.config.js](https://github.com/cenfun/monocart-reporter-test/blob/main/packages/coverage/webpack.config.js)) The instrumented code will automatically generate coverage data and save it on `window.__coverage__`. The Istanbul HTML report will be generated and attached to the test report as an attachment.
530
539
  ```js
531
540
  import { test, expect } from '@playwright/test';
532
541
  import { attachCoverageReport } from 'monocart-reporter';
533
- test.describe('take v8 coverage', () => {
534
- test('first, startJSCoverage and open page', async () => {
535
- await page.coverage.startJSCoverage();
542
+ test.describe.configure({
543
+ mode: 'serial'
544
+ });
545
+ let page;
546
+ test.describe('take Istanbul coverage', () => {
547
+ test('first, open page', async ({ browser }) => {
548
+ page = await browser.newPage();
536
549
  await page.goto(pageUrl);
537
550
  });
538
551
 
@@ -542,29 +555,34 @@ test.describe('take v8 coverage', () => {
542
555
  });
543
556
  });
544
557
 
545
- test('finally, stopJSCoverage and take coverage', async () => {
546
- // take v8 coverage
547
- const jsCoverage = await page.coverage.stopJSCoverage();
548
- // filter file list
549
- const coverageInput = jsCoverage.filter((item) => {
550
- if (!item.url.endsWith('.js')) {
551
- return false;
552
- }
553
- return true;
554
- });
555
- expect(coverageInput.length).toBeGreaterThan(0);
558
+ test('finally, take coverage', async () => {
559
+ // take Istanbul coverage
560
+ const coverageData = await page.evaluate(() => window.__coverage__);
561
+ expect(coverageData, 'expect found Istanbul data: __coverage__').toBeTruthy();
556
562
  // coverage report
557
- const report = await attachCoverageReport(coverageInput, test.info());
558
- console.log(report.lines);
563
+ const report = await attachCoverageReport(coverageData, test.info());
564
+ console.log(report.summary);
559
565
  });
560
566
  });
561
567
  ```
562
- - [istanbul](https://github.com/istanbuljs) Requires your source code is instrumented. Usually we can use the tool [babel-plugin-istanbul](https://github.com/istanbuljs/babel-plugin-istanbul) to build instrumenting code (see example: [webpack.config.js](https://github.com/cenfun/monocart-reporter-test/blob/main/packages/coverage/webpack.config.js)) The instrumented code will automatically generate coverage data and save it on `window.__coverage__`
568
+
569
+ ![](/docs/istanbul.png)
570
+
571
+ - [V8](https://v8.dev/blog/javascript-code-coverage) ([Chromium-based only](https://chromedevtools.github.io/devtools-protocol/tot/Profiler/#type-ScriptCoverage)) Simply take coverage data with [class-coverage](https://playwright.dev/docs/api/class-coverage) APIs, the V8 HTML report will be generated.
563
572
  ```js
564
573
  import { test, expect } from '@playwright/test';
565
574
  import { attachCoverageReport } from 'monocart-reporter';
566
- test.describe('take istanbul coverage', () => {
567
- test('first, open page', async () => {
575
+ test.describe.configure({
576
+ mode: 'serial'
577
+ });
578
+ let page;
579
+ test.describe('take V8 coverage', () => {
580
+ test('first, open page', async ({ browser }) => {
581
+ page = await browser.newPage();
582
+ await Promise.all([
583
+ page.coverage.startJSCoverage(),
584
+ page.coverage.startCSSCoverage()
585
+ ]);
568
586
  await page.goto(pageUrl);
569
587
  });
570
588
 
@@ -575,12 +593,86 @@ test.describe('take istanbul coverage', () => {
575
593
  });
576
594
 
577
595
  test('finally, take coverage', async () => {
578
- // take istanbul coverage
579
- const coverageInput = await page.evaluate(() => window.__coverage__);
580
- expect(coverageInput, 'expect found istanbul data: __coverage__').toBeTruthy();
596
+ const [jsCoverage, cssCoverage] = await Promise.all([
597
+ page.coverage.stopJSCoverage(),
598
+ page.coverage.stopCSSCoverage()
599
+ ]);
600
+ const coverageList = [... jsCoverage, ... cssCoverage];
601
+ // filter file list
602
+ // coverageList = coverageList.filter((item) => {
603
+ // if (item.url.endsWith('.js') || item.url.endsWith('.css')) {
604
+ // return true;
605
+ // }
606
+ // });
607
+ expect(coverageList.length).toBeGreaterThan(0);
581
608
  // coverage report
582
- const report = await attachCoverageReport(coverageInput, test.info());
583
- console.log(report.lines);
609
+ const report = await attachCoverageReport(coverageList, test.info());
610
+ console.log(report.summary);
611
+ });
612
+ });
613
+ ```
614
+
615
+ ![](/docs/v8.gif)
616
+
617
+ - [V8 to Istanbul](https://github.com/istanbuljs/v8-to-istanbul) Take V8 coverage data with [class-coverage](https://playwright.dev/docs/api/class-coverage) APIs, then the V8 coverage format will be converted to Istanbul's coverage format. The Istanbul HTML report will be generated.
618
+ ```js
619
+ const report = await attachCoverageReport(coverageList, test.info(), {
620
+ toIstanbul: true
621
+ });
622
+ ```
623
+
624
+ ### Compare Istanbul, V8 and V8 to Istanbul
625
+ | | Istanbul | V8 | V8 to Istanbul |
626
+ | :--------------| :------ | :------ | :---------------------- |
627
+ | Input data format | Istanbul (Object) | V8 (Array) | V8 (Array) |
628
+ | Options | `watermarks: {}` | `watermarks: [50, 80]` | `toIstanbul: true, watermarks: {}` |
629
+ | Output report | [Istanbul HTML report](https://cenfun.github.io/monocart-reporter/report-coverage-report-coverage-take-Istanbul-coverage-report-finally-take-coverage-Desktop-Chromium/coverage/index.html) | [V8 HTML report](https://cenfun.github.io/monocart-reporter/report-coverage-report-coverage-take-V8-js-and-css-coverage-report-finally-take-coverage-Desktop-Chromium/coverage/index.html) | [Istanbul HTML report](https://cenfun.github.io/monocart-reporter/report-coverage-report-coverage-take-V8-js-to-Istanbul-coverage-report-finally-take-coverage-Desktop-Chromium/coverage/index.html) |
630
+ | Indicators | Covered Lines, Branches, Statements and Functions, Execution Counts | Covered Bytes, Execution Counts | Covered Lines, Branches, Statements and Functions, Execution Counts |
631
+ | CSS coverage | ❌ | ✅ | ❌ |
632
+ | Minified code | N/A | ✅ | ❌ |
633
+ | Code formatting | N/A | ✅ | ❌ |
634
+
635
+ ## Attach Network Report
636
+ Using `MonocartReporter.attachNetworkReport(har, testInfo)` API to generate network report during the test. Arguments:
637
+ - `har` HAR path (String) or HAR file buffer (Buffer). see [HAR 1.2 Spec](http://www.softwareishard.com/blog/har-12-spec/)
638
+ - `testInfo` see [TestInfo](https://playwright.dev/docs/api/class-testinfo)
639
+
640
+ (see example: [report-network.spec.js](https://github.com/cenfun/monocart-reporter/blob/main/tests/report-network/report-network.spec.js))
641
+
642
+ ```js
643
+ const fs = require('fs');
644
+ const path = require('path');
645
+ const { test } = require('@playwright/test');
646
+ const { attachNetworkReport } = require('monocart-reporter');
647
+ let context;
648
+ test.describe('attach network report 1', () => {
649
+
650
+ const harPath = path.resolve('.temp/network-report1.har');
651
+ if (fs.existsSync(harPath)) {
652
+ // remove previous
653
+ fs.rmSync(harPath);
654
+ }
655
+
656
+ test('first, open page', async ({ browser }) => {
657
+ context = await browser.newContext({
658
+ recordHar: {
659
+ path: harPath
660
+ }
661
+ });
662
+ const page = await context.newPage();
663
+ await page.goto('http://playwright.dev/', {
664
+ waitUntil: 'networkidle'
665
+ });
666
+ });
667
+
668
+ test('next, run test cases', async () => {
669
+
670
+ });
671
+
672
+ test('finally, attach HAR', async () => {
673
+ // Close context to ensure HAR is saved to disk.
674
+ await context.close();
675
+ await attachNetworkReport(harPath, test.info());
584
676
  });
585
677
  });
586
678
  ```
@@ -619,7 +711,7 @@ await MonocartReporter.merge(reportDataList, {
619
711
  example: [merged report](https://cenfun.github.io/monocart-reporter-test/merged)
620
712
 
621
713
  ## onEnd hook
622
- The `onEnd` function will be executed after report generated. the arguments are:
714
+ The `onEnd` function will be executed after report generated. Arguments:
623
715
  - `reportData` all report data, properties:
624
716
  - `name` (String) report name
625
717
  - `date` (Number) start date in milliseconds
@@ -735,11 +827,26 @@ Please create an [Incoming Webhooks](https://learn.microsoft.com/en-us/microsoft
735
827
  - [weixin-webhook.js](/tests/common/weixin-webhook.js)
736
828
  - [feishu-webhook.js](/tests/common/feishu-webhook.js)
737
829
 
738
- ## Report UI [packages/app](packages/app)
739
- - Base on [Vue 3](https://github.com/vuejs/core)
830
+ ## Dependencies and Packages
831
+ - UI framework [Vue 3](https://github.com/vuejs/core)
740
832
  - Lightweight UI components [vine-ui](https://github.com/cenfun/vine-ui)
741
- - High Performance Grid [turbogrid](https://github.com/cenfun/turbogrid)
742
- - JSON compress/decompress with [lz-utils](https://github.com/cenfun/lz-utils)
833
+ - High performance grid [turbogrid](https://github.com/cenfun/turbogrid)
834
+ - String compress/decompress [lz-utils](https://github.com/cenfun/lz-utils)
835
+ - Packages
836
+ - `packages/app` Monocart report UI
837
+ - `packages/istanbul` Istanbul report libs
838
+ - `packages/show-report` Monocart show-report CLI libs
839
+ - `packages/v8` V8 HTML report UI
840
+ - `packages/vendor` Third-party libs
841
+
743
842
 
843
+ ## Contributing
844
+ ```sh
845
+ npm install starfall-cli -g
846
+ npm install
847
+ npm run test
848
+ npm run build
849
+ npm run dev
850
+ ```
744
851
  ## CHANGELOG
745
852
  - [CHANGELOG.md](CHANGELOG.md)
package/lib/common.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const EC = require('eight-colors');
2
2
  const Util = require('./utils/util.js');
3
3
  const defaultSummary = require('./default/summary.js');
4
- const { generatePieChart } = require('./utils/chart.js');
4
+ const generatePieChart = require('./utils/pie.js');
5
5
 
6
6
  const caseHandler = (item, summary) => {
7
7
  summary.tests.value += 1;
@@ -1,6 +1,5 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
-
4
3
  <head>
5
4
  <meta charset="utf-8">
6
5
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
@@ -8,6 +7,6 @@
8
7
  <title>{title}</title>
9
8
  </head>
10
9
  <body>
11
- {content}
10
+ {content}
12
11
  </body>
13
12
  </html>
@@ -23,7 +23,7 @@ const generateHtml = (outputDir, filename, reportData) => {
23
23
 
24
24
  let reportJs = `console.error("${errMsg}");`;
25
25
  if (fs.existsSync(reportDistPath)) {
26
- reportJs = Util.readFileContentSync(reportDistPath);
26
+ reportJs = Util.readFileSync(reportDistPath);
27
27
  } else {
28
28
  EC.logRed(errMsg);
29
29
  }
@@ -39,7 +39,7 @@ const generateHtml = (outputDir, filename, reportData) => {
39
39
  });
40
40
 
41
41
  let htmlPath = path.resolve(outputDir, `${filename}.html`);
42
- Util.writeFileContentSync(htmlPath, html);
42
+ Util.writeFileSync(htmlPath, html);
43
43
  htmlPath = Util.relativePath(htmlPath);
44
44
  console.log(`[MCR] html report: ${EC.cyan(htmlPath)}`);
45
45