bun-ui-tests 1.0.3 → 1.0.5

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 +26 -6
  2. package/package.json +1 -1
  3. package/ui-runner.ts +21 -21
package/cli.ts CHANGED
@@ -2,10 +2,25 @@
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
- const __dirname = import.meta.dir;
8
+ // Robustly determine the package root directory
9
+ function getPackageRoot() {
10
+ // 1. Try to use process.argv[1] which often points to the real script path
11
+ // when run via bunx or direct execution.
12
+ try {
13
+ const argvPath = process.argv[1];
14
+ if (argvPath && argvPath.endsWith("cli.ts")) {
15
+ return dirname(argvPath);
16
+ }
17
+ } catch (e) {}
18
+
19
+ // 2. Fallback to import.meta.dir
20
+ return import.meta.dir;
21
+ }
22
+
23
+ const __dirname = getPackageRoot();
9
24
 
10
25
  const COMMANDS = {
11
26
  run: "Run the test UI (production mode)",
@@ -60,11 +75,16 @@ async function buildFrontend() {
60
75
 
61
76
  async function checkBuildExists(): Promise<boolean> {
62
77
  const distPath = join(__dirname, "app", "dist", "index.html");
78
+ console.error(`Debug: process.argv[1] is ${process.argv[1]}`);
79
+ console.error(`Debug: Resolved __dirname is ${__dirname}`);
63
80
  try {
64
- await access(distPath);
65
- return true;
66
- } catch {
67
- console.error(`Debug: Checked path not found: ${distPath}`);
81
+ const exists = await Bun.file(distPath).exists();
82
+ if (!exists) {
83
+ console.error(`Debug: Bun.file.exists failed for: ${distPath}`);
84
+ }
85
+ return exists;
86
+ } catch (err) {
87
+ console.error(`Debug: Error checking path ${distPath}:`, err);
68
88
  return false;
69
89
  }
70
90
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bun-ui-tests",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "A beautiful UI for running Bun tests",
5
5
  "type": "module",
6
6
  "bin": {
package/ui-runner.ts CHANGED
@@ -14,7 +14,6 @@
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 { existsSync } from "node:fs";
18
17
 
19
18
  // Determina o diretório do executável ou script
20
19
  const getBaseDir = () => {
@@ -22,12 +21,22 @@ const getBaseDir = () => {
22
21
  if (import.meta.path && !import.meta.path.endsWith('.ts')) {
23
22
  return dirname(process.execPath);
24
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
+
25
33
  // Se rodando como script .ts, usa o dir do próprio arquivo
26
34
  return import.meta.dir;
27
35
  };
28
36
 
29
37
  const baseDir = getBaseDir();
30
38
  const distPath = join(baseDir, "app", "dist");
39
+ console.log(`Debug: ui-runner argv[1] is ${process.argv[1]}`);
31
40
  console.log(`Debug: distPath is ${distPath}`);
32
41
  const isDevMode = process.env.BUN_TEST_UI_DEV === "true";
33
42
 
@@ -128,29 +137,20 @@ if (isDevMode) {
128
137
  }
129
138
 
130
139
  // 2. Arquivos Estáticos (Frontend)
131
- if (existsSync(distPath)) {
132
- let filePath = url.pathname === "/" ? "/index.html" : url.pathname;
133
- const fullPath = join(distPath, filePath);
134
-
135
- try {
136
- const file = Bun.file(fullPath);
137
- if (await file.exists()) {
138
- return new Response(file);
139
- }
140
-
141
- // Se não encontrou o arquivo e não é um asset (SPA fallback)
142
- if (!filePath.includes(".")) {
143
- const indexFile = Bun.file(join(distPath, "index.html"));
144
- return new Response(indexFile);
145
- }
146
- } catch (err) {
147
- console.error("Error serving file:", err);
140
+ const file = Bun.file(join(distPath, url.pathname === "/" ? "/index.html" : url.pathname));
141
+ if (await file.exists()) {
142
+ return new Response(file);
143
+ }
144
+
145
+ // SPA fallback
146
+ if (!url.pathname.includes(".")) {
147
+ const indexFile = Bun.file(join(distPath, "index.html"));
148
+ if (await indexFile.exists()) {
149
+ return new Response(indexFile);
148
150
  }
149
- } else {
150
- return new Response("Frontend build not found. Run 'buntestui build' first.", { status: 404 });
151
151
  }
152
152
 
153
- return new Response("Not found", { status: 404 });
153
+ return new Response("Frontend build not found.", { status: 404 });
154
154
  },
155
155
  websocket: websocketHandler
156
156
  });