bun-ui-tests 1.0.2 → 1.0.4

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 +12 -7
  2. package/package.json +1 -1
  3. package/ui-runner.ts +14 -28
package/cli.ts CHANGED
@@ -1,12 +1,11 @@
1
1
  #!/usr/bin/env bun
2
2
 
3
3
  import { spawn } from "node:child_process";
4
- import { readFile, access, realpath } from "node:fs/promises";
4
+ import { readFile, access } from "node:fs/promises";
5
5
  import { join, dirname } from "node:path";
6
6
  import { fileURLToPath } from "node:url";
7
7
 
8
- const __filename = await realpath(fileURLToPath(import.meta.url));
9
- const __dirname = dirname(__filename);
8
+ const __dirname = import.meta.dir;
10
9
 
11
10
  const COMMANDS = {
12
11
  run: "Run the test UI (production mode)",
@@ -60,11 +59,17 @@ async function buildFrontend() {
60
59
  }
61
60
 
62
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}`);
63
65
  try {
64
- const distPath = join(__dirname, "app", "dist", "index.html");
65
- await access(distPath);
66
- return true;
67
- } catch {
66
+ const exists = await Bun.file(distPath).exists();
67
+ if (!exists) {
68
+ console.error(`Debug: Bun.file.exists failed for: ${distPath}`);
69
+ }
70
+ return exists;
71
+ } catch (err) {
72
+ console.error(`Debug: Error checking path ${distPath}:`, err);
68
73
  return false;
69
74
  }
70
75
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bun-ui-tests",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "A beautiful UI for running Bun tests",
5
5
  "type": "module",
6
6
  "bin": {
package/ui-runner.ts CHANGED
@@ -14,25 +14,20 @@
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";
18
- import { existsSync, realpathSync } from "node:fs";
19
17
 
20
18
  // Determina o diretório do executável ou script
21
19
  const getBaseDir = () => {
22
20
  // Se rodando como executável compilado, pega o diretório onde o CLI foi instalado
23
- // O executável fica na raiz do pacote, então app/dist fica relativo a ele
24
21
  if (import.meta.path && !import.meta.path.endsWith('.ts')) {
25
- // É um executável compilado - usa process.execPath (path real do executável)
26
- // import.meta.path retorna um path virtual do bunfs
27
22
  return dirname(process.execPath);
28
23
  }
29
- // Se rodando como script .ts em dev, usa o dirname do próprio arquivo
30
- const __filename = realpathSync(fileURLToPath(import.meta.url));
31
- return dirname(__filename);
24
+ // Se rodando como script .ts, usa o dir do próprio arquivo
25
+ return import.meta.dir;
32
26
  };
33
27
 
34
28
  const baseDir = getBaseDir();
35
29
  const distPath = join(baseDir, "app", "dist");
30
+ console.log(`Debug: distPath is ${distPath}`);
36
31
  const isDevMode = process.env.BUN_TEST_UI_DEV === "true";
37
32
 
38
33
  // WebSocket Handler (lógica compartilhada)
@@ -132,29 +127,20 @@ if (isDevMode) {
132
127
  }
133
128
 
134
129
  // 2. Arquivos Estáticos (Frontend)
135
- if (existsSync(distPath)) {
136
- let filePath = url.pathname === "/" ? "/index.html" : url.pathname;
137
- const fullPath = join(distPath, filePath);
138
-
139
- try {
140
- const file = Bun.file(fullPath);
141
- if (await file.exists()) {
142
- return new Response(file);
143
- }
144
-
145
- // Se não encontrou o arquivo e não é um asset (SPA fallback)
146
- if (!filePath.includes(".")) {
147
- const indexFile = Bun.file(join(distPath, "index.html"));
148
- return new Response(indexFile);
149
- }
150
- } catch (err) {
151
- console.error("Error serving file:", err);
130
+ const file = Bun.file(join(distPath, url.pathname === "/" ? "/index.html" : url.pathname));
131
+ if (await file.exists()) {
132
+ return new Response(file);
133
+ }
134
+
135
+ // SPA fallback
136
+ if (!url.pathname.includes(".")) {
137
+ const indexFile = Bun.file(join(distPath, "index.html"));
138
+ if (await indexFile.exists()) {
139
+ return new Response(indexFile);
152
140
  }
153
- } else {
154
- return new Response("Frontend build not found. Run 'buntestui build' first.", { status: 404 });
155
141
  }
156
142
 
157
- return new Response("Not found", { status: 404 });
143
+ return new Response("Frontend build not found.", { status: 404 });
158
144
  },
159
145
  websocket: websocketHandler
160
146
  });