Skip to content

Commit

Permalink
test/httpZipResponseToFiles: don't unzip non-zip responses (#1235)
Browse files Browse the repository at this point in the history
This should make tests fail faster, and make failures easier to understand:

Previously: Error: end of central directory record signature not found
Now:        Error: expected 200 "OK", got 400 "Bad Request"

Related:

* #595
* #588
* #1052
  • Loading branch information
alxndrsn authored Oct 28, 2024
1 parent 9931f18 commit 15bd82c
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions test/util/zip.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,25 @@ const binaryParser = (res, callback) => {
};

const httpZipResponseToFiles = (zipHttpResponse) => new Promise((resolve, reject) => {
zipHttpResponse.buffer().parse(binaryParser).end((err, res) => {
if (err) return reject(err);

// eslint-disable-next-line no-shadow
yauzl.fromBuffer(res.body, (err, zipfile) => {
zipHttpResponse
.expect(200)
.expect('Content-Type', 'application/zip')
.buffer()
.parse(binaryParser)
.end((err, res) => {
if (err) return reject(err);

// eslint-disable-next-line no-shadow
processZipFile(zipfile, (err, result) => {
if (err) reject(err);
else resolve(result);
yauzl.fromBuffer(res.body, (err, zipfile) => {
if (err) return reject(err);

// eslint-disable-next-line no-shadow
processZipFile(zipfile, (err, result) => {
if (err) reject(err);
else resolve(result);
});
});
});
});
});

module.exports = { zipStreamToFiles, httpZipResponseToFiles };

0 comments on commit 15bd82c

Please sign in to comment.