monocart-reporter 2.8.1 → 2.8.3
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 +61 -0
- package/lib/packages/monocart-reporter-assets.js +2 -2
- package/lib/utils/util.js +15 -0
- package/package.json +5 -5
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
|
@@ -190,6 +190,60 @@ const findUpConfig = (customConfigFile) => {
|
|
|
190
190
|
// default config not found
|
|
191
191
|
};
|
|
192
192
|
|
|
193
|
+
const checkRegisterFeature = () => {
|
|
194
|
+
const nv = process.versions.node;
|
|
195
|
+
|
|
196
|
+
// "module.register" added in Node.js: v20.6.0
|
|
197
|
+
// if (Util.cmpVersion(nv, '20.6.0') >= 0) {
|
|
198
|
+
// return true;
|
|
199
|
+
// }
|
|
200
|
+
// but also added in: v18.19.0
|
|
201
|
+
const requiredNV = '18.19.0';
|
|
202
|
+
if (Util.cmpVersion(nv, requiredNV) < 0) {
|
|
203
|
+
Util.logInfo(`The current Node.js version "${nv}" does NOT support "module.register", it requires "${requiredNV}" or higher.`);
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// could be < 20.6.0 but just ignore it, please using latest minor version
|
|
208
|
+
|
|
209
|
+
return true;
|
|
210
|
+
};
|
|
211
|
+
|
|
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);
|
|
227
|
+
|
|
228
|
+
const supportRegister = checkRegisterFeature();
|
|
229
|
+
if (!supportRegister) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
|
|
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
|
+
}
|
|
243
|
+
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
|
|
193
247
|
const resolveConfigOptions = async (configPath) => {
|
|
194
248
|
// json format
|
|
195
249
|
const ext = path.extname(configPath);
|
|
@@ -220,6 +274,8 @@ const resolveConfigOptions = async (configPath) => {
|
|
|
220
274
|
|
|
221
275
|
const mergeReports = async (str, cliOptions) => {
|
|
222
276
|
|
|
277
|
+
await initNodeOptions(cliOptions);
|
|
278
|
+
|
|
223
279
|
const customConfig = cliOptions.config;
|
|
224
280
|
const configPath = findUpConfig(customConfig);
|
|
225
281
|
|
|
@@ -285,6 +341,11 @@ program.command('merge-reports')
|
|
|
285
341
|
.option('-n, --name <name>', 'report name for title')
|
|
286
342
|
.option('-o, --outputFile <path>', 'output file')
|
|
287
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
|
+
|
|
288
349
|
.action((str, options) => {
|
|
289
350
|
mergeReports(str, options);
|
|
290
351
|
});
|