|
1 | 1 | import { expect } from "@std/expect"; |
2 | | -import { parseRootPath } from "./config.ts"; |
| 2 | +import { normalizeConfig, parseRootPath } from "./config.ts"; |
| 3 | +import type { FreshConfig } from "./mod.ts"; |
3 | 4 |
|
4 | | -// FIXME: Windows |
5 | | -Deno.test.ignore("parseRootPath", () => { |
6 | | - const cwd = Deno.cwd(); |
| 5 | +Deno.test("parseRootPath", () => { |
| 6 | + const cwd = Deno.cwd().replaceAll("\\", "/"); |
| 7 | + |
| 8 | + // File paths |
7 | 9 | expect(parseRootPath("file:///foo/bar", cwd)).toEqual("/foo/bar"); |
8 | 10 | expect(parseRootPath("file:///foo/bar.ts", cwd)).toEqual("/foo"); |
| 11 | + if (Deno.build.os === "windows") { |
| 12 | + expect(parseRootPath("file:///C:/foo/bar", cwd)).toEqual("C:/foo/bar"); |
| 13 | + expect(parseRootPath("file:///C:/foo/bar.ts", cwd)).toEqual("C:/foo"); |
| 14 | + } |
| 15 | + |
| 16 | + // Relative paths |
| 17 | + expect(parseRootPath("./foo/bar", cwd)).toEqual(`${cwd}/foo/bar`); |
| 18 | + expect(parseRootPath("./foo/bar.ts", cwd)).toEqual(`${cwd}/foo`); |
| 19 | + |
| 20 | + // Absolute paths |
9 | 21 | expect(parseRootPath("/foo/bar", cwd)).toEqual("/foo/bar"); |
10 | 22 | expect(parseRootPath("/foo/bar.ts", cwd)).toEqual("/foo"); |
11 | 23 | expect(parseRootPath("/foo/bar.tsx", cwd)).toEqual("/foo"); |
12 | 24 | expect(parseRootPath("/foo/bar.js", cwd)).toEqual("/foo"); |
13 | 25 | expect(parseRootPath("/foo/bar.jsx", cwd)).toEqual("/foo"); |
14 | 26 | expect(parseRootPath("/foo/bar.mjs", cwd)).toEqual("/foo"); |
| 27 | + if (Deno.build.os === "windows") { |
| 28 | + expect(parseRootPath("C:/foo/bar", cwd)).toEqual("C:/foo/bar"); |
| 29 | + expect(parseRootPath("C:/foo/bar.ts", cwd)).toEqual("C:/foo"); |
| 30 | + } |
| 31 | +}); |
| 32 | + |
| 33 | +Deno.test("normalizeConfig - root", () => { |
| 34 | + const cwd = Deno.cwd().replaceAll("\\", "/"); |
| 35 | + const configRoot = (root?: string) => normalizeConfig({ root }).root; |
| 36 | + |
| 37 | + expect(configRoot()).toEqual(cwd); |
| 38 | + expect(configRoot("/foo/bar")).toEqual("/foo/bar"); |
| 39 | + expect(configRoot("/foo/bar.ts")).toEqual("/foo"); |
| 40 | + expect(configRoot("file:///foo/bar")).toEqual("/foo/bar"); |
| 41 | + expect(configRoot("./foo/bar")).toEqual(`${cwd}/foo/bar`); |
| 42 | + expect(configRoot("./foo/bar.ts")).toEqual(`${cwd}/foo`); |
| 43 | + |
| 44 | + if (Deno.build.os === "windows") { |
| 45 | + expect(configRoot("C:/foo/bar.ts")).toEqual("C:/foo"); |
| 46 | + expect(configRoot("file:///C:/foo/bar")).toEqual("C:/foo/bar"); |
| 47 | + } |
| 48 | +}); |
| 49 | + |
| 50 | +Deno.test("normalizeConfig - build.outDir", () => { |
| 51 | + const cwd = Deno.cwd().replaceAll("\\", "/"); |
| 52 | + const outDir = (options: FreshConfig) => |
| 53 | + normalizeConfig(options).build.outDir; |
| 54 | + |
| 55 | + // Default outDir |
| 56 | + expect(outDir({ root: "./src" })).toEqual(`${cwd}/src/_fresh`); |
| 57 | + expect(outDir({ root: "/src" })).toEqual("/src/_fresh"); |
| 58 | + expect(outDir({ root: "file:///src" })).toEqual("/src/_fresh"); |
| 59 | + |
| 60 | + // Relative outDir |
| 61 | + expect(outDir({ root: "/src", build: { outDir: "dist" } })).toEqual( |
| 62 | + "/src/dist", |
| 63 | + ); |
| 64 | + expect(outDir({ root: "/src", build: { outDir: "./dist" } })).toEqual( |
| 65 | + "/src/dist", |
| 66 | + ); |
| 67 | + |
| 68 | + // Absolute outDir |
| 69 | + expect(outDir({ root: "/src", build: { outDir: "/dist" } })).toEqual( |
| 70 | + "/dist", |
| 71 | + ); |
| 72 | + expect(outDir({ root: "/src", build: { outDir: "/dist/fresh" } })).toEqual( |
| 73 | + "/dist/fresh", |
| 74 | + ); |
| 75 | + expect(outDir({ root: "/src", build: { outDir: "file:///dist" } })).toEqual( |
| 76 | + "/dist", |
| 77 | + ); |
| 78 | +}); |
| 79 | + |
| 80 | +Deno.test("normalizeConfig - staticDir", () => { |
| 81 | + const cwd = Deno.cwd().replaceAll("\\", "/"); |
| 82 | + const staticDir = (options: FreshConfig) => |
| 83 | + normalizeConfig(options).staticDir; |
| 84 | + |
| 85 | + // Default staticDir |
| 86 | + expect(staticDir({ root: "./src" })).toEqual(`${cwd}/src/static`); |
| 87 | + expect(staticDir({ root: "/src" })).toEqual("/src/static"); |
| 88 | + expect(staticDir({ root: "file:///src" })).toEqual("/src/static"); |
| 89 | + |
| 90 | + // Relative staticDir |
| 91 | + expect(staticDir({ root: "/src", staticDir: "public" })).toEqual( |
| 92 | + "/src/public", |
| 93 | + ); |
| 94 | + expect(staticDir({ root: "/src", staticDir: "./public" })).toEqual( |
| 95 | + "/src/public", |
| 96 | + ); |
| 97 | + |
| 98 | + // Absolute staticDir |
| 99 | + expect(staticDir({ root: "/src", staticDir: "/public" })).toEqual( |
| 100 | + "/public", |
| 101 | + ); |
| 102 | + expect(staticDir({ root: "/src", staticDir: "/public/assets" })).toEqual( |
| 103 | + "/public/assets", |
| 104 | + ); |
| 105 | + expect(staticDir({ root: "/src", staticDir: "file:///public" })).toEqual( |
| 106 | + "/public", |
| 107 | + ); |
15 | 108 | }); |
0 commit comments