-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Helper to bypass mock FS & expose real files/directories #304
Conversation
Will update README tomorrow and Thanks! |
- Lazy-loaded files were not able to be written to if they hadn't been read yet - Descriptors defaulted to writable: false after setting value
- Included mock.createDirectoryInfoFromPaths() - Included mock.bypass()
This can be considered complete (unless changes requested) Recent updates:
|
- Added mock.mapFile(), mock.mapDir(), and mock.mapPaths() - Created improved tests for the new methods (comparing stats with real files, etc)
Ok! I think you'll find the new API much more intuitive and flexible! I believe the new readme should be easy to understand, as well. We now have three new mapper methods: I re-wrote everything which also allowed for better tests & better overall architecture. |
Updated according to last review:
Note
Is this acceptable? Would you like to alter the readme or handle it somehow? |
Investigating the TypeError with Buffer in Windows Node 12, now. At a bit of a loss on this. I can't see how any changes would have affected that. Will debug offline. |
I am quite sure your new implementation supports |
Should clarify - I'm referring to |
I just checked out the current source from upstream master and confirmed that the buffer TypeError is happening on Windows for Node 12.
|
For the buffer thing, can you find the exact line? Nodejs fs APIs support string/buffer on path, for example in the doc:
But Nodejs path APIs only support string.
This means if you forward a |
It's in regard to Error:
Originating code: https://github.com/tschaub/mock-fs/blob/master/test/lib/fs.link-symlink.spec.js#L191-L204 |
I see, could be a regression related to latest nodejs v12.18.3. |
Confirmed it's a win32 only regression in latest nodejs v12, I will try to investigate. I think we can ignore that failure in this PR. |
@3cp How'd it go? Any luck on determining a solution? |
I have not spent time on the win32 problem yet. Will do in coming week. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this great contribution @nonara.
I'll follow up with a separate pull request to address the additional comments.
const res = fn(); | ||
|
||
// Handle promise return | ||
if (typeof res.then === 'function') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will throw a TypeError
if fn
returns null
or undefined
.
// Handle promise return | ||
if (typeof res.then === 'function') { | ||
res.then(exports.enable); | ||
res.catch(exports.enable); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be better handled with res.finally(exports.enable)
.
return res; | ||
} catch (e) { | ||
exports.enable(); | ||
throw e; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be in a finally
block.
|
||
| Option | Type | Default | Description | | ||
| --------- | ------- | ------- | ------------ | ||
| lazyLoad | boolean | true | File content isn't loaded until explicitly read |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could just be called lazy
- avoiding a bit of repetition: load(dir, {lazy: true})
.
Sure thing! Thanks for taking the time to review. |
The win32 issue is indeed a regression in nodejs code base. I will create a PR or issue there. |
The win32 issue is fixed in nodejs, but not patched in v12 yet. nodejs/node#34514 |
Any idea when this will be released? Working on a project that could really use it ❤️ |
There are some edge cases to be cleaned up (#306 (comment)). I will PR the fix shortly after merging #303. |
Hi, thanks for this wonderful upgrade |
…_modules now that tschaub/mock-fs#304 is available
…_modules now that tschaub/mock-fs#304 is available
…ules now that tschaub/mock-fs#304 is available
@nonara Many thanks for your effort! That's a great addition to mockFs that will make testing much easier :-) |
@frederikheld You're very welcome. Thank you for the kind comment! |
Adds two new features:
mock.bypass()
- Allows executing commands against the actual FSmock.load()
-Reads the filesystem to map actual files and directories from the filesystem
Options:
recursive
,lazyLoad
See readme for more detail
closes #62
closes #213
(possibly others?)