Skip to content

Commit

Permalink
added onData hook
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Sep 2, 2024
1 parent b314912 commit a61504d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* 2.8.0
- (New Feature) added new merge command for CLI: `npx monocart merge path-to/*/*.json` (#142)
- added `onData` hook
- better support for playwright multiple reports generation:
- added new option `copyAttachments` to copy attachments for reporter (#143)
- updated default `outputFile` to `./monocart-report/index.html` from `./test-results/report.html`
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ see example [merge.js](https://github.com/cenfun/monocart-reporter-examples/blob

### Using `merge` CLI
```sh
npx monocart merge path-to/shard*/index.json
npx monocart merge <glob-patterns>
# -o --outputFile
npx monocart merge path-to/shard*/index.json -o merged-reports/index.html
Expand Down
13 changes: 12 additions & 1 deletion lib/generate-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,17 @@ const onEndHandler = async (reportData, options) => {
await onEnd(reportData, helper);
};

const onDataHandler = async (reportData, options, rawData) => {
// onData callback
const onData = options.onData;
if (typeof onData !== 'function') {
return;
}
await onData(reportData, rawData);
};

const generateReport = async (reportData, options) => {

const generateReport = async (reportData, options, rawData) => {

Util.logInfo('generating test report ...');

Expand All @@ -209,6 +218,8 @@ const generateReport = async (reportData, options) => {

}

await onDataHandler(reportData, options, rawData);

// console.log(reportData);
const htmlFile = path.basename(outputFile);

Expand Down
6 changes: 6 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ export type MonocartReporterOptions = {
merge?: boolean;
}

/**
* onData hook
*/
onData?: (reportData: any, rawData: any) => Promise<void>;


/** onEnd hook: https://github.com/cenfun/monocart-reporter?#onend-hook */
onEnd?: (reportData: any, helper: Helper) => Promise<void>;

Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class MonocartReporter {
trends: this.trends
});

return generateReport(reportData, this.options);
return generateReport(reportData, this.options, this.root);
}

}
Expand Down
2 changes: 1 addition & 1 deletion lib/merge-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,6 @@ module.exports = async (reportDataList, userOptions = {}) => {
const reportData = await mergeDataList(dataList, options);
// console.log(reportData.artifacts);

return generateReport(reportData, options);
return generateReport(reportData, options, dataList);

};

0 comments on commit a61504d

Please sign in to comment.