Update tests

This commit is contained in:
2026-03-21 10:14:38 +01:00
parent cf010ad4f5
commit d2ddaef0d4
26 changed files with 798 additions and 101 deletions
+1 -5
View File
@@ -2,9 +2,7 @@ import handleWebPages from "./web-pages/handle-web-pages";
import handleRoutes from "./handle-routes";
import isDevelopment from "../../utils/is-development";
import grabConstants from "../../utils/grab-constants";
import { AppData } from "../../data/app-data";
import handleHmr from "./handle-hmr";
import handleHmrUpdate from "./handle-hmr-update";
import handlePublic from "./handle-public";
import handleFiles from "./handle-files";
type Params = {
@@ -39,9 +37,7 @@ export default async function bunextRequestHandler({
}
}
if (url.pathname == `/${AppData["ClientHMRPath"]}`) {
response = await handleHmrUpdate({ req });
} else if (url.pathname === "/__hmr" && is_dev) {
if (url.pathname === "/__hmr" && is_dev) {
response = await handleHmr({ req });
} else if (url.pathname.startsWith("/api/")) {
response = await handleRoutes({ req });
-82
View File
@@ -1,82 +0,0 @@
import grabDirNames from "../../utils/grab-dir-names";
import { AppData } from "../../data/app-data";
import path from "path";
import grabRootFile from "./web-pages/grab-root-file";
import grabPageBundledReactComponent from "./web-pages/grab-page-bundled-react-component";
import writeHMRTsxModule from "./web-pages/write-hmr-tsx-module";
const { BUNX_HYDRATION_SRC_DIR } = grabDirNames();
type Params = {
req: Request;
};
export default async function ({ req }: Params): Promise<Response> {
try {
const url = new URL(req.url);
const target_href = url.searchParams.get("href");
if (!target_href) {
return new Response(
`No HREF passed to /${AppData["ClientHMRPath"]}`,
{ status: 404 },
);
}
const target_href_url = new URL(target_href);
const match = global.ROUTER.match(target_href_url.pathname);
if (!match?.filePath) {
return new Response(`No pages file matched for this path`, {
status: 404,
});
}
const out_file = path.join(
BUNX_HYDRATION_SRC_DIR,
target_href_url.pathname,
"index.js",
);
const { root_file } = grabRootFile();
const { tsx } =
(await grabPageBundledReactComponent({
file_path: match.filePath,
root_file,
})) || {};
if (!tsx) {
throw new Error(`Couldn't grab txt string`);
}
const artifact = await writeHMRTsxModule({
tsx,
out_file,
});
const file = Bun.file(out_file);
if (await file.exists()) {
return new Response(file, {
headers: {
"Content-Type": "text/javascript",
},
});
}
return new Response("Not found", {
status: 404,
});
} catch (error: any) {
const error_msg = error.message;
console.error(error_msg);
return new Response(error_msg || "HMR Error", {
status: 404,
});
}
}
@@ -47,6 +47,11 @@ export default async function grabPageErrorComponent({
routeParams,
module,
bundledMap,
serverRes: {
responseOptions: {
status: is404 ? 404 : 500
}
} as any
};
} catch {
const DefaultNotFound: FC = () => (
@@ -70,6 +75,11 @@ export default async function grabPageErrorComponent({
routeParams,
module: { default: DefaultNotFound },
bundledMap: {} as BundlerCTXMap,
serverRes: {
responseOptions: {
status: is404 ? 404 : 500
}
} as any
};
}
}