Skip to content

Commit

Permalink
added tests for issue #5
Browse files Browse the repository at this point in the history
unzipping while a zipped directory already exists
  • Loading branch information
Mostafa-Samir committed Jun 1, 2016
1 parent b1fd441 commit ed4ab0f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
12 changes: 11 additions & 1 deletion tests/unzip.async.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,14 @@ describe("Unzipping asynchronously", function () {
expect(localMemory.T5ZippedFS.read("hello/world/says-world", 'text')).to.equal("World");
});

})
it("uses existing folders without throwing EEXIST error", function(done) {
zipper.unzip("./tests/assets/hello.zip", function(error, unzipped) {
expect(error).to.be.null;

unzipped.save("./tests/assets/hello-unzip-exists", function(error) {
expect(error).to.be.null;
});
});
});

});
38 changes: 21 additions & 17 deletions tests/unzip.sync.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,42 @@ var localMemory = {}; // used for passing variables between tests


describe("Unzipping synchronously", function () {

it("unzips a .zip file in memory without errors", function () {

localMemory.T1ZippedFS = zipper.sync.unzip("./tests/assets/hello.zip").memory();
});

it("checks if the ZippedFS object contains correct data", function () {

expect(localMemory.T1ZippedFS.contents()).to.include("hello/says-hello") &&
expect(localMemory.T1ZippedFS.read("hello/says-hello", 'text')).to.equal("Hello") &&
expect(localMemory.T1ZippedFS.contents()).to.include("hello/world/says-world") &&
expect(localMemory.T1ZippedFS.read("hello/world/says-world", 'text')).to.equal("World");
});

it("unzips a .zip file to disk without errors", function () {

fs.mkdirSync("./tests/assets/hello-sync-unzip");
zipper.sync.unzip("./tests/assets/hello.zip").save("./tests/assets/hello-sync-unzip/");
});

it("checks if unzipped files on disk contain correct data", function (done) {

fs.readFile("./tests/assets/hello-sync-unzip/hello/says-hello", 'utf8', function (err, data) {

if (err)
throw err;

expect(data).to.equal("Hello");

fs.readFile("./tests/assets/hello-sync-unzip/hello/world/says-world", 'utf8', function (err, world_data) {

if (err)
throw err;

expect(world_data).to.equal("World");

done();
});
});
Expand All @@ -51,16 +51,20 @@ describe("Unzipping synchronously", function () {
it("unzips a file directly from the buffer containing it", function () {

var buff = fs.readFileSync("./tests/assets/hello.zip");

localMemory.T5ZippedFS = zipper.sync.unzip(buff).memory();
});

it("checks if the ZippedFS object contains correct data", function () {

expect(localMemory.T5ZippedFS.contents()).to.include("hello/says-hello") &&
expect(localMemory.T5ZippedFS.read("hello/says-hello", 'text')).to.equal("Hello") &&
expect(localMemory.T5ZippedFS.contents()).to.include("hello/world/says-world") &&
expect(localMemory.T5ZippedFS.read("hello/world/says-world", 'text')).to.equal("World");
});

})
it("uses existing folders without throwing EEXIST error", function() {
zipper.sync.unzip("./tests/assets/hello.zip").save("./tests/assets/hello-unzip-exists");
});

});

0 comments on commit ed4ab0f

Please sign in to comment.