From 1ebd8394c5862e47179e8a43008c852c4dd3def8 Mon Sep 17 00:00:00 2001 From: Josh Wolfe Date: Thu, 31 Dec 2015 07:20:22 -0700 Subject: [PATCH] run zip64 test as part of normal test suite. tests now fail due to abandoned large.bin pipe. --- package.json | 2 +- test/test.js | 5 +++++ test/zip64.js | 33 +++++++++++++++++++++++---------- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 07d19ea..4be6daf 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "yet another unzip library for node", "main": "index.js", "scripts": { - "test": "node test/zip64.js && node test/test.js", + "test": "node test/test.js", "test-cov": "istanbul cover test/test.js", "test-travis": "istanbul cover --report lcovonly test/test.js" }, diff --git a/test/test.js b/test/test.js index 13308cd..1f12530 100644 --- a/test/test.js +++ b/test/test.js @@ -1,4 +1,5 @@ var yauzl = require("../"); +var zip64 = require("./zip64"); var fs = require("fs"); var path = require("path"); var Pend = require("pend"); @@ -235,11 +236,15 @@ pend.go(function(cb) { }); }); +// zip64 +pend.go(zip64.runTest); + pend.wait(function() { // if you don't see this, something never happened. console.log("done"); }); + function listZipFiles(dir) { var zipfilePaths = fs.readdirSync(dir).filter(function(filepath) { return /\.zip$/.exec(filepath); diff --git a/test/zip64.js b/test/zip64.js index 772a3db..cf26745 100644 --- a/test/zip64.js +++ b/test/zip64.js @@ -6,6 +6,8 @@ var Readable = require("stream").Readable; var Writable = require("stream").Writable; var BufferList = require("bl"); +exports.runTest = runTest; + function usage() { process.stdout.write("" + "zip64.js usage:\n" + @@ -156,7 +158,9 @@ function compressFile(inputPath, outputPath) { } } -function runTest() { +var logPrefix = "test/zip64: "; +function runTest(cb) { + if (cb == null) cb = function() {}; makeRandomAccessReader(function(reader, size) { yauzl.fromRandomAccessReader(reader, size, function(err, zipfile) { if (err) throw err; @@ -164,39 +168,48 @@ function runTest() { zipfile.on("entry", function(entry) { var expectedContents; if (entryIndex === 0) { - if (entry.fileName !== "a.txt") throw new Error("expected 'a.txt'. got '" + entry.fileName + "'."); + if (entry.fileName !== "a.txt") throw new Error(logPrefix + "expected 'a.txt'. got '" + entry.fileName + "'."); expectedContents = "hello a\n"; } else if (entryIndex === 1) { - if (entry.fileName !== "large.bin") throw new Error("expected 'large.bin'. got '" + entry.fileName + "'."); + if (entry.fileName !== "large.bin") throw new Error(logPrefix + "expected 'large.bin'. got '" + entry.fileName + "'."); expectedContents = null; // special case } else if (entryIndex === 2) { - if (entry.fileName !== "b.txt") throw new Error("expected 'b.txt'. got '" + entry.fileName + "'."); + if (entry.fileName !== "b.txt") throw new Error(logPrefix + "expected 'b.txt'. got '" + entry.fileName + "'."); expectedContents = "hello b\n"; } else { - throw new Error("too many entries"); + throw new Error(logPrefix + "too many entries"); } entryIndex += 1; zipfile.openReadStream(entry, function(err, readStream) { if (err) throw err; if (expectedContents != null) { readStream.pipe(BufferList(function(err, data) { - if (data.toString() !== expectedContents) throw new Error("expected contents:\n" + expectedContents + "\ngot:\n" + data.toString() + "\n"); - console.log("test/zip64: " + entry.fileName + ": PASS"); + if (data.toString() !== expectedContents) throw new Error(logPrefix + "expected contents:\n" + expectedContents + "\ngot:\n" + data.toString() + "\n"); + console.log(logPrefix + entry.fileName + ": PASS"); })); } else { // make sure this is the big thing getPrefixOfLargeBinContents(function(expectedPrefixBuffer) { getPrefixOfStream(readStream, function(actualPrefixBuffer) { if (buffersEqual(expectedPrefixBuffer, actualPrefixBuffer)) { - console.log("test/zip64: " + entry.fileName + ": PASS"); + console.log(logPrefix + entry.fileName + ": PASS"); } else { - throw new Error("large.bin contents read did not return expected stream") + throw new Error(logPrefix + "large.bin contents read did not return expected stream") } }); }); } }); }); + zipfile.on("close", function() { + console.log(logPrefix + "closed"); + if (entryIndex === 3) { + console.log(logPrefix + "pass"); + cb(); + } else { + throw new Error(logPrefix + "closed prematurely"); + } + }); }); }); } @@ -251,4 +264,4 @@ function buffersEqual(buf1, buf2) { return true; } -cli(); +if (require.main === module) cli();