-
Notifications
You must be signed in to change notification settings - Fork 17
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
Error when including in project #5
Comments
Hi, thanks for the issue report. The issue here is that webpack can't use the You might be able to work around this by leveraging memory-fs via webpack's resolve.alias configuration option. This will create an in-memory virtual filesystem that the jest snapshots will be written to. You will then have to add code to read them out of that virtual fs after your tests run and do something with them (you could maybe run a WebDAV server and use it to write them back to your real filesystem). However, I do not know if this approach will work; if If you get a setup working, I'd be interested to hear about it. |
Thank you very much @suchipi now I see, it makes a lot of sense. Apparently the virutal memory file system worked and Im not getting the fs error anymore. So I guess it correctly aliased fs for memory-fs. The problem is what you expected, other modules are also throwing errors. What Im pretty curious is this line ERROR in ./~/chai-jest-snapshot/~/jest-snapshot/~/jest-util/build/Console.js
Module not found: Error: Cannot resolve module 'console' in /Users/MrLaptop/WWW/advertiser-front/node_modules/chai-jest-snapshot/node_modules/jest-snapshot/node_modules/jest-util/build
@ ./~/chai-jest-snapshot/~/jest-snapshot/~/jest-util/build/Console.js 35:16-34 Shouldn't be console working fine in the browser? Im pretty new to testing in javascript, and this boilerplate structure is pretty complex for me, Im trying to make sense out of it. What I understand is: Karma launches a PhantomJs instance to run tests vía Mocha, tests are bundled with webpack as to be able to use es6 and magic things. Since chai-jest-snapshot relies on building files to the filesystem and its being run in Phantom which is a browser, it can literally not do that. Thats why all these problems occur. Am I right? So my question is, couldn't snapshots be built before the browser instance launches, webpack can extract CSS files and similar things, so I must assume it can write files? Or am I totally lost here? Trying to comprehend it, sorry for the mental chaos! |
Webpack statically analyzes your files without running them in order to compile them together. That means that, without running any of your code, it looks for things like The reason your build is failing because it can't find console is because it can't find the native node.js module called It's used like this: const { Console } = require("console");
const out = someWritableStream();
const err = someOtherWritableStream();
const myConsole = new Console(out, err);
// behaves just like the global `console`, but logs to the streams you created it with,
// instead of stdout and stderr (which is what the global `console` does).
myConsole.log("hi");
myConsole.error("hi"); Webpack can't pull in any built-in node.js modules (such as In the browser, there's no builtin way to create a The shim might look like this: module.exports = {
console: window.console,
Console: () => window.console,
}; |
@suchipi Thank you very much for the detailed explanation, now I understand where is the problem. I think Im going to focus more on trying to get the snapshot working independently from webpack since this looks like a though task, and I can't invest much more time in it :D I will probably return to tackle it in the future, so if I get any clear results, I will get back to you. Thanks! |
You might find use in https://www.npmjs.com/package/mocha-webpack |
Hello. Congrats for this amazing tool, cant wait to use it!
I tried including it in my current setup, runing tests with karma and mocha, and using Chai. You can see setup here:
https://github.com/davezuko/react-redux-starter-kit
The error comes when importing the module like the other ones:
wich should work perfectly. But I get a ton of errors:
Apparently webpack is having some trouble using some core node modules?? Im very confused. Any light you could shed would be amazing.
thanks!
The text was updated successfully, but these errors were encountered: