Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve tests #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
102 changes: 70 additions & 32 deletions test/compressed.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,83 @@ var fs = require('fs');
var path = require('path');
var temp = require('temp');
var dirdiff = require('dirdiff');
var streamBuffers = require("stream-buffers");
var unzip = require('../');

test("parse compressed archive (created by POSIX zip)", function (t) {
var archive = path.join(__dirname, '../testData/compressed-standard/archive.zip');

var unzipParser = unzip.Parse();
fs.createReadStream(archive).pipe(unzipParser);
unzipParser.on('error', function(err) {
throw err;
function testParsing(filename) {
test('parse compressed archive: ' + filename, function(t) {
var archive = path.join(__dirname, '../testData/' + filename + '/archive.zip');

var unzipParser = unzip.Parse();
fs.createReadStream(archive).pipe(unzipParser);
unzipParser.on('error', function(err) {
throw err;
});

unzipParser.on('close', t.end.bind(this));
});
}

unzipParser.on('close', t.end.bind(this));
});
function testExtraction(filename) {
test('extract compressed archive: ' + filename, function(t) {
var archive = path.join(__dirname, '../testData/' + filename + '/archive.zip');

test("extract compressed archive w/ file sizes known prior to zlib inflation (created by POSIX zip)", function (t) {
var archive = path.join(__dirname, '../testData/compressed-standard/archive.zip');
temp.mkdir('node-unzip-', function(err, dirPath) {
if (err) {
throw err;
}
var unzipExtractor = unzip.Extract({ path: dirPath });
unzipExtractor.on('error', function(err) {
throw err;
});
unzipExtractor.on('close', testExtractionResults);

temp.mkdir('node-unzip-', function (err, dirPath) {
if (err) {
throw err;
}
var unzipExtractor = unzip.Extract({ path: dirPath });
unzipExtractor.on('error', function(err) {
throw err;
fs.createReadStream(archive).pipe(unzipExtractor);

function testExtractionResults() {
dirdiff(path.join(__dirname, '../testData/' + filename + '/inflated'), dirPath, {
fileContents: true
}, function(err, diffs) {
if (err) {
throw err;
}
t.equal(diffs.length, 0, 'extracted directory contents');
t.end();
});
}
});
unzipExtractor.on('close', testExtractionResults);

fs.createReadStream(archive).pipe(unzipExtractor);

function testExtractionResults() {
dirdiff(path.join(__dirname, '../testData/compressed-standard/inflated'), dirPath, {
fileContents: true
}, function (err, diffs) {
if (err) {
throw err;
}
t.equal(diffs.length, 0, 'extracted directory contents');
t.end();
});
});
}

// test all archive parsing and extraction
fs.readdir(path.join(__dirname, '../testData/'), function(err, files) {
files.forEach(function(filename) {
if (/^compressed/.test(filename)) {
testParsing(filename);
testExtraction(filename);
}
});
});
});

test('pipe a single file entry out of a zip', function (t) {
var archive = path.join(__dirname, '../testData/compressed-standard/archive.zip');

fs.createReadStream(archive)
.pipe(unzip.Parse())
.on('entry', function(entry) {
if (entry.path === 'file.txt') {
var writableStream = new streamBuffers.WritableStreamBuffer();
writableStream.on('close', function () {
var str = writableStream.getContentsAsString('utf8');
var fileStr = fs.readFileSync(path.join(__dirname, '../testData/compressed-standard/inflated/file.txt'), 'utf8')
t.equal(str, fileStr);
t.end();
});
entry.pipe(writableStream);
} else {
entry.autodrain();
}
});
});

78 changes: 0 additions & 78 deletions test/fileSizeUnknownFlag.js

This file was deleted.

29 changes: 0 additions & 29 deletions test/pipeSingleEntry.js

This file was deleted.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*! jQuery UI - v1.10.2 - 2013-04-11
* http://jqueryui.com
* Includes: jquery.ui.core.css
* Copyright 2013 jQuery Foundation and other contributors Licensed MIT */

/* Layout helpers
----------------------------------*/
.ui-helper-hidden {
display: none;
}
.ui-helper-hidden-accessible {
border: 0;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
.ui-helper-reset {
margin: 0;
padding: 0;
border: 0;
outline: 0;
line-height: 1.3;
text-decoration: none;
font-size: 100%;
list-style: none;
}
.ui-helper-clearfix:before,
.ui-helper-clearfix:after {
content: "";
display: table;
border-collapse: collapse;
}
.ui-helper-clearfix:after {
clear: both;
}
.ui-helper-clearfix {
min-height: 0; /* support: IE7 */
}
.ui-helper-zfix {
width: 100%;
height: 100%;
top: 0;
left: 0;
position: absolute;
opacity: 0;
filter:Alpha(Opacity=0);
}

.ui-front {
z-index: 100;
}


/* Interaction Cues
----------------------------------*/
.ui-state-disabled {
cursor: default !important;
}


/* Icons
----------------------------------*/

/* states and images */
.ui-icon {
display: block;
text-indent: -99999px;
overflow: hidden;
background-repeat: no-repeat;
}


/* Misc visuals
----------------------------------*/

/* Overlays */
.ui-widget-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.