2011-09-05 02:42:54 +04:00
|
|
|
describe("Files and Directories API", function() {
|
2011-08-02 03:47:43 +04:00
|
|
|
var TEST_DIR = "testdir",
|
|
|
|
TEST_FILE = "testfile",
|
|
|
|
START_CWD = fs.workingDirectory;
|
2012-03-23 15:45:13 +04:00
|
|
|
|
|
|
|
it("should create a new temporary directory and change the Current Working Directory to it", function() {
|
2011-08-02 03:47:43 +04:00
|
|
|
expect(fs.makeDirectory(TEST_DIR)).toBeTruthy();
|
|
|
|
expect(fs.changeWorkingDirectory(TEST_DIR)).toBeTruthy();
|
|
|
|
});
|
2012-03-23 15:45:13 +04:00
|
|
|
|
2011-08-02 03:47:43 +04:00
|
|
|
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.separator + TEST_DIR + fs.separator + TEST_FILE,
|
|
|
|
abs = fs.absolute(".." + suffix),
|
|
|
|
lastIndex = abs.lastIndexOf(suffix);
|
|
|
|
expect(lastIndex).toNotEqual(-1);
|
|
|
|
expect(lastIndex + suffix.length === abs.length);
|
|
|
|
});
|
2012-03-23 15:45:13 +04:00
|
|
|
|
2011-09-05 02:42:54 +04:00
|
|
|
it("should return to previous Current Working Directory and remove temporary directory", function() {
|
2011-08-02 03:47:43 +04:00
|
|
|
expect(fs.changeWorkingDirectory(START_CWD)).toBeTruthy();
|
2011-09-01 02:32:56 +04:00
|
|
|
fs.removeTree(TEST_DIR);
|
2011-08-02 03:47:43 +04:00
|
|
|
});
|
2011-09-05 02:42:54 +04:00
|
|
|
|
2012-07-04 06:48:25 +04:00
|
|
|
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);
|
|
|
|
});
|
2012-03-17 07:43:26 +04:00
|
|
|
|
|
|
|
// TODO: test the actual functionality once we can create symlink.
|
|
|
|
it("should have readLink function", function() {
|
|
|
|
expect(typeof fs.readLink).toEqual('function');
|
|
|
|
});
|
2012-07-04 06:48:25 +04:00
|
|
|
|
|
|
|
fs.removeTree(TEST_DIR);
|
2012-03-17 07:43:26 +04:00
|
|
|
});
|