-
Notifications
You must be signed in to change notification settings - Fork 750
Expand file tree
/
Copy pathconfig_test.ts
More file actions
107 lines (92 loc) · 3.71 KB
/
config_test.ts
File metadata and controls
107 lines (92 loc) · 3.71 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { expect } from "@std/expect";
import { normalizeConfig, parseRootPath } from "./config.ts";
import type { FreshConfig } from "./mod.ts";
Deno.test("parseRootPath", () => {
const cwd = Deno.cwd().replaceAll("\\", "/");
// File paths
expect(parseRootPath("file:///foo/bar", cwd)).toEqual("/foo/bar");
expect(parseRootPath("file:///foo/bar.ts", cwd)).toEqual("/foo");
if (Deno.build.os === "windows") {
expect(parseRootPath("file:///C:/foo/bar", cwd)).toEqual("C:/foo/bar");
expect(parseRootPath("file:///C:/foo/bar.ts", cwd)).toEqual("C:/foo");
}
// Relative paths
expect(parseRootPath("./foo/bar", cwd)).toEqual(`${cwd}/foo/bar`);
expect(parseRootPath("./foo/bar.ts", cwd)).toEqual(`${cwd}/foo`);
// Absolute paths
expect(parseRootPath("/foo/bar", cwd)).toEqual("/foo/bar");
expect(parseRootPath("/foo/bar.ts", cwd)).toEqual("/foo");
expect(parseRootPath("/foo/bar.tsx", cwd)).toEqual("/foo");
expect(parseRootPath("/foo/bar.js", cwd)).toEqual("/foo");
expect(parseRootPath("/foo/bar.jsx", cwd)).toEqual("/foo");
expect(parseRootPath("/foo/bar.mjs", cwd)).toEqual("/foo");
if (Deno.build.os === "windows") {
expect(parseRootPath("C:/foo/bar", cwd)).toEqual("C:/foo/bar");
expect(parseRootPath("C:/foo/bar.ts", cwd)).toEqual("C:/foo");
}
});
Deno.test("normalizeConfig - root", () => {
const cwd = Deno.cwd().replaceAll("\\", "/");
const configRoot = (root?: string) => normalizeConfig({ root }).root;
expect(configRoot()).toEqual(cwd);
expect(configRoot("/foo/bar")).toEqual("/foo/bar");
expect(configRoot("/foo/bar.ts")).toEqual("/foo");
expect(configRoot("file:///foo/bar")).toEqual("/foo/bar");
expect(configRoot("./foo/bar")).toEqual(`${cwd}/foo/bar`);
expect(configRoot("./foo/bar.ts")).toEqual(`${cwd}/foo`);
if (Deno.build.os === "windows") {
expect(configRoot("C:/foo/bar.ts")).toEqual("C:/foo");
expect(configRoot("file:///C:/foo/bar")).toEqual("C:/foo/bar");
}
});
Deno.test("normalizeConfig - build.outDir", () => {
const cwd = Deno.cwd().replaceAll("\\", "/");
const outDir = (options: FreshConfig) => normalizeConfig(options).buildOutDir;
// Default outDir
expect(outDir({ root: "./src" })).toEqual(`${cwd}/src/_fresh`);
expect(outDir({ root: "/src" })).toEqual("/src/_fresh");
expect(outDir({ root: "file:///src" })).toEqual("/src/_fresh");
// Relative outDir
expect(outDir({ root: "/src", buildOutDir: "dist" })).toEqual(
"/src/dist",
);
expect(outDir({ root: "/src", buildOutDir: "./dist" })).toEqual(
"/src/dist",
);
// Absolute outDir
expect(outDir({ root: "/src", buildOutDir: "/dist" })).toEqual(
"/dist",
);
expect(outDir({ root: "/src", buildOutDir: "/dist/fresh" })).toEqual(
"/dist/fresh",
);
expect(outDir({ root: "/src", buildOutDir: "file:///dist" })).toEqual(
"/dist",
);
});
Deno.test("normalizeConfig - staticDir", () => {
const cwd = Deno.cwd().replaceAll("\\", "/");
const staticDir = (options: FreshConfig) =>
normalizeConfig(options).staticDir;
// Default staticDir
expect(staticDir({ root: "./src" })).toEqual(`${cwd}/src/static`);
expect(staticDir({ root: "/src" })).toEqual("/src/static");
expect(staticDir({ root: "file:///src" })).toEqual("/src/static");
// Relative staticDir
expect(staticDir({ root: "/src", staticDir: "public" })).toEqual(
"/src/public",
);
expect(staticDir({ root: "/src", staticDir: "./public" })).toEqual(
"/src/public",
);
// Absolute staticDir
expect(staticDir({ root: "/src", staticDir: "/public" })).toEqual(
"/public",
);
expect(staticDir({ root: "/src", staticDir: "/public/assets" })).toEqual(
"/public/assets",
);
expect(staticDir({ root: "/src", staticDir: "file:///public" })).toEqual(
"/public",
);
});