forked from denoland/fresh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatic_test.ts
65 lines (57 loc) · 1.72 KB
/
static_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { assertEquals, dirname, fromFileUrl, join } from "./deps.ts";
import { withFakeServe } from "./test_utils.ts";
Deno.test("don't fallthrough to /_fresh/static in dev", async () => {
const fixtureDir = join(
dirname(fromFileUrl(import.meta.url)),
"fixture_static",
);
try {
await Deno.mkdir(join(fixtureDir, "_fresh", "static"), { recursive: true });
} catch (_err) {
// ignore
}
await Deno.writeTextFile(
join(fixtureDir, "_fresh", "static", "style.css"),
"h1 { color: blue; }",
);
await withFakeServe(
"./tests/fixture_static/dev.ts",
async (server) => {
const res = await server.get(`/style.css`);
const css = await res.text();
assertEquals(css.replace(/\s+/g, ""), "h1{color:red;}");
},
);
await Deno.remove(join(fixtureDir, "_fresh", "static", "style.css"));
await withFakeServe(
"./tests/fixture_static/dev.ts",
async (server) => {
const res = await server.get(`/style.css`);
const css = await res.text();
assertEquals(css.replace(/\s+/g, ""), "h1{color:red;}");
},
);
});
Deno.test("fallthrough to /_fresh/static in normal mode", async () => {
const fixtureDir = join(
dirname(fromFileUrl(import.meta.url)),
"fixture_static",
);
try {
await Deno.mkdir(join(fixtureDir, "_fresh", "static"), { recursive: true });
} catch (_err) {
// ignore
}
await Deno.writeTextFile(
join(fixtureDir, "_fresh", "static", "style.css"),
"h1 { color: blue; }",
);
await withFakeServe(
"./tests/fixture_static/main.ts",
async (server) => {
const res = await server.get(`/style.css`);
const css = await res.text();
assertEquals(css.replace(/\s+/g, ""), "h1{color:blue;}");
},
);
});