monocart-reporter 2.8.2 → 2.8.4
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 +6 -0
- package/lib/cli.js +34 -9
- package/lib/index.js +17 -4
- package/lib/packages/monocart-reporter-assets.js +2 -2
- package/package.json +2 -3
- package/lib/hooks.js +0 -37
package/README.md
CHANGED
|
@@ -1057,6 +1057,12 @@ npx monocart merge path-to/shard*/index.json -o merged-reports/index.html
|
|
|
1057
1057
|
# -c --config
|
|
1058
1058
|
npx monocart merge path-to/shard*/index.json -c mr.config.js
|
|
1059
1059
|
```
|
|
1060
|
+
The default config files (In order of priority)
|
|
1061
|
+
- mr.config.js
|
|
1062
|
+
- mr.config.cjs
|
|
1063
|
+
- mr.config.mjs
|
|
1064
|
+
- mr.config.json
|
|
1065
|
+
- mr.config.ts
|
|
1060
1066
|
|
|
1061
1067
|
|
|
1062
1068
|
## onEnd Hook
|
package/lib/cli.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
@@ -7,7 +7,6 @@ const https = require('https');
|
|
|
7
7
|
const net = require('net');
|
|
8
8
|
const os = require('os');
|
|
9
9
|
const { pathToFileURL } = require('url');
|
|
10
|
-
const { register } = require('module');
|
|
11
10
|
const EC = require('eight-colors');
|
|
12
11
|
const KSR = require('koa-static-resolver');
|
|
13
12
|
const Koa = require('koa');
|
|
@@ -210,18 +209,41 @@ const checkRegisterFeature = () => {
|
|
|
210
209
|
return true;
|
|
211
210
|
};
|
|
212
211
|
|
|
213
|
-
const
|
|
212
|
+
const loadEnv = (cliOptions) => {
|
|
213
|
+
if (!cliOptions.env) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const envFile = cliOptions.env === true ? '.env' : cliOptions.env;
|
|
217
|
+
const loadEnvFile = process.loadEnvFile;
|
|
218
|
+
if (typeof loadEnvFile === 'function') {
|
|
219
|
+
loadEnvFile(envFile);
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
const initNodeOptions = async (cliOptions) => {
|
|
225
|
+
|
|
226
|
+
loadEnv(cliOptions);
|
|
214
227
|
|
|
215
228
|
const supportRegister = checkRegisterFeature();
|
|
216
229
|
if (!supportRegister) {
|
|
217
230
|
return;
|
|
218
231
|
}
|
|
219
232
|
|
|
220
|
-
|
|
233
|
+
// for loading mr.config.ts
|
|
234
|
+
const modulePath = cliOptions.import || cliOptions.require;
|
|
235
|
+
if (!modulePath) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const res = await import(modulePath);
|
|
240
|
+
if (res && typeof res.register === 'function') {
|
|
241
|
+
await res.register();
|
|
242
|
+
}
|
|
221
243
|
|
|
222
244
|
};
|
|
223
245
|
|
|
224
|
-
|
|
246
|
+
|
|
225
247
|
const resolveConfigOptions = async (configPath) => {
|
|
226
248
|
// json format
|
|
227
249
|
const ext = path.extname(configPath);
|
|
@@ -229,10 +251,6 @@ const resolveConfigOptions = async (configPath) => {
|
|
|
229
251
|
return JSON.parse(Util.readFileSync(configPath));
|
|
230
252
|
}
|
|
231
253
|
|
|
232
|
-
if (ext === '.ts') {
|
|
233
|
-
initTSPreload();
|
|
234
|
-
}
|
|
235
|
-
|
|
236
254
|
let configOptions;
|
|
237
255
|
let err;
|
|
238
256
|
try {
|
|
@@ -256,6 +274,8 @@ const resolveConfigOptions = async (configPath) => {
|
|
|
256
274
|
|
|
257
275
|
const mergeReports = async (str, cliOptions) => {
|
|
258
276
|
|
|
277
|
+
await initNodeOptions(cliOptions);
|
|
278
|
+
|
|
259
279
|
const customConfig = cliOptions.config;
|
|
260
280
|
const configPath = findUpConfig(customConfig);
|
|
261
281
|
|
|
@@ -321,6 +341,11 @@ program.command('merge-reports')
|
|
|
321
341
|
.option('-n, --name <name>', 'report name for title')
|
|
322
342
|
.option('-o, --outputFile <path>', 'output file')
|
|
323
343
|
|
|
344
|
+
.option('--import <module>', 'preload module at startup')
|
|
345
|
+
.option('--require <module>', 'preload module at startup')
|
|
346
|
+
|
|
347
|
+
.option('--env [path]', 'env file (default: ".env")')
|
|
348
|
+
|
|
324
349
|
.action((str, options) => {
|
|
325
350
|
mergeReports(str, options);
|
|
326
351
|
});
|
package/lib/index.js
CHANGED
|
@@ -55,23 +55,26 @@ class MonocartReporter {
|
|
|
55
55
|
this.tickTime = this.options.tickTime || 1000;
|
|
56
56
|
this.tickStart();
|
|
57
57
|
|
|
58
|
+
// read trends from json before clean dir
|
|
59
|
+
getTrends(this.options.trend).then((trends) => {
|
|
60
|
+
// console.log('=========================== ', 'trends', trends.length);
|
|
61
|
+
this.trends = trends;
|
|
62
|
+
});
|
|
63
|
+
|
|
58
64
|
this.init();
|
|
65
|
+
|
|
59
66
|
}
|
|
60
67
|
|
|
61
68
|
async init() {
|
|
62
69
|
|
|
63
70
|
this.options.cwd = Util.formatPath(process.cwd());
|
|
64
71
|
|
|
65
|
-
// read trends from json before clean dir
|
|
66
|
-
this.trends = await getTrends(this.options.trend);
|
|
67
|
-
|
|
68
72
|
// init outputDir
|
|
69
73
|
const outputFile = await Util.resolveOutputFile(this.options.outputFile);
|
|
70
74
|
this.options.outputFile = outputFile;
|
|
71
75
|
|
|
72
76
|
const outputDir = path.dirname(outputFile);
|
|
73
77
|
|
|
74
|
-
Util.initDir(outputDir);
|
|
75
78
|
// for visitor relative path of attachments
|
|
76
79
|
this.options.outputDir = outputDir;
|
|
77
80
|
|
|
@@ -85,6 +88,14 @@ class MonocartReporter {
|
|
|
85
88
|
this.bindFunctions(stateOptions);
|
|
86
89
|
this.stateServer = createStateServer(stateOptions);
|
|
87
90
|
}
|
|
91
|
+
|
|
92
|
+
this.cleanOutputDir();
|
|
93
|
+
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
cleanOutputDir() {
|
|
97
|
+
Util.initDir(this.options.outputDir);
|
|
98
|
+
// console.log('=========================== ', 'cleanOutputDir');
|
|
88
99
|
}
|
|
89
100
|
|
|
90
101
|
// ==========================================================================
|
|
@@ -139,6 +150,8 @@ class MonocartReporter {
|
|
|
139
150
|
this.config = config;
|
|
140
151
|
this.root = suite;
|
|
141
152
|
|
|
153
|
+
// console.log('=========================== ', 'onBegin');
|
|
154
|
+
|
|
142
155
|
// output dir for test results (not reporter)
|
|
143
156
|
this.options.testOutputDir = config.projects[0].outputDir;
|
|
144
157
|
// console.log(`onBegin: ${suite.allTests().length} tests`);
|