@arghajit/dummy 0.3.2 → 0.3.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/package.json +2 -2
- package/scripts/config-reader.mjs +96 -0
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
|
+
"version": "0.3.3",
|
|
5
5
|
"description": "A Playwright reporter and dashboard for visualizing test results.",
|
|
6
6
|
"homepage": "https://playwright-pulse-report.netlify.app/",
|
|
7
7
|
"keywords": [
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"files": [
|
|
27
27
|
"dist",
|
|
28
28
|
"screenshots",
|
|
29
|
-
"scripts
|
|
29
|
+
"scripts"
|
|
30
30
|
],
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"bin": {
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import * as fs from "fs";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
import { pathToFileURL } from "url";
|
|
5
|
+
|
|
6
|
+
const DEFAULT_OUTPUT_DIR = "pulse-report";
|
|
7
|
+
|
|
8
|
+
async function findPlaywrightConfig() {
|
|
9
|
+
const possibleConfigs = [
|
|
10
|
+
"playwright.config.ts",
|
|
11
|
+
"playwright.config.js",
|
|
12
|
+
"playwright.config.mjs",
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
for (const configFile of possibleConfigs) {
|
|
16
|
+
const configPath = path.resolve(process.cwd(), configFile);
|
|
17
|
+
if (fs.existsSync(configPath)) {
|
|
18
|
+
return { path: configPath, exists: true };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return { path: null, exists: false };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function extractOutputDirFromConfig(configPath) {
|
|
26
|
+
try {
|
|
27
|
+
let config;
|
|
28
|
+
|
|
29
|
+
if (configPath.endsWith(".ts")) {
|
|
30
|
+
try {
|
|
31
|
+
const { register } = await import("node:module");
|
|
32
|
+
const { pathToFileURL } = await import("node:url");
|
|
33
|
+
|
|
34
|
+
register("ts-node/esm", pathToFileURL("./"));
|
|
35
|
+
|
|
36
|
+
config = await import(pathToFileURL(configPath).href);
|
|
37
|
+
} catch (tsError) {
|
|
38
|
+
try {
|
|
39
|
+
const tsNode = await import("ts-node");
|
|
40
|
+
tsNode.register({
|
|
41
|
+
transpileOnly: true,
|
|
42
|
+
compilerOptions: {
|
|
43
|
+
module: "ESNext",
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
config = await import(pathToFileURL(configPath).href);
|
|
47
|
+
} catch (fallbackError) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
config = await import(pathToFileURL(configPath).href);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const playwrightConfig = config.default || config;
|
|
56
|
+
|
|
57
|
+
if (playwrightConfig && Array.isArray(playwrightConfig.reporter)) {
|
|
58
|
+
for (const reporterConfig of playwrightConfig.reporter) {
|
|
59
|
+
if (Array.isArray(reporterConfig)) {
|
|
60
|
+
const [reporterPath, options] = reporterConfig;
|
|
61
|
+
|
|
62
|
+
if (
|
|
63
|
+
typeof reporterPath === "string" &&
|
|
64
|
+
(reporterPath.includes("playwright-pulse-report") ||
|
|
65
|
+
reporterPath.includes("@arghajit/playwright-pulse-report"))
|
|
66
|
+
) {
|
|
67
|
+
if (options && options.outputDir) {
|
|
68
|
+
return path.resolve(process.cwd(), options.outputDir);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return null;
|
|
76
|
+
} catch (error) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export async function getOutputDir(customOutputDirFromArgs = null) {
|
|
82
|
+
if (customOutputDirFromArgs) {
|
|
83
|
+
return path.resolve(process.cwd(), customOutputDirFromArgs);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const { path: configPath, exists } = await findPlaywrightConfig();
|
|
87
|
+
|
|
88
|
+
if (exists) {
|
|
89
|
+
const outputDirFromConfig = await extractOutputDirFromConfig(configPath);
|
|
90
|
+
if (outputDirFromConfig) {
|
|
91
|
+
return outputDirFromConfig;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return path.resolve(process.cwd(), DEFAULT_OUTPUT_DIR);
|
|
96
|
+
}
|