forked from cloudflare/workers-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
paths.test.ts
39 lines (33 loc) · 1.16 KB
/
paths.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
import * as path from "node:path";
import { getBasePath, readableRelative } from "../paths";
describe("paths", () => {
describe("getBasePath()", () => {
it("should return the path to the wrangler package", () => {
expect(getBasePath()).toMatch(/packages[/\\]wrangler$/);
});
it("should use the __RELATIVE_PACKAGE_PATH__ as defined on the global context to compute the base path", () => {
(
global as unknown as { __RELATIVE_PACKAGE_PATH__: string }
).__RELATIVE_PACKAGE_PATH__ = "/foo/bar";
expect(getBasePath()).toEqual(path.resolve("/foo/bar"));
});
});
});
describe("readableRelative", () => {
const base = process.cwd();
it("should leave paths to files in the current directory as-is", () => {
expect(readableRelative(path.join(base, "wrangler.toml"))).toBe(
`wrangler.toml`
);
});
it("should leave files in the parent directory as-is", () => {
expect(readableRelative(path.resolve(base, "../wrangler.toml"))).toMatch(
/^\..[/\\]wrangler.toml$/
);
});
it("should add ./ to nested paths", () => {
expect(
readableRelative(path.join(base, "subdir", "wrangler.toml"))
).toMatch(/^\.[/\\]subdir[/\\]wrangler\.toml$/);
});
});