@arghajit/dummy 0.3.4 → 0.3.6

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@arghajit/dummy",
3
3
  "author": "Arghajit Singha",
4
- "version": "0.3.4",
4
+ "version": "0.3.6",
5
5
  "description": "A Playwright reporter and dashboard for visualizing test results.",
6
6
  "homepage": "https://playwright-pulse-report.netlify.app/",
7
7
  "keywords": [
@@ -2,6 +2,7 @@
2
2
  import * as fs from "fs";
3
3
  import * as path from "path";
4
4
  import { pathToFileURL } from "url";
5
+ import { dirname } from "path";
5
6
 
6
7
  const DEFAULT_OUTPUT_DIR = "pulse-report";
7
8
 
@@ -26,30 +27,51 @@ async function extractOutputDirFromConfig(configPath) {
26
27
  try {
27
28
  let config;
28
29
 
29
- if (configPath.endsWith(".ts")) {
30
- try {
31
- const { register } = await import("node:module");
32
- const { pathToFileURL } = await import("node:url");
30
+ const configDir = dirname(configPath);
31
+ const originalDirname = global.__dirname;
32
+ const originalFilename = global.__filename;
33
33
 
34
- register("ts-node/esm", pathToFileURL("./"));
34
+ try {
35
+ global.__dirname = configDir;
36
+ global.__filename = configPath;
35
37
 
36
- config = await import(pathToFileURL(configPath).href);
37
- } catch (tsError) {
38
+ if (configPath.endsWith(".ts")) {
38
39
  try {
39
- const tsNode = await import("ts-node");
40
- tsNode.register({
41
- transpileOnly: true,
42
- compilerOptions: {
43
- module: "ESNext",
44
- },
45
- });
40
+ const { register } = await import("node:module");
41
+ const { pathToFileURL } = await import("node:url");
42
+
43
+ register("ts-node/esm", pathToFileURL("./"));
44
+
46
45
  config = await import(pathToFileURL(configPath).href);
47
- } catch (fallbackError) {
48
- return null;
46
+ } catch (tsError) {
47
+ try {
48
+ const tsNode = await import("ts-node");
49
+ tsNode.register({
50
+ transpileOnly: true,
51
+ compilerOptions: {
52
+ module: "ESNext",
53
+ },
54
+ });
55
+ config = await import(pathToFileURL(configPath).href);
56
+ } catch (fallbackError) {
57
+ console.error("Failed to load TypeScript config:", fallbackError);
58
+ return null;
59
+ }
49
60
  }
61
+ } else {
62
+ config = await import(pathToFileURL(configPath).href);
63
+ }
64
+ } finally {
65
+ if (originalDirname !== undefined) {
66
+ global.__dirname = originalDirname;
67
+ } else {
68
+ delete global.__dirname;
69
+ }
70
+ if (originalFilename !== undefined) {
71
+ global.__filename = originalFilename;
72
+ } else {
73
+ delete global.__filename;
50
74
  }
51
- } else {
52
- config = await import(pathToFileURL(configPath).href);
53
75
  }
54
76
 
55
77
  const playwrightConfig = config.default || config;
@@ -66,32 +88,45 @@ async function extractOutputDirFromConfig(configPath) {
66
88
  reporterPath.includes("@arghajit/dummy"))
67
89
  ) {
68
90
  if (options && options.outputDir) {
69
- return path.resolve(process.cwd(), options.outputDir);
91
+ const resolvedPath =
92
+ typeof options.outputDir === "string"
93
+ ? options.outputDir
94
+ : options.outputDir;
95
+ console.log(`Found outputDir in config: ${resolvedPath}`);
96
+ return path.resolve(process.cwd(), resolvedPath);
70
97
  }
71
98
  }
72
99
  }
73
100
  }
74
101
  }
75
102
 
103
+ console.log("No matching reporter config found with outputDir");
76
104
  return null;
77
105
  } catch (error) {
106
+ console.error("Error extracting outputDir from config:", error);
78
107
  return null;
79
108
  }
80
109
  }
81
110
 
82
111
  export async function getOutputDir(customOutputDirFromArgs = null) {
83
112
  if (customOutputDirFromArgs) {
113
+ console.log(`Using custom outputDir from CLI: ${customOutputDirFromArgs}`);
84
114
  return path.resolve(process.cwd(), customOutputDirFromArgs);
85
115
  }
86
116
 
87
117
  const { path: configPath, exists } = await findPlaywrightConfig();
118
+ console.log(
119
+ `Config file search result: ${exists ? configPath : "not found"}`
120
+ );
88
121
 
89
122
  if (exists) {
90
123
  const outputDirFromConfig = await extractOutputDirFromConfig(configPath);
91
124
  if (outputDirFromConfig) {
125
+ console.log(`Using outputDir from config: ${outputDirFromConfig}`);
92
126
  return outputDirFromConfig;
93
127
  }
94
128
  }
95
129
 
130
+ console.log(`Using default outputDir: ${DEFAULT_OUTPUT_DIR}`);
96
131
  return path.resolve(process.cwd(), DEFAULT_OUTPUT_DIR);
97
132
  }