I use mock-fsto try and test the Webpack plugin that I wrote, which modifies a file in my file system.
Here's the test:
test('writes chunks to build/assets.json if no json file present', () => {
mockFs({
[buildDir]: {},
});
const stats = new Stats({
assetsByChunkName: {
main: 'main.somecrazyhash12341213445345.js',
},
});
const compiler = new Compiler(stats);
const plugin = new ChunksToJsonPlugin(config);
expect(fs.existsSync(assetFilePath)).toBe(false);
plugin.apply(compiler);
compiler.execHandler();
expect(fs.existsSync(assetFilePath)).toBe(true);
expect(fs.readFileSync(assetFilePath, 'utf-8')).toEqual(
JSON.stringify({
main: 'main.somecrazyhash12341213445345.js',
})
);
mockFs.restore();
});
It works great when I run it on my own, but when I run it as part of a package, other tests (which don't use mock-fs) break.
ss http://d.pr/i/z2ne+
I noticed that it mock-fsis in stacktrace, which makes me think that the file system is also mocking these tests (which I don't want).
mock-fs states that:
mock-fs @4 . , fs, process.binding('fs'). - , fs (, graceful-fs) Node Node fs.
, process.binding, Jest, , , .
? , mock-fs?