Skip to content

Commit 1369c62

Browse files
committed
test: enable parseRootPath test and fix windows issues
1 parent 2b0f76b commit 1369c62

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

src/config.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@ export function parseRootPath(root: string, cwd: string): string {
4949
root = path.dirname(root);
5050
}
5151

52+
if (Deno.build.os === "windows") {
53+
root = root.replaceAll("\\", "/");
54+
}
55+
5256
return root;
5357
}
5458

5559
export function normalizeConfig(options: FreshConfig): ResolvedFreshConfig {
56-
const root = options.root
57-
? parseRootPath(options.root, Deno.cwd())
58-
: Deno.cwd();
60+
const root = parseRootPath(options.root ?? ".", Deno.cwd());
5961

6062
return {
6163
root,

src/config_test.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
import { expect } from "@std/expect";
22
import { parseRootPath } from "./config.ts";
33

4-
// FIXME: Windows
5-
Deno.test.ignore("parseRootPath", () => {
6-
const cwd = Deno.cwd();
4+
Deno.test("parseRootPath", () => {
5+
const cwd = Deno.cwd().replaceAll("\\", "/");
6+
7+
// File paths
78
expect(parseRootPath("file:///foo/bar", cwd)).toEqual("/foo/bar");
89
expect(parseRootPath("file:///foo/bar.ts", cwd)).toEqual("/foo");
10+
expect(parseRootPath("file:///C:/foo/bar", cwd)).toEqual("C:/foo/bar");
11+
expect(parseRootPath("file:///C:/foo/bar.ts", cwd)).toEqual("C:/foo");
12+
13+
// Relative paths
14+
expect(parseRootPath("./foo/bar", cwd)).toEqual(`${cwd}/foo/bar`);
15+
expect(parseRootPath("./foo/bar.ts", cwd)).toEqual(`${cwd}/foo`);
16+
17+
// Absolute paths
918
expect(parseRootPath("/foo/bar", cwd)).toEqual("/foo/bar");
1019
expect(parseRootPath("/foo/bar.ts", cwd)).toEqual("/foo");
1120
expect(parseRootPath("/foo/bar.tsx", cwd)).toEqual("/foo");

0 commit comments

Comments
 (0)