/
relative.test.js
37 lines (30 loc) 路 1.28 KB
/
relative.test.js
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
import test from "ava";
import os from "os";
import relative from "../../lib/utils/relative.js";
if (os.platform() === "win32") {
test("should get correct relative path - depth 0 - windows", t => {
t.is(relative("C:\\the\\root", "C:\\the\\root\\one.js"), "one.js");
});
test("should get correct relative path - depth 1 - windows", t => {
t.is(relative("C:\\the\\root", "C:\\the\\rootone.js"), "..\\rootone.js");
});
test("should get correct relative path - depth 2 - windows", t => {
t.is(relative("C:\\the\\root", "C:\\therootone.js"), "C:\\therootone.js");
});
test("should get correct relative path with main root - depth 0 - windows", t => {
t.is(relative("C:\\", "C:\\the\\root\\one.js"), "the\\root\\one.js");
});
} else {
test("should get correct relative path - depth 0", t => {
t.is(relative("/the/root", "/the/root/one.js"), "one.js");
});
test("should get correct relative path - depth 1", t => {
t.is(relative("/the/root", "/the/rootone.js"), "../rootone.js");
});
test("should get correct relative path - depth 2", t => {
t.is(relative("/the/root", "/therootone.js"), "/therootone.js");
});
test("should get correct relative path with main root - depth 0", t => {
t.is(relative("/", "/the/root/one.js"), "the/root/one.js");
});
}