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

createWriteStream is not mocked in node 16/17 #343

Closed
BuZZ-T opened this issue Nov 12, 2021 · 5 comments
Closed

createWriteStream is not mocked in node 16/17 #343

BuZZ-T opened this issue Nov 12, 2021 · 5 comments

Comments

@BuZZ-T
Copy link

BuZZ-T commented Nov 12, 2021

Hi! I observed the following problem using mock-fs:

I've written a file using fs.createWriteStream:
https://github.com/BuZZ-T/rusted-chromium/blob/35bd03817439545ec52c66a4a75d93acb13eb477/download.ts#L87

const file = createWriteStream(downloadPath + '.zip')
// ...
zipFileResponse.body.pipe(file)

and checked if it's written properly using mock-fs:
https://github.com/BuZZ-T/rusted-chromium/blob/35bd03817439545ec52c66a4a75d93acb13eb477/download.int.spec.ts#L113

expect(existsSync(chromeZip10)).toBe(true)

This works on node 14. When running the tests with node 16 or 17, the tests fail:
https://app.travis-ci.com/github/BuZZ-T/rusted-chromium/builds/241287559

When i run the tests locally with node 16 and 17, i can see that the file is created in the real filesystem.
The functionality with the unmocked createWriteStream is working properly and the same for all tested node versions.

Am i doing sth. wrong, or is this a bug of mock-fs?

Thx for your help and your great work!

@3cp
Copy link
Collaborator

3cp commented Nov 12, 2021

I deleted my previous reply, after I realised you said the file was created in real file system. It's bit odd, I checked our unit test code, it seems createWriteStream is creating mocked file just fine in node v16.

@3cp
Copy link
Collaborator

3cp commented Nov 13, 2021

Can you check node 14, whether your test code generates file in real file system too?

@3cp
Copy link
Collaborator

3cp commented Nov 13, 2021

What I guess is that your async downloadChromium function didn't wait for the write steam to finish writing.
It might be the similar timing issue as createReadSteam in nodejs v16+ #338 (comment)

You probably can try using the write stream's "close" or "finish" event callback to mark the ending of downloadChromium.

@BuZZ-T
Copy link
Author

BuZZ-T commented Nov 13, 2021

Hi 3cp! No, using node 14 no file is created in the real fs.

Thx for the hint with the timing issue, i'll check that!

@BuZZ-T
Copy link
Author

BuZZ-T commented Dec 14, 2021

Sorry for the late feedback. @3cp was right, error was on my side. It's working now! I appreciate the support and your work!

@BuZZ-T BuZZ-T closed this as completed Dec 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants