Comments (4)
I was actually going to suggest doing something just like that: stub in your own stream implementation (Readable, PassThrough, etc.) as the returned value from unzipper
and emit events to trigger different function calls. The only downside is because you're keeping your functions private it requires more setup and stubbing to test each private method instead of exposing them for testing by exporting the function separately.
from node-unzipper.
Seems like that's a bit of a hassle. Would it be easier to pull out each of your event handlers and test them more individually? Testing code like that feels like its closer to an "integration" test since you're verifying different units of work will work together, which would make more sense to actually use unzipper
as part of the test.
from node-unzipper.
I'm not an expert in testing, so I may have mixed unit and integration tests.
My event handlers are private methods and I didn't plan to test it (I know there is a debate about it).
Actually, the only thing I would like to test is the callback (with or without error):
if(isValid) {
readableStream.pipe(unzipper.Parse())
.on('entry', (entry) => {
// Filter and write files like in the doc
...
})
.on('finish', () => {
callback();
});
} else {
callback(new Error());
}
If stubbing unzipper is too complicated, I'll try to use it with a simple .zip file for my tests.
from node-unzipper.
Oops! My bad... Actually my first idea works well but I called the event emit at the wrong place 🤦♂️
Here is my solution:
describe('...', () => {
let readableStream = null;
let Parse = null;
beforeEach(() => {
readableStream = new stream.Readable({ read: () => null });
Parse = sinon.stub(unzipper, 'Parse');
Parse.returns(readableStream);
});
afterEach(() => {
Parse.restore();
});
it('...', done => {
myFunctionToTest(..., err => {
expect(err).to.be.undefined;
done();
});
readableStream.emit('finish');
});
});
Sorry and thanks for you help @camlegleiter
from node-unzipper.
Related Issues (20)
- Open method throwing error for zip file greater than 4GB
- Incorrect decoding when parsing an archive with a file with Cyrillic characters HOT 2
- Move away from unmaintained fstream HOT 3
- release version 0.10.13 to npm HOT 3
- How to get first few bytes per entry? HOT 1
- How can I make it faster? HOT 1
- Unhandled rejection Error: invalid signature: 0x21726152 HOT 3
- Getting BAD_PASSWORD very often
- It doesn't work with Nodejs v19.8.0, v19.8.1
- In Node v18 or higher: unzipper.Parse({forceStream: true}) throws Error [ERR_STREAM_PREMATURE_CLOSE]: Premature close | SOLVED HOT 1
- Package Version Management
- Files extracted from zip are currupt HOT 18
- Possible copyright violation HOT 1
- async iteration example no longer works in Node 18x, 19x HOT 3
- README needs an example of how to handle directories
- Not getting all files extracted HOT 13
- Attempt to decompress latest Maxmind GeoLite archive causes the error HOT 1
- `Open.file()` returns unicode replacement character(�) for unicode filenames HOT 1
- stream is not async iterable (DuplexWrapper)
- Corrupted unzipped files when using Extract HOT 15
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-unzipper.