monocart-reporter 2.8.2 → 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 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 initTSPreload = () => {
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
- register('./hooks.js', pathToFileURL(__filename));
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
- // eslint-disable-next-line complexity
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monocart-reporter",
3
- "version": "2.8.2",
3
+ "version": "2.8.3",
4
4
  "description": "A playwright test reporter. Shows suites/cases/steps with tree style, markdown annotations, custom columns/formatters/data collection visitors, console logs, style tags, send email.",
5
5
  "main": "lib/index.js",
6
6
  "bin": {
@@ -53,7 +53,6 @@
53
53
  "devDependencies": {
54
54
  "@babel/code-frame": "^7.24.7",
55
55
  "@playwright/test": "^1.47.2",
56
- "amaro": "^0.1.8",
57
56
  "ansi-to-html": "^0.7.2",
58
57
  "async-tick": "^1.0.0",
59
58
  "autolinker": "^4.0.0",
@@ -62,7 +61,7 @@
62
61
  "dotenv": "^16.4.5",
63
62
  "eslint": "^9.11.0",
64
63
  "eslint-config-plus": "^2.0.2",
65
- "eslint-plugin-html": "^8.1.1",
64
+ "eslint-plugin-html": "^8.1.2",
66
65
  "eslint-plugin-vue": "^9.28.0",
67
66
  "file-saver": "^2.0.5",
68
67
  "find-up": "^7.0.0",
package/lib/hooks.js DELETED
@@ -1,37 +0,0 @@
1
-
2
- const EC = require('eight-colors');
3
-
4
- const extensionsRegex = /\.ts$|\.mts$|\.cts$/;
5
-
6
- async function load(url, context, nextLoad) {
7
-
8
- if (extensionsRegex.test(url) && !url.includes('/node_modules/')) {
9
-
10
- const { transformSync } = await import('amaro').catch((e) => {
11
- // console.log(e.message || e);
12
- EC.logRed('The "amaro" module is required for loading ".ts" file, please run "npm i amaro"');
13
- });
14
-
15
- // Use format 'module' so it returns the source as-is, without stripping the types.
16
- // Format 'commonjs' would not return the source for historical reasons.
17
- const { source } = await nextLoad(url, {
18
- ... context,
19
- format: 'module'
20
- });
21
- if (source === null) {
22
- throw new Error('Source code cannot be null or undefined');
23
- }
24
- const { code } = transformSync(source.toString(), {
25
- mode: 'strip-only'
26
- });
27
- return {
28
- format: 'module',
29
- source: code
30
- };
31
- }
32
- return nextLoad(url, context);
33
- }
34
-
35
- module.exports = {
36
- load
37
- };