-
Notifications
You must be signed in to change notification settings - Fork 87
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
real fs called when require is in the trace #145
Comments
I have also been successfully using the real 'use strict';
const fs = require('fs');
const path = require('path');
const Module = require('module');
const mock = require('mock-fs');
const fsSandbox = {
'mock-fs-child.js': fs.readFileSync(path.resolve(__dirname, 'mock-fs-child.js')),
};
mock.currentSandbox = fsSandbox;
// Node's module loading system should be backed up by the real file system.
Module.__resolveFilename__ = Module._resolveFilename;
Module._resolveFilename = function (request, parent) {
if (request === 'fs') return this.__resolveFilename__(request, parent);
mock.restore();
try {
return this.__resolveFilename__(request, parent);
} finally {
mock(fsSandbox);
}
};
for (let ext in Module._extensions) {
let defaultLoader = Module._extensions[ext];
Module._extensions[ext] = function (module, filename) {
mock.restore();
try {
return defaultLoader(module, filename);
} finally {
mock(fsSandbox);
}
};
}
Module.prototype.__compile__ = Module.prototype._compile;
Module.prototype._compile = function (content, filename) {
// Use the sandbox to evaluate the code in our modules.
mock(fsSandbox);
try {
return this.__compile__(content, filename);
} finally {
mock.restore();
}
};
// `watchFile` is unsupported and throws with mock-fs
Object.defineProperty(fs, 'watchFile', {
get: () => (() => null),
set: () => null,
});
mock(fsSandbox);
require('./mock-fs-child'); mock-fs-child.js 'use strict';
const fs = require('fs');
const path = require('path');
fs.accessSync(path.resolve(__dirname, 'mock-fs.js')); Here, the If you'd be interested in including it in |
The PR #139 contains breaking changes. An example of a package in which the tests are broken after update This is not expected behavior for I think need to leave behavior from |
Would it be possible for you to use @blond - I'd be curious to get some more detail on what functionality you were relying on. As far as I could tell, calling |
@tschaub, this issue happens without overriding Test case in the OP. |
ping |
I will probably run a fork with this issue patched Would you entertain a patch that uses a |
What can I do to make it work with |
My use case is that I want I'm thinking of overriding |
I think if you override |
Is this ticket affecting a scenario like so:
Here in this case, it seems to have references to both the mock fs and the real fs:
|
mock-fs.js
mock-fs-child.js
The
accessSync
call throws in[email protected]
, but succeeds despite the file being absent in the sandbox in[email protected]
.Node v. 6.3.0
The text was updated successfully, but these errors were encountered: