bun-ui-tests 1.0.4 → 1.0.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/cli.ts +82 -49
- package/package.json +1 -1
- package/ui-runner.ts +10 -0
package/cli.ts
CHANGED
|
@@ -2,10 +2,45 @@
|
|
|
2
2
|
|
|
3
3
|
import { spawn } from "node:child_process";
|
|
4
4
|
import { readFile, access } from "node:fs/promises";
|
|
5
|
-
import { join, dirname } from "node:path";
|
|
5
|
+
import { join, dirname, resolve } from "node:path";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
// Função robusta para determinar o diretório raiz do pacote
|
|
9
|
+
function getPackageRoot() {
|
|
10
|
+
// 1. Tentar import.meta.dir (Bun específico)
|
|
11
|
+
if (import.meta.dir) {
|
|
12
|
+
return import.meta.dir;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// 2. Tentar process.argv[1] (caminho do script)
|
|
16
|
+
try {
|
|
17
|
+
const argvPath = process.argv[1];
|
|
18
|
+
if (argvPath) {
|
|
19
|
+
// Se é um arquivo .ts, usa o diretório dele
|
|
20
|
+
if (argvPath.endsWith('.ts')) {
|
|
21
|
+
return dirname(argvPath);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Se é um executável, procura node_modules
|
|
25
|
+
// bunx instala em: ~/.bun/install/cache/bun-ui-tests@version/
|
|
26
|
+
const parts = argvPath.split('/');
|
|
27
|
+
const cacheIndex = parts.findIndex(p => p === 'cache');
|
|
28
|
+
if (cacheIndex !== -1 && cacheIndex + 1 < parts.length) {
|
|
29
|
+
// Pega até o nome do pacote (ex: bun-ui-tests@1.0.5)
|
|
30
|
+
const packagePath = parts.slice(0, cacheIndex + 2).join('/');
|
|
31
|
+
return packagePath;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
} catch (e) {
|
|
35
|
+
console.error('Error resolving from argv[1]:', e);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// 3. Fallback: usar diretório atual
|
|
39
|
+
console.warn('⚠️ Could not determine package root, using current directory');
|
|
40
|
+
return process.cwd();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const packageRoot = getPackageRoot();
|
|
9
44
|
|
|
10
45
|
const COMMANDS = {
|
|
11
46
|
run: "Run the test UI (production mode)",
|
|
@@ -18,7 +53,7 @@ async function showHelp() {
|
|
|
18
53
|
🧪 Bun Test UI - A beautiful UI for running Bun tests
|
|
19
54
|
|
|
20
55
|
Usage:
|
|
21
|
-
|
|
56
|
+
bunx bun-ui-tests <command>
|
|
22
57
|
|
|
23
58
|
Commands:
|
|
24
59
|
run Start the test UI (production mode)
|
|
@@ -26,50 +61,44 @@ Commands:
|
|
|
26
61
|
help Show this help message
|
|
27
62
|
|
|
28
63
|
Examples:
|
|
29
|
-
|
|
30
|
-
|
|
64
|
+
bunx bun-ui-tests run # Run in production mode
|
|
65
|
+
bunx bun-ui-tests dev # Run in development mode (for testing)
|
|
31
66
|
`);
|
|
32
67
|
}
|
|
33
68
|
|
|
34
|
-
async function
|
|
35
|
-
|
|
69
|
+
async function checkBuildExists(): Promise<boolean> {
|
|
70
|
+
const distPath = join(packageRoot, "app", "dist", "index.html");
|
|
36
71
|
|
|
37
|
-
|
|
72
|
+
console.log(`🔍 Debug Info:`);
|
|
73
|
+
console.log(` - process.argv[1]: ${process.argv[1]}`);
|
|
74
|
+
console.log(` - Resolved packageRoot: ${packageRoot}`);
|
|
75
|
+
console.log(` - Looking for: ${distPath}`);
|
|
38
76
|
|
|
39
|
-
return new Promise<void>((resolve, reject) => {
|
|
40
|
-
const proc = spawn("bun", ["run", "build"], {
|
|
41
|
-
cwd: appDir,
|
|
42
|
-
stdio: "inherit",
|
|
43
|
-
shell: true
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
proc.on("close", (code) => {
|
|
47
|
-
if (code === 0) {
|
|
48
|
-
console.log("\n✅ Frontend built successfully!");
|
|
49
|
-
resolve();
|
|
50
|
-
} else {
|
|
51
|
-
reject(new Error(`Frontend build failed with code ${code}`));
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
proc.on("error", (err) => {
|
|
56
|
-
reject(err);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async function checkBuildExists(): Promise<boolean> {
|
|
62
|
-
const distPath = join(__dirname, "app", "dist", "index.html");
|
|
63
|
-
console.error(`Debug: __dirname is ${__dirname}`);
|
|
64
|
-
console.error(`Debug: import.meta.url is ${import.meta.url}`);
|
|
65
77
|
try {
|
|
66
78
|
const exists = await Bun.file(distPath).exists();
|
|
67
79
|
if (!exists) {
|
|
68
|
-
console.
|
|
80
|
+
console.log(` - File exists: NO ❌`);
|
|
81
|
+
|
|
82
|
+
// Tentar procurar em locais alternativos
|
|
83
|
+
const alternatives = [
|
|
84
|
+
join(process.cwd(), "app", "dist", "index.html"),
|
|
85
|
+
join(dirname(process.argv[0]), "app", "dist", "index.html"),
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
console.log(`\n🔍 Trying alternative paths:`);
|
|
89
|
+
for (const alt of alternatives) {
|
|
90
|
+
const altExists = await Bun.file(alt).exists();
|
|
91
|
+
console.log(` - ${alt}: ${altExists ? '✓' : '✗'}`);
|
|
92
|
+
if (altExists) {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
console.log(` - File exists: YES ✓`);
|
|
69
98
|
}
|
|
70
99
|
return exists;
|
|
71
100
|
} catch (err) {
|
|
72
|
-
console.error(
|
|
101
|
+
console.error(`❌ Error checking path:`, err);
|
|
73
102
|
return false;
|
|
74
103
|
}
|
|
75
104
|
}
|
|
@@ -79,9 +108,19 @@ async function runTestUI() {
|
|
|
79
108
|
const buildExists = await checkBuildExists();
|
|
80
109
|
|
|
81
110
|
if (!buildExists) {
|
|
82
|
-
console.log("⚠️ Frontend assets not found.\n");
|
|
83
|
-
console.log("
|
|
84
|
-
console.log("
|
|
111
|
+
console.log("\n⚠️ Frontend assets not found.\n");
|
|
112
|
+
console.log("This usually means one of:");
|
|
113
|
+
console.log(" 1. The package wasn't built before publishing (contact maintainer)");
|
|
114
|
+
console.log(" 2. You're running from source (run: bun run build first)");
|
|
115
|
+
console.log(" 3. Installation issue (try: npm cache clean --force)\n");
|
|
116
|
+
|
|
117
|
+
console.log("💡 Temporary workaround:");
|
|
118
|
+
console.log(" git clone https://github.com/KillDarkness/Bun-UI-Test.git");
|
|
119
|
+
console.log(" cd Bun-UI-Test");
|
|
120
|
+
console.log(" bun install");
|
|
121
|
+
console.log(" cd app && bun install && bun run build && cd ..");
|
|
122
|
+
console.log(" bun run ui-runner.ts\n");
|
|
123
|
+
|
|
85
124
|
process.exit(1);
|
|
86
125
|
}
|
|
87
126
|
|
|
@@ -91,11 +130,10 @@ async function runTestUI() {
|
|
|
91
130
|
console.log("Press Ctrl+C to stop\n");
|
|
92
131
|
|
|
93
132
|
// Roda o script do backend diretamente com Bun
|
|
94
|
-
|
|
95
|
-
const runnerScript = join(__dirname, "ui-runner.ts");
|
|
133
|
+
const runnerScript = join(packageRoot, "ui-runner.ts");
|
|
96
134
|
|
|
97
135
|
const proc = spawn("bun", ["run", runnerScript], {
|
|
98
|
-
cwd: process.cwd(),
|
|
136
|
+
cwd: process.cwd(),
|
|
99
137
|
stdio: "inherit",
|
|
100
138
|
shell: false,
|
|
101
139
|
env: { ...process.env, NODE_ENV: "production" }
|
|
@@ -127,8 +165,7 @@ async function runDevMode() {
|
|
|
127
165
|
console.log("🌐 Frontend: http://localhost:5050 (with hot reload)\n");
|
|
128
166
|
console.log("Press Ctrl+C to stop\n");
|
|
129
167
|
|
|
130
|
-
|
|
131
|
-
const backendPath = join(__dirname, "ui-runner.ts");
|
|
168
|
+
const backendPath = join(packageRoot, "ui-runner.ts");
|
|
132
169
|
const backendProc = spawn("bun", ["run", backendPath], {
|
|
133
170
|
cwd: process.cwd(),
|
|
134
171
|
stdio: "inherit",
|
|
@@ -136,18 +173,15 @@ async function runDevMode() {
|
|
|
136
173
|
env: { ...process.env, BUN_TEST_UI_DEV: "true" }
|
|
137
174
|
});
|
|
138
175
|
|
|
139
|
-
// Aguarda um pouco para o backend iniciar
|
|
140
176
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
141
177
|
|
|
142
|
-
|
|
143
|
-
const appDir = join(__dirname, "app");
|
|
178
|
+
const appDir = join(packageRoot, "app");
|
|
144
179
|
const frontendProc = spawn("bun", ["run", "dev"], {
|
|
145
180
|
cwd: appDir,
|
|
146
181
|
stdio: "inherit",
|
|
147
182
|
shell: true
|
|
148
183
|
});
|
|
149
184
|
|
|
150
|
-
// Handle Ctrl+C
|
|
151
185
|
process.on("SIGINT", () => {
|
|
152
186
|
console.log("\n\n👋 Stopping Bun Test UI...");
|
|
153
187
|
backendProc.kill("SIGINT");
|
|
@@ -155,7 +189,6 @@ async function runDevMode() {
|
|
|
155
189
|
process.exit(0);
|
|
156
190
|
});
|
|
157
191
|
|
|
158
|
-
// Se um processo terminar, termina o outro também
|
|
159
192
|
backendProc.on("close", (code) => {
|
|
160
193
|
console.log("\n❌ Backend stopped");
|
|
161
194
|
frontendProc.kill("SIGINT");
|
package/package.json
CHANGED
package/ui-runner.ts
CHANGED
|
@@ -21,12 +21,22 @@ const getBaseDir = () => {
|
|
|
21
21
|
if (import.meta.path && !import.meta.path.endsWith('.ts')) {
|
|
22
22
|
return dirname(process.execPath);
|
|
23
23
|
}
|
|
24
|
+
|
|
25
|
+
// Try process.argv[1] to find real path
|
|
26
|
+
try {
|
|
27
|
+
const argvPath = process.argv[1];
|
|
28
|
+
if (argvPath && argvPath.endsWith("ui-runner.ts")) {
|
|
29
|
+
return dirname(argvPath);
|
|
30
|
+
}
|
|
31
|
+
} catch (e) {}
|
|
32
|
+
|
|
24
33
|
// Se rodando como script .ts, usa o dir do próprio arquivo
|
|
25
34
|
return import.meta.dir;
|
|
26
35
|
};
|
|
27
36
|
|
|
28
37
|
const baseDir = getBaseDir();
|
|
29
38
|
const distPath = join(baseDir, "app", "dist");
|
|
39
|
+
console.log(`Debug: ui-runner argv[1] is ${process.argv[1]}`);
|
|
30
40
|
console.log(`Debug: distPath is ${distPath}`);
|
|
31
41
|
const isDevMode = process.env.BUN_TEST_UI_DEV === "true";
|
|
32
42
|
|