-
Notifications
You must be signed in to change notification settings - Fork 742
Expand file tree
/
Copy pathdev_build_cache_test.ts
More file actions
44 lines (41 loc) · 1.53 KB
/
dev_build_cache_test.ts
File metadata and controls
44 lines (41 loc) · 1.53 KB
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
import { expect } from "@std/expect";
import * as path from "@std/path";
import { MemoryBuildCache } from "./dev_build_cache.ts";
import { FreshFileTransformer } from "./file_transformer.ts";
import type { ResolvedFreshConfig } from "../mod.ts";
Deno.test({
name: "MemoryBuildCache - should error if reading outside of staticDir",
fn: async () => {
const tmp = await Deno.makeTempDir();
const config: ResolvedFreshConfig = {
root: tmp,
mode: "development",
basePath: "/",
staticDir: path.join(tmp, "static"),
build: {
outDir: path.join(tmp, "dist"),
},
};
const fileTransformer = new FreshFileTransformer();
const buildCache = new MemoryBuildCache(
config,
"testing",
fileTransformer,
"latest",
);
const thrown = buildCache.readFile("../SECRETS.txt");
const thrown2 = buildCache.readFile("./../../SECRETS.txt");
const noThrown = buildCache.readFile("styles.css");
const noThrown2 = buildCache.readFile(".well-known/foo.txt");
const noThrown3 = buildCache.readFile("./styles.css");
const noThrown4 = buildCache.readFile("./.well-known/foo.txt");
await buildCache.flush();
const err = "Processed file resolved outside of static dir";
await expect(thrown).rejects.toThrow(err);
await expect(thrown2).rejects.toThrow(err);
await expect(noThrown).resolves.toBe(null);
await expect(noThrown2).resolves.toBe(null);
await expect(noThrown3).resolves.toBe(null);
await expect(noThrown4).resolves.toBe(null);
},
});