From 0b56dfce42c3944cce47e284608e6806f4c839c3 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 3 Jul 2016 19:19:21 +0100 Subject: Move tests to test for easier Mocha usage --- test/unzip.tests.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 test/unzip.tests.js (limited to 'test/unzip.tests.js') diff --git a/test/unzip.tests.js b/test/unzip.tests.js new file mode 100644 index 0000000..994fb68 --- /dev/null +++ b/test/unzip.tests.js @@ -0,0 +1,40 @@ +var fs = require("fs"); +var assert = require("assert"); +var path = require("path"); + +var test = require("./testing").test; +var unzip = require("../lib/unzip"); +var promises = require("../lib/promises"); + +describe("unzip", function() { + test("unzip fails if given empty object", function() { + return unzip.openZip({}).then(function() { + assert.ok(false, "Expected failure"); + }, function(error) { + assert.equal("Could not find file in options", error.message); + }); + }); + + test("unzip can open local zip file", function() { + var zipPath = path.join(__dirname, "test-data/hello.zip"); + return unzip.openZip({path: zipPath}).then(function(zipFile) { + return zipFile.read("hello", "utf8"); + }).then(function(contents) { + assert.equal(contents, "Hello world\n"); + }); + }); + + test('unzip can open Buffer', function() { + var zipPath = path.join(__dirname, "test-data/hello.zip"); + return promises.nfcall(fs.readFile, zipPath) + .then(function(buffer) { + return unzip.openZip({buffer: buffer}); + }) + .then(function(zipFile) { + return zipFile.read("hello", "utf8"); + }) + .then(function(contents) { + assert.equal(contents, "Hello world\n"); + }); + }); +}); -- cgit v1.2.3