forked from ariya/phantomjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fs-spec-03.js
137 lines (116 loc) · 5.23 KB
/
fs-spec-03.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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
describe("Files and Directories API", function() {
var TEST_DIR = "testdir",
TEST_FILE = "testfile",
START_CWD = fs.workingDirectory;
it("should create a new temporary directory and change the Current Working Directory to it", function() {
expect(fs.makeDirectory(TEST_DIR)).toBeTruthy();
expect(fs.changeWorkingDirectory(TEST_DIR)).toBeTruthy();
});
it("should create a file in the Current Working Directory and check it's absolute path", function() {
fs.write(TEST_FILE, TEST_FILE, "w");
var suffix = fs.join("", TEST_DIR, TEST_FILE),
abs = fs.absolute(".." + suffix),
lastIndex = abs.lastIndexOf(suffix);
expect(lastIndex).toNotEqual(-1);
expect(lastIndex + suffix.length === abs.length);
});
it("should return to previous Current Working Directory and remove temporary directory", function() {
expect(fs.changeWorkingDirectory(START_CWD)).toBeTruthy();
fs.removeTree(TEST_DIR);
});
it("should copy Content of the '/test/' Directory in a temporary directory, compare with the original and then remove", function() {
var phantomLibraryPathListingLength = fs.list(phantom.libraryPath).length;
fs.copyTree(phantom.libraryPath, "/tmp/"+TEST_DIR);
expect(phantomLibraryPathListingLength === fs.list("/tmp/"+TEST_DIR).length);
fs.removeTree("/tmp/"+TEST_DIR);
});
// TODO: test the actual functionality once we can create symlink.
it("should have readLink function", function() {
expect(typeof fs.readLink).toEqual('function');
});
fs.removeTree(TEST_DIR);
describe("fs.join(...)", function() {
var parts, expected, actual;
it("empty parts", function() {
parts = [];
expected = ".";
actual = fs.join.apply(null, parts);
expect(actual).toEqual(expected);
});
it("one part (empty string)", function() {
parts = [""];
expected = ".";
actual = fs.join.apply(null, parts);
expect(actual).toEqual(expected);
});
it("one part (array)", function() {
parts = [[], null];
expected = ".";
actual = fs.join.apply(null, parts);
expect(actual).toEqual(expected);
});
it("empty string and one part", function() {
parts = ["", "a"];
expected = "/a";
actual = fs.join.apply(null, parts);
expect(actual).toEqual(expected);
});
it("empty string and multiple parts", function() {
parts = ["", "a", "b", "c"];
expected = "/a/b/c";
actual = fs.join.apply(null, parts);
expect(actual).toEqual(expected);
});
it("empty string and multiple parts with empty strings", function() {
parts = ["", "a", "", "b", "", "c"];
expected = "/a/b/c";
actual = fs.join.apply(null, parts);
expect(actual).toEqual(expected);
});
it("multiple parts", function() {
parts = ["a", "b", "c"];
expected = "a/b/c";
actual = fs.join.apply(null, parts);
expect(actual).toEqual(expected);
});
it("multiple parts with empty strings", function() {
parts = ["a", "", "b", "", "c"];
expected = "a/b/c";
actual = fs.join.apply(null, parts);
expect(actual).toEqual(expected);
});
});
describe("fs.split(path)", function() {
var path, expected, actual;
it("should split absolute path with trailing separator", function() {
path = fs.separator + "a" + fs.separator + "b" + fs.separator + "c" + fs.separator + "d" + fs.separator;
actual = fs.split(path);
expected = ["", "a", "b", "c", "d"];
expect(actual).toEqual(expected);
});
it("should split absolute path without trailing separator", function() {
path = fs.separator + "a" + fs.separator + "b" + fs.separator + "c" + fs.separator + "d";
actual = fs.split(path);
expected = ["", "a", "b", "c", "d"];
expect(actual).toEqual(expected);
});
it("should split non-absolute path with trailing separator", function() {
path = "a" + fs.separator + "b" + fs.separator + "c" + fs.separator + "d" + fs.separator;
actual = fs.split(path);
expected = ["a", "b", "c", "d"];
expect(actual).toEqual(expected);
});
it("should split non-absolute path without trailing separator", function() {
path = "a" + fs.separator + "b" + fs.separator + "c" + fs.separator + "d";
actual = fs.split(path);
expected = ["a", "b", "c", "d"];
expect(actual).toEqual(expected);
});
it("should split path with consecutive separators", function() {
path = "a" + fs.separator + fs.separator + fs.separator + "b" + fs.separator + "c" + fs.separator + fs.separator + "d" + fs.separator + fs.separator + fs.separator;
expected = ["a", "b", "c", "d"];
actual = fs.split(path);
expect(actual).toEqual(expected);
});
});
});