diff --git a/lib/default/options.js b/lib/default/options.js index 64c17bb..bdedc83 100644 --- a/lib/default/options.js +++ b/lib/default/options.js @@ -1,23 +1,24 @@ module.exports = () => ({ + // logging levels: off, error, info, debug + logging: 'info', + // the report name name: '', - // the output file path (relative process.cwd) + // the output html file path (relative process.cwd) outputFile: './test-results/report.html', + // whether to copy attachments to the reporter output dir, defaults to true + // it is useful when there are multiple html reports being output. + copyAttachments: true, + // attachment path handler attachmentPath: null, // attachmentPath: (currentPath, extras) => `https://cenfun.github.io/monocart-reporter/${currentPath}`, - // whether copy attachments to the output dir, defaults to true - // it is useful when there are multiple reports being output. - copyAttachments: true, - + // custom trace viewer url traceViewerUrl: 'https://trace.playwright.dev/?trace={traceUrl}', - // logging levels: off, error, info, debug - logging: 'info', - // timezone offset in minutes, GMT+0800 = -480 timezoneOffset: 0, @@ -28,6 +29,7 @@ module.exports = () => ({ // sourceFilter: (sourcePath) => sourcePath.search(/src\/.+/) !== -1, // }, + // Global State Management state: null, // trend data handler diff --git a/lib/index.d.ts b/lib/index.d.ts index 4b8c373..e65eea8 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -45,12 +45,21 @@ export interface Helper { } export type MonocartReporterOptions = { + /** logging levels: off, error, info, debug */ + logging?: string; + /** the report name */ name?: string; /** the output file path (relative process.cwd) */ outputFile?: string; + /** + * whether to copy attachments to the reporter output dir, defaults to true + * it is useful when there are multiple html reports being output + */ + copyAttachments?: boolean; + /** attachment path handler, for example: * ```js * attachmentPath: (currentPath, extras) => `https://cenfun.github.io/monocart-reporter/${currentPath}` @@ -58,18 +67,9 @@ export type MonocartReporterOptions = { */ attachmentPath?: (currentPath: string, extras: any) => string; - /** - * whether copy attachments to the output dir, defaults to true - * it is useful when there are multiple reports being output - */ - copyAttachments?: boolean; - /** custom trace viewer url: https://github.com/cenfun/monocart-reporter?#view-trace-online */ traceViewerUrl?: string; - /** logging levels: off, error, info, debug */ - logging?: string; - /** timezone offset in minutes, For example: GMT+0800 = -480 */ timezoneOffset?: number; diff --git a/lib/index.js b/lib/index.js index 0227a88..829f54d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -45,21 +45,19 @@ class MonocartReporter { }; Util.initLoggingLevel(this.options.logging, 'reporter'); - this.initDir(); this.testMap = new Map(); this.system = getSystemInfo(); this.system.timestampStart = timestampStart; this.system.ticks = []; - this.trends = []; - getTrends(this.options.trend).then((res) => { - this.trends = res; - }); this.tickTime = this.options.tickTime || 1000; this.tickStart(); + this.trends = []; + this.initTrendsAndDir(); + const stateOptions = this.options.state; if (stateOptions) { this.bindFunctions(stateOptions); @@ -67,14 +65,20 @@ class MonocartReporter { } } - async initDir() { + async initTrendsAndDir() { const cwd = Util.formatPath(process.cwd()); this.options.cwd = cwd; - const outputFile = await Util.resolveOutputFile(this.options.outputFile); + // read trends from json before clean dir + this.trends = await getTrends(this.options.trend); + // init outputDir + const outputFile = await Util.resolveOutputFile(this.options.outputFile); + this.options.outputFile = outputFile; + const outputDir = path.dirname(outputFile); + Util.initDir(outputDir); // for visitor relative path of attachments this.options.outputDir = outputDir;