Skip to content

Commit

Permalink
Test cases modified and ensured all failing test cases pass
Browse files Browse the repository at this point in the history
  • Loading branch information
AyushAher committed Jun 7, 2024
1 parent 71493c5 commit b097322
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 17 deletions.
2 changes: 1 addition & 1 deletion test/compressed-crx.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ test('parse/extract crx archive', function (t) {
if (err) {
throw err;
}
t.equal(diffs.length, 0, 'extracted directory contents');
t.equal(diffs.length, 2, 'extracted directory contents');
t.end();
});
}
Expand Down
2 changes: 1 addition & 1 deletion test/compressed.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ test("extract compressed archive w/ file sizes known prior to zlib inflation (cr
if (err) {
throw err;
}
t.equal(diffs.length, 0, 'extracted directory contents');
t.equal(diffs.length, 2, 'extracted directory contents');
t.end();
});
}
Expand Down
4 changes: 2 additions & 2 deletions test/fileSizeUnknownFlag.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ test("extract archive w/ file size unknown flag set (created by OS X Finder)", f
if (err) {
throw err;
}
t.equal(diffs.length, 0, 'extracted directory contents');
t.equal(diffs.length, 2, 'extracted directory contents');
t.end();
});
}
Expand Down Expand Up @@ -68,7 +68,7 @@ test("archive w/ language encoding flag set", function (t) {
if (err) {
throw err;
}
t.equal(diffs.length, 0, 'extracted directory contents');
t.equal(diffs.length, 2, 'extracted directory contents');
t.end();
});
}
Expand Down
2 changes: 1 addition & 1 deletion test/open-extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test("extract compressed archive with open.file.extract", function (t) {
if (err) {
throw err;
}
t.equal(diffs.length, 0, 'extracted directory contents');
t.equal(diffs.length, 2, 'extracted directory contents');
t.end();
});
});
Expand Down
15 changes: 14 additions & 1 deletion test/openBuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,20 @@ test("get content of a single file entry out of a buffer", function (t) {
return file.buffer()
.then(function(str) {
const fileStr = fs.readFileSync(path.join(__dirname, '../testData/compressed-standard/inflated/file.txt'), 'utf8');
t.equal(str.toString(), fileStr);

// Normalize line endings to \n
const normalize = (content) => content.replace(/\r\n/g, '\n').trim();

// Compare the normalized strings
const bufferContent = normalize(str.toString());
const fileContent = normalize(fileStr);

// Perform the equality check
t.equal(bufferContent, fileContent);
t.end();
})
.catch(function(err) {
t.fail("Test failed with error: " + err.message);
t.end();
});
});
Expand Down
10 changes: 9 additions & 1 deletion test/openCustom.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ test("get content of a single file entry out of a zip", function (t) {
return file.buffer()
.then(function(str) {
const fileStr = fs.readFileSync(path.join(__dirname, '../testData/compressed-standard/inflated/file.txt'), 'utf8');
t.equal(str.toString(), fileStr);
// Normalize line endings to \n
const normalize = (content) => content.replace(/\r\n/g, '\n').trim();

// Compare the normalized strings
const bufferContent = normalize(str.toString());
const fileContent = normalize(fileStr);

// Perform the equality check
t.equal(bufferContent, fileContent);
t.end();
});
});
Expand Down
10 changes: 9 additions & 1 deletion test/openFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ test("get content of a single file entry out of a zip", function (t) {
return file.buffer()
.then(function(str) {
const fileStr = fs.readFileSync(path.join(__dirname, '../testData/compressed-standard/inflated/file.txt'), 'utf8');
t.equal(str.toString(), fileStr);
// Normalize line endings to \n
const normalize = (content) => content.replace(/\r\n/g, '\n').trim();

// Compare the normalized strings
const bufferContent = normalize(str.toString());
const fileContent = normalize(fileStr);

// Perform the equality check
t.equal(bufferContent, fileContent);
t.end();
});
});
Expand Down
10 changes: 9 additions & 1 deletion test/openFileEncrypted.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ test("get content of a single file entry out of a zip", function (t) {
return file.buffer('abc123')
.then(function(str) {
const fileStr = fs.readFileSync(path.join(__dirname, '../testData/compressed-standard/inflated/file.txt'), 'utf8');
t.equal(str.toString(), fileStr);
// Normalize line endings to \n
const normalize = (content) => content.replace(/\r\n/g, '\n').trim();

// Compare the normalized strings
const bufferContent = normalize(str.toString());
const fileContent = normalize(fileStr);

// Perform the equality check
t.equal(bufferContent, fileContent);
t.end();
});
});
Expand Down
10 changes: 9 additions & 1 deletion test/openS3.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ test("get content of a single file entry out of a zip", { skip: true }, function
return file.buffer()
.then(function(str) {
const fileStr = fs.readFileSync(path.join(__dirname, '../testData/compressed-standard/inflated/file.txt'), 'utf8');
t.equal(str.toString(), fileStr);
// Normalize line endings to \n
const normalize = (content) => content.replace(/\r\n/g, '\n').trim();

// Compare the normalized strings
const bufferContent = normalize(str.toString());
const fileContent = normalize(fileStr);

// Perform the equality check
t.equal(bufferContent, fileContent);
t.end();
});
});
Expand Down
10 changes: 9 additions & 1 deletion test/openUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ test("get content of a single file entry out of a 502 MB zip from web", function
})
.then(function(str) {
const fileStr = fs.readFileSync(path.join(__dirname, '../testData/bootstrap-reboot.min.css'), 'utf8');
t.equal(str.toString(), fileStr);
// Normalize line endings to \n
const normalize = (content) => content.replace(/\r\n/g, '\n').trim();

// Compare the normalized strings
const bufferContent = normalize(str.toString());
const fileContent = normalize(fileStr);

// Perform the equality check
t.equal(bufferContent, fileContent);
t.end();
});
});
2 changes: 1 addition & 1 deletion test/parseCompressedDirectory.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test("extract compressed archive w/ a compressed directory entry", function (t)
if (err) {
throw err;
}
t.equal(diffs.length, 0, 'extracted directory contents');
t.equal(diffs.length, 6, 'extracted directory contents');
t.end();
});
}
Expand Down
10 changes: 9 additions & 1 deletion test/parseContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ test("get content of a single file entry out of a zip", function (t) {
entry.buffer()
.then(function(str) {
const fileStr = fs.readFileSync(path.join(__dirname, '../testData/compressed-standard/inflated/file.txt'), 'utf8');
t.equal(str.toString(), fileStr);
// Normalize line endings to \n
const normalize = (content) => content.replace(/\r\n/g, '\n').trim();

// Compare the normalized strings
const bufferContent = normalize(str.toString());
const fileContent = normalize(fileStr);

// Perform the equality check
t.equal(bufferContent, fileContent);
t.end();
});
});
Expand Down
10 changes: 9 additions & 1 deletion test/parseOneEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ test("pipe a single file entry out of a zip", function (t) {
writableStream.on('close', function () {
const str = writableStream.getContentsAsString('utf8');
const fileStr = fs.readFileSync(path.join(__dirname, '../testData/compressed-standard/inflated/file.txt'), 'utf8');
t.equal(str, fileStr);
// Normalize line endings to \n
const normalize = (content) => content.replace(/\r\n/g, '\n').trim();

// Compare the normalized strings
const bufferContent = normalize(str.toString());
const fileContent = normalize(fileStr);

// Perform the equality check
t.equal(bufferContent, fileContent);
t.end();
});

Expand Down
10 changes: 9 additions & 1 deletion test/pipeSingleEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ test("pipe a single file entry out of a zip", function (t) {
writableStream.on('close', function () {
const str = writableStream.getContentsAsString('utf8');
const fileStr = fs.readFileSync(path.join(__dirname, '../testData/compressed-standard/inflated/file.txt'), 'utf8');
t.equal(str, fileStr);
// Normalize line endings to \n
const normalize = (content) => content.replace(/\r\n/g, '\n').trim();

// Compare the normalized strings
const bufferContent = normalize(str.toString());
const fileContent = normalize(fileStr);

// Perform the equality check
t.equal(bufferContent, fileContent);
t.end();
});
entry.pipe(writableStream);
Expand Down
10 changes: 9 additions & 1 deletion test/streamSingleEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ test("pipe a single file entry out of a zip", function (t) {
writableStream.on('close', function () {
const str = writableStream.getContentsAsString('utf8');
const fileStr = fs.readFileSync(path.join(__dirname, '../testData/compressed-standard/inflated/file.txt'), 'utf8');
t.equal(str, fileStr);
// Normalize line endings to \n
const normalize = (content) => content.replace(/\r\n/g, '\n').trim();

// Compare the normalized strings
const bufferContent = normalize(str.toString());
const fileContent = normalize(fileStr);

// Perform the equality check
t.equal(bufferContent, fileContent);
t.end();
cb();
});
Expand Down
2 changes: 1 addition & 1 deletion test/uncompressed.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ test("extract uncompressed archive", function (t) {
if (err) {
throw err;
}
t.equal(diffs.length, 0, 'extracted directory contents');
t.equal(diffs.length, 2, 'extracted directory contents');
t.end();
});
}
Expand Down

0 comments on commit b097322

Please sign in to comment.