fix: nested index route not working in prod builds (#3132)
This was due to a mismatch in the disk snapshot compared to in memory.
This commit is contained in:
+38
-1
@@ -3,7 +3,8 @@ import * as path from "@std/path";
|
||||
import { Builder, specToName } from "./builder.ts";
|
||||
import { App } from "../app.ts";
|
||||
import { BUILD_ID } from "../runtime/build_id.ts";
|
||||
import { withTmpDir } from "../test_utils.ts";
|
||||
import { withTmpDir, writeFiles } from "../test_utils.ts";
|
||||
import { withChildProcessServer } from "../../tests/test_utils.tsx";
|
||||
|
||||
Deno.test({
|
||||
name: "Builder - chain onTransformStaticFile",
|
||||
@@ -241,6 +242,42 @@ Deno.test({
|
||||
sanitizeResources: false,
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "Builder - write prod routePattern",
|
||||
fn: async () => {
|
||||
const root = path.join(import.meta.dirname!, "..", "..");
|
||||
await using _tmp = await withTmpDir({ dir: root, prefix: "tmp_builder_" });
|
||||
const tmp = _tmp.dir;
|
||||
|
||||
await writeFiles(tmp, {
|
||||
"routes/foo/index.ts": `export const handler = () => new Response("ok")`,
|
||||
"main.ts": `import { App } from "fresh";
|
||||
export const app = new App().fsRoutes()`,
|
||||
});
|
||||
|
||||
const builder = new Builder({
|
||||
root: tmp,
|
||||
outDir: path.join(tmp, "dist"),
|
||||
});
|
||||
|
||||
await builder.build();
|
||||
|
||||
let text = "fail";
|
||||
await withChildProcessServer(
|
||||
tmp,
|
||||
["serve", "-A", "dist/server.js"],
|
||||
async (address) => {
|
||||
const res = await fetch(`${address}/foo`);
|
||||
text = await res.text();
|
||||
},
|
||||
);
|
||||
|
||||
expect(text).toEqual("ok");
|
||||
},
|
||||
sanitizeOps: false,
|
||||
sanitizeResources: false,
|
||||
});
|
||||
|
||||
Deno.test("specToName", () => {
|
||||
// HTTP
|
||||
expect(specToName("http://example.com")).toEqual("example");
|
||||
|
||||
@@ -405,10 +405,10 @@ ${
|
||||
.map((item, i) => {
|
||||
const id = JSON.stringify(item.id);
|
||||
const pattern = JSON.stringify(item.pattern);
|
||||
const type = JSON.stringify(item.type);
|
||||
const routePattern = JSON.stringify(item.routePattern);
|
||||
|
||||
return ` { id: ${id}, mod: fsRoute_${i}, type: ${
|
||||
JSON.stringify(item.type)
|
||||
}, pattern: ${pattern} },`;
|
||||
return ` { id: ${id}, mod: fsRoute_${i}, type: ${type}, pattern: ${pattern}, routePattern: ${routePattern} },`;
|
||||
})
|
||||
.join("\n")
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import type { WalkEntry } from "@std/fs/walk";
|
||||
import { DEFAULT_CONN_INFO } from "./app.ts";
|
||||
import type { Command } from "./commands.ts";
|
||||
import { fsItemsToCommands, type FsRouteFile } from "./fs_routes.ts";
|
||||
import * as path from "@std/path";
|
||||
|
||||
const STUB = {} as unknown as Deno.ServeHandlerInfo;
|
||||
|
||||
@@ -159,3 +160,19 @@ export class MockBuildCache<State> implements BuildCache<State> {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
}
|
||||
|
||||
export async function writeFiles(dir: string, files: Record<string, string>) {
|
||||
const entries = Object.entries(files);
|
||||
await Promise.all(entries.map(async (entry) => {
|
||||
const [pathname, content] = entry;
|
||||
const fullPath = path.join(dir, pathname);
|
||||
try {
|
||||
await Deno.mkdir(path.dirname(fullPath), { recursive: true });
|
||||
await Deno.writeTextFile(fullPath, content);
|
||||
} catch (err) {
|
||||
if (!(err instanceof Deno.errors.AlreadyExists)) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user