Skip to content

Commit

Permalink
read trends from json before clean dir
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Sep 2, 2024
1 parent 6d5c0c8 commit 26889e3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
18 changes: 10 additions & 8 deletions lib/default/options.js
Original file line number Diff line number Diff line change
@@ -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,

Expand All @@ -28,6 +29,7 @@ module.exports = () => ({
// sourceFilter: (sourcePath) => sourcePath.search(/src\/.+/) !== -1,
// },

// Global State Management
state: null,

// trend data handler
Expand Down
18 changes: 9 additions & 9 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,31 @@ 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}`
* ```
*/
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;

Expand Down
18 changes: 11 additions & 7 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,36 +45,40 @@ 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);
this.stateServer = createStateServer(stateOptions);
}
}

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;
Expand Down

0 comments on commit 26889e3

Please sign in to comment.