Support AOT-built static assets (#1999)
Creates a static folder under `config.build.outDir` during AOT build. Serves any static files that are found there. --------- Co-authored-by: Marvin Hagemeister <marvin@deno.com>
This commit is contained in:
co-authored by
Marvin Hagemeister
parent
d655386617
commit
264f3073bd
@@ -1,14 +1,17 @@
|
||||
import * as path from "$std/path/mod.ts";
|
||||
import {
|
||||
assert,
|
||||
assertEquals,
|
||||
assertNotMatch,
|
||||
assertStringIncludes,
|
||||
puppeteer,
|
||||
} from "./deps.ts";
|
||||
import {
|
||||
getStdOutput,
|
||||
recreateFolder,
|
||||
startFreshServer,
|
||||
waitForText,
|
||||
withFakeServe,
|
||||
} from "$fresh/tests/test_utils.ts";
|
||||
import { BuildSnapshotJson } from "$fresh/src/build/mod.ts";
|
||||
|
||||
@@ -258,3 +261,47 @@ Deno.test("pass target options", async () => {
|
||||
`Asset contained ?? despite target es2015\n\n${stdout}\n${stderr}`,
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("serve static files from build dir", async () => {
|
||||
const filePath = path.join(
|
||||
path.dirname(path.fromFileUrl(import.meta.url)),
|
||||
"fixture_build_static",
|
||||
"_fresh",
|
||||
"static",
|
||||
"foo.txt",
|
||||
);
|
||||
|
||||
await recreateFolder(path.dirname(filePath));
|
||||
await Deno.writeTextFile(filePath, `it works`);
|
||||
|
||||
await withFakeServe(
|
||||
"./tests/fixture_build_static/main.ts",
|
||||
async (server) => {
|
||||
const res = await server.get("/foo.txt");
|
||||
const text = await res.text();
|
||||
assertEquals(text, "it works");
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("prefer static files from build dir", async () => {
|
||||
const filePath = path.join(
|
||||
path.dirname(path.fromFileUrl(import.meta.url)),
|
||||
"fixture_build_static",
|
||||
"_fresh",
|
||||
"static",
|
||||
"duplicate.txt",
|
||||
);
|
||||
|
||||
await recreateFolder(path.dirname(filePath));
|
||||
await Deno.writeTextFile(filePath, "it works");
|
||||
|
||||
await withFakeServe(
|
||||
"./tests/fixture_build_static/main.ts",
|
||||
async (server) => {
|
||||
const res = await server.get("/duplicate.txt");
|
||||
const text = await res.text();
|
||||
assertEquals(text, "it works");
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user