bun-ui-tests 1.0.6 → 1.0.7

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.
Files changed (3) hide show
  1. package/cli.ts +51 -25
  2. package/package.json +1 -1
  3. package/ui-runner.ts +18 -7
package/cli.ts CHANGED
@@ -12,7 +12,13 @@ function getPackageRoot() {
12
12
  return import.meta.dir;
13
13
  }
14
14
 
15
- // 2. Tentar process.argv[1] (caminho do script)
15
+ // 2. Tentar via import.meta.url
16
+ try {
17
+ const __filename = fileURLToPath(import.meta.url);
18
+ return dirname(__filename);
19
+ } catch (e) {}
20
+
21
+ // 3. Tentar process.argv[1] (caminho do script)
16
22
  try {
17
23
  const argvPath = process.argv[1];
18
24
  if (argvPath) {
@@ -21,10 +27,10 @@ function getPackageRoot() {
21
27
  return dirname(argvPath);
22
28
  }
23
29
 
24
- // Se é um executável, procura node_modules
30
+ // Se é um executável, procura node_modules ou cache
25
31
  // bunx instala em: ~/.bun/install/cache/bun-ui-tests@version/
26
32
  const parts = argvPath.split('/');
27
- const cacheIndex = parts.findIndex(p => p === 'cache');
33
+ const cacheIndex = parts.findIndex(p => p === 'cache' || p === '.bun' || p === 'node_modules');
28
34
  if (cacheIndex !== -1 && cacheIndex + 1 < parts.length) {
29
35
  // Pega até o nome do pacote (ex: bun-ui-tests@1.0.5)
30
36
  const packagePath = parts.slice(0, cacheIndex + 2).join('/');
@@ -35,12 +41,11 @@ function getPackageRoot() {
35
41
  console.error('Error resolving from argv[1]:', e);
36
42
  }
37
43
 
38
- // 3. Fallback: usar diretório atual
39
- console.warn('⚠️ Could not determine package root, using current directory');
44
+ // 4. Fallback: usar diretório atual
40
45
  return process.cwd();
41
46
  }
42
47
 
43
- const packageRoot = getPackageRoot();
48
+ let packageRoot = getPackageRoot();
44
49
 
45
50
  const COMMANDS = {
46
51
  run: "Run the test UI (production mode)",
@@ -48,6 +53,36 @@ const COMMANDS = {
48
53
  help: "Show this help message"
49
54
  };
50
55
 
56
+ async function findVerifiedRoot(): Promise<string> {
57
+ const possibleRoots = [
58
+ packageRoot,
59
+ process.cwd(),
60
+ dirname(fileURLToPath(import.meta.url)),
61
+ ];
62
+
63
+ for (const root of possibleRoots) {
64
+ if (!root) continue;
65
+ const runnerPath = join(root, "ui-runner.ts");
66
+ const distPath = join(root, "app", "dist", "index.html");
67
+
68
+ if (await Bun.file(runnerPath).exists() && await Bun.file(distPath).exists()) {
69
+ return root;
70
+ }
71
+ }
72
+
73
+ // Se não achou, tenta procurar subindo diretórios (útil se estiver em node_modules/.bin)
74
+ try {
75
+ let current = packageRoot;
76
+ for (let i = 0; i < 3; i++) {
77
+ const runnerPath = join(current, "ui-runner.ts");
78
+ if (await Bun.file(runnerPath).exists()) return current;
79
+ current = dirname(current);
80
+ }
81
+ } catch (e) {}
82
+
83
+ return packageRoot;
84
+ }
85
+
51
86
  async function showHelp() {
52
87
  console.log(`
53
88
  🧪 Bun Test UI - A beautiful UI for running Bun tests
@@ -66,33 +101,18 @@ Examples:
66
101
  `);
67
102
  }
68
103
 
69
- async function checkBuildExists(): Promise<boolean> {
70
- const distPath = join(packageRoot, "app", "dist", "index.html");
104
+ async function checkBuildExists(root: string): Promise<boolean> {
105
+ const distPath = join(root, "app", "dist", "index.html");
71
106
 
72
107
  console.log(`🔍 Debug Info:`);
73
108
  console.log(` - process.argv[1]: ${process.argv[1]}`);
74
- console.log(` - Resolved packageRoot: ${packageRoot}`);
109
+ console.log(` - Resolved packageRoot: ${root}`);
75
110
  console.log(` - Looking for: ${distPath}`);
76
111
 
77
112
  try {
78
113
  const exists = await Bun.file(distPath).exists();
79
114
  if (!exists) {
80
115
  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
116
  } else {
97
117
  console.log(` - File exists: YES ✓`);
98
118
  }
@@ -104,8 +124,11 @@ async function checkBuildExists(): Promise<boolean> {
104
124
  }
105
125
 
106
126
  async function runTestUI() {
127
+ // Encontra o root real onde estão os arquivos
128
+ packageRoot = await findVerifiedRoot();
129
+
107
130
  // Verifica se o build do frontend existe
108
- const buildExists = await checkBuildExists();
131
+ const buildExists = await checkBuildExists(packageRoot);
109
132
 
110
133
  if (!buildExists) {
111
134
  console.log("\n⚠️ Frontend assets not found.\n");
@@ -160,6 +183,9 @@ async function runTestUI() {
160
183
  }
161
184
 
162
185
  async function runDevMode() {
186
+ // Encontra o root real onde estão os arquivos
187
+ packageRoot = await findVerifiedRoot();
188
+
163
189
  console.log("🚀 Starting Bun Test UI (Development Mode)...\n");
164
190
  console.log("📡 WebSocket server: ws://localhost:5060");
165
191
  console.log("🌐 Frontend: http://localhost:5050 (with hot reload)\n");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bun-ui-tests",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "A beautiful UI for running Bun tests",
5
5
  "type": "module",
6
6
  "bin": {
package/ui-runner.ts CHANGED
@@ -14,24 +14,35 @@
14
14
  import { spawn } from "node:child_process";
15
15
  import { readdir, readFile, stat } from "node:fs/promises";
16
16
  import { join, relative, dirname } from "node:path";
17
+ import { fileURLToPath } from "node:url";
17
18
 
18
19
  // Determina o diretório do executável ou script
19
20
  const getBaseDir = () => {
20
- // Se rodando como executável compilado, pega o diretório onde o CLI foi instalado
21
- if (import.meta.path && !import.meta.path.endsWith('.ts')) {
22
- return dirname(process.execPath);
21
+ // 1. Tentar import.meta.dir (Bun específico)
22
+ if (import.meta.dir) {
23
+ return import.meta.dir;
23
24
  }
25
+
26
+ // 2. Tentar via import.meta.url
27
+ try {
28
+ const __filename = fileURLToPath(import.meta.url);
29
+ return dirname(__filename);
30
+ } catch (e) {}
24
31
 
25
- // Try process.argv[1] to find real path
32
+ // 3. Try process.argv[1] to find real path
26
33
  try {
27
34
  const argvPath = process.argv[1];
28
- if (argvPath && argvPath.endsWith("ui-runner.ts")) {
35
+ if (argvPath) {
36
+ // Se rodando como executável compilado, pega o diretório onde o CLI foi instalado
37
+ if (import.meta.path && !import.meta.path.endsWith('.ts')) {
38
+ return dirname(process.execPath);
39
+ }
29
40
  return dirname(argvPath);
30
41
  }
31
42
  } catch (e) {}
32
43
 
33
- // Se rodando como script .ts, usa o dir do próprio arquivo
34
- return import.meta.dir;
44
+ // Se tudo falhar
45
+ return process.cwd();
35
46
  };
36
47
 
37
48
  const baseDir = getBaseDir();