From 194d625640bd7850550f98b1564070acf2931b02 Mon Sep 17 00:00:00 2001 From: cenfun Date: Mon, 2 Sep 2024 21:41:00 +0800 Subject: [PATCH] updated default `outputFile` to `./monocart-report/index.html` from `./test-results/report.html` --- CHANGELOG.md | 4 ++- README.md | 65 ++++++++++++++------------------------ lib/default/options.js | 4 +-- lib/index.d.ts | 2 +- lib/utils/util.js | 2 +- tests/playwright.config.js | 2 +- 6 files changed, 32 insertions(+), 47 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f645b0a..4c2985b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,9 @@ * 2.8.0 - (New Feature) added new merge command for CLI: `npx monocart merge path-to/*/*.json` (#142) - - added new option `copyAttachments` (#143) + - 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` * 2.7.1 - fixed custom raw dir for merging coverage diff --git a/README.md b/README.md index b96e2bd..fe9ca16 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ module.exports = { ['list'], ['monocart-reporter', { name: "My Test Report", - outputFile: './test-results/report.html' + outputFile: './monocart-report/index.html' }] ] }; @@ -89,26 +89,9 @@ Playwright Docs [https://playwright.dev/docs/test-reporters](https://playwright. ## Output - path-to/your-filename.html Single HTML file (data compressed), easy to transfer/deploy or open directly anywhere -> Note: Test attachments (screenshots images/videos) are not included but linked with relative path in report. All attachments will be found in [playwrightConfig.outputDir](https://playwright.dev/docs/api/class-testconfig#test-config-output-dir) -```js -// playwright.config.js -// attachments outputDir and report outputFile used same folder -const date = new Date().toISOString().slice(0, 10); //2022-10-10 -const outputDir = `./test-results/${date}`; -module.exports = { - outputDir: outputDir, - reporter: [ - ['monocart-reporter', { - name: `My Test Report ${date}`, - outputFile: `${outputDir}/index.html` - }] - ] -}; -// deploy the folder to your report site and easy checking online -// http://your.report.site/test-results/2022-10-10 -``` +> Note: All attachments (screenshots images/videos) will be linked with relative path in report. - path-to/your-filename.json -Separated metadata file (Already included in the above HTML and compressed, it can be deleted). Can be used for debugging or custom data collection. +Separated data file which can be used for debugging or data provider (It's included in the above HTML and compressed). ## Reporter Options ```js @@ -117,7 +100,7 @@ Separated metadata file (Already included in the above HTML and compressed, it c name: '', // the output file path (relative process.cwd) - outputFile: './test-results/report.html', + outputFile: './monocart-report/index.html', // attachment path handler attachmentPath: null, @@ -140,7 +123,7 @@ Separated metadata file (Already included in the above HTML and compressed, it c // trend data handler trend: null, - // trend: () => './test-results/report.json', + // trend: () => './monocart-report/index.json', // custom tags style tags: null, @@ -185,7 +168,7 @@ The server add the http header `Access-Control-Allow-Origin: *` to [allow reques ```sh npx monocart show-report --ssl ``` -For example: `npx monocart show-report test-results/index.html --ssl ssl/key.pem,ssl/cert.pem` +For example: `npx monocart show-report monocart-report/index.html --ssl ssl/key.pem,ssl/cert.pem` You can create and install local CA with [mkcert](https://mkcert.dev) - Using your own trace viewer url with option `traceViewerUrl`: @@ -193,7 +176,7 @@ You can create and install local CA with [mkcert](https://mkcert.dev) // reporter options { name: "My Test Report", - outputFile: './test-results/report.html', + outputFile: './monocart-report/index.html', // defaults to 'https://trace.playwright.dev/?trace={traceUrl}' traceViewerUrl: 'https://your-own-trace-viewer-url/?trace={traceUrl}' } @@ -228,7 +211,7 @@ module.exports = { reporter: [ ['monocart-reporter', { name: "My Test Report", - outputFile: './test-results/report.html', + outputFile: './monocart-report/index.html', // custom columns columns: (defaultColumns) => { @@ -270,7 +253,7 @@ module.exports = { reporter: [ ['monocart-reporter', { name: "My Test Report", - outputFile: './test-results/report.html', + outputFile: './monocart-report/index.html', columns: (defaultColumns) => { // duration formatter @@ -308,7 +291,7 @@ module.exports = { reporter: [ ['monocart-reporter', { name: "My Test Report", - outputFile: './test-results/report.html', + outputFile: './monocart-report/index.html', columns: (defaultColumns) => { const locationColumn = defaultColumns.find((column) => column.id === 'location'); locationColumn.searchable = true; @@ -413,7 +396,7 @@ module.exports = { reporter: [ ['monocart-reporter', { name: "My Test Report", - outputFile: './test-results/report.html', + outputFile: './monocart-report/index.html', mermaid: { // mermaid script url, using mermaid CDN: https://www.jsdelivr.com/package/npm/mermaid scriptSrc: 'https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js', @@ -494,7 +477,7 @@ module.exports = { reporter: [ ['monocart-reporter', { name: "My Test Report", - outputFile: './test-results/report.html', + outputFile: './monocart-report/index.html', visitor: (data, metadata) => { // [MCR-123] collect data from the title const matchResult = metadata.title.match(/\[(.+)\]/); @@ -524,7 +507,7 @@ module.exports = { reporter: [ ['monocart-reporter', { name: "My Test Report", - outputFile: './test-results/report.html', + outputFile: './monocart-report/index.html', visitor: (data, metadata) => { // collect data from the annotations if (metadata.annotations) { @@ -547,7 +530,7 @@ module.exports = { reporter: [ ['monocart-reporter', { name: "My Test Report", - outputFile: './test-results/report.html', + outputFile: './monocart-report/index.html', visitor: (data, metadata) => { const mySecrets = [process.env.PASSWORD, process.env.TOKEN]; mySecrets.forEach((secret) => { @@ -588,7 +571,7 @@ module.exports = { reporter: [ ['monocart-reporter', { name: "My Test Report", - outputFile: './test-results/report.html', + outputFile: './monocart-report/index.html', tags: { smoke: { style: { @@ -612,7 +595,7 @@ module.exports = { ['list'], ['monocart-reporter', { name: "My Test Report", - outputFile: './test-results/report.html', + outputFile: './monocart-report/index.html', tags: { // ... }, @@ -656,7 +639,7 @@ module.exports = { reporter: [ ['monocart-reporter', { name: "My Test Report", - outputFile: './test-results/report.html' + outputFile: './monocart-report/index.html' }] ] }; @@ -723,9 +706,9 @@ module.exports = { reporter: [ ['monocart-reporter', { name: "My Test Report", - outputFile: './test-results/report.html', + outputFile: './monocart-report/index.html', // connect previous report data for trend chart - trend: './test-results/report.json' + trend: './monocart-report/index.json' }] ] }; @@ -741,7 +724,7 @@ module.exports = { reporter: [ ['monocart-reporter', { name: "My Test Report", - outputFile: './test-results/report.html', + outputFile: './monocart-report/index.html', // connect previous report data for trend chart trend: async () => { const previousReportData = await readDataFromSomeWhere("path-to/report.json"); @@ -778,7 +761,7 @@ module.exports = { reporter: [ ['monocart-reporter', { name: "My Test Report", - outputFile: './test-results/report.html', + outputFile: './monocart-report/index.html', // global coverage report options coverage: { entryFilter: (entry) => true, @@ -992,7 +975,7 @@ module.exports = { ['list'], ['monocart-reporter', { name: "My Test Report", - outputFile: './test-results/report.html', + outputFile: './monocart-report/index.html', state: { data: { count: 0 @@ -1060,7 +1043,7 @@ module.exports = { ['list'], ['monocart-reporter', { name: "My Test Report", - outputFile: './test-results/report.html', + outputFile: './monocart-report/index.html', state: { onReceive: function(message) { const test = this.getTest(message.testId); @@ -1149,7 +1132,7 @@ module.exports = { reporter: [ ['monocart-reporter', { name: "My Test Report", - outputFile: './test-results/report.html', + outputFile: './monocart-report/index.html', // async hook after report data generated onEnd: async (reportData, helper) => { // console.log(reportData.summary); diff --git a/lib/default/options.js b/lib/default/options.js index bdedc83..942411d 100644 --- a/lib/default/options.js +++ b/lib/default/options.js @@ -6,7 +6,7 @@ module.exports = () => ({ name: '', // the output html file path (relative process.cwd) - outputFile: './test-results/report.html', + outputFile: './monocart-report/index.html', // whether to copy attachments to the reporter output dir, defaults to true // it is useful when there are multiple html reports being output. @@ -34,7 +34,7 @@ module.exports = () => ({ // trend data handler trend: null, - // trend: () => './test-results/report.json', + // trend: () => './monocart-report/index.json', // custom tags style tags: null, diff --git a/lib/index.d.ts b/lib/index.d.ts index e65eea8..e0a0879 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -96,7 +96,7 @@ export type MonocartReporterOptions = { /** trend data handler: https://github.com/cenfun/monocart-reporter?#trend-chart * ```js - * trend: () => './test-results/report.json' + * trend: () => './monocart-report/index.json' * ``` */ trend?: string | (() => Promise); diff --git a/lib/utils/util.js b/lib/utils/util.js index add372d..18464ae 100644 --- a/lib/utils/util.js +++ b/lib/utils/util.js @@ -95,7 +95,7 @@ const Util = { // end with html if (!outputFile.endsWith('.html')) { - outputFile = path.join(outputFile, 'report.html'); + outputFile = path.join(outputFile, 'index.html'); } return path.resolve(outputFile); diff --git a/tests/playwright.config.js b/tests/playwright.config.js index 01c9777..4644dbe 100644 --- a/tests/playwright.config.js +++ b/tests/playwright.config.js @@ -78,12 +78,12 @@ module.exports = { }], ['html', { outputFolder: '../.temp/html', - outputFile: 'results.html', open: 'never' }], ['junit', { outputFile: '../.temp/junit/results.xml' }], + // ['monocart-reporter'] ['monocart-reporter', { name: 'My Test Report',