Skip to content

Commit 5f281d9

Browse files
authored
test: fix test cases for uncompress stream (#118)
Improve test assertions for file comparison and enhance stream handling in the uncompress functionality. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Improved test infrastructure for stream handling with enhanced error propagation and flow control. * Updated test assertions with more descriptive mismatch messages for better diagnostics. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent b2d231b commit 5f281d9

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

test/zip/uncompress_stream.test.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,23 +193,24 @@ describe('test/zip/uncompress_stream.test.js', () => {
193193
pump(sourceStream, uncompressStream, err => {
194194
assert(!err);
195195
const res = dircompare.compareSync(originalDir, destDir);
196-
assert(res.distinct === 0);
197-
assert(res.equal === 5);
196+
assert.equal(res.distinct, 0, 'distinct files count mismatch');
197+
assert.equal(res.equal, 5, 'equal files count mismatch');
198198
assert(res.totalFiles === 4);
199199
assert(res.totalDirs === 1);
200200
done();
201201
});
202202

203203
uncompressStream.on('entry', (header, stream, next) => {
204-
stream.on('end', next);
205-
206204
if (header.type === 'file') {
207-
stream.pipe(fs.createWriteStream(path.join(destDir, header.name)));
205+
pipelinePromise(stream, fs.createWriteStream(path.join(destDir, header.name)))
206+
.then(next)
207+
.catch(done);
208208
} else { // directory
209209
fs.mkdir(path.join(destDir, header.name), { recursive: true }, err => {
210210
if (err) return done(err);
211211
stream.resume();
212212
});
213+
stream.on('end', next);
213214
}
214215
});
215216
});
@@ -231,15 +232,16 @@ describe('test/zip/uncompress_stream.test.js', () => {
231232
});
232233

233234
uncompressStream.on('entry', (header, stream, next) => {
234-
stream.on('end', next);
235-
236235
if (header.type === 'file') {
237-
stream.pipe(fs.createWriteStream(path.join(destDir, header.name)));
236+
pipelinePromise(stream, fs.createWriteStream(path.join(destDir, header.name)))
237+
.then(next)
238+
.catch(done);
238239
} else { // directory
239240
fs.mkdir(path.join(destDir, header.name), { recursive: true }, err => {
240241
if (err) return done(err);
241242
stream.resume();
242243
});
244+
stream.on('end', next);
243245
}
244246
});
245247
});

0 commit comments

Comments
 (0)