-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Jest tests run against local code, not against the bundle #4028
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
Comments
This is the expected behavior. Jest is supposed to run on source files. On any large codebase, generating a bundle before running tests is too slow, so Jest compiles files just-in-time, which makes it fast. |
Ok, thanks for the info. But I have the bundle already generated and on the same local file system, with a source map. This would make Jest unusable for any browserified project, or am I missing something? |
You just run Jest on source files, no need to browserify it, just apply the same babel transforms if necessary. |
I am afraid I don't understand. I browserify code to get rid of Node objects. Then I want to test if this went well. My source files call into package dependencies that themselves call into Node API (like PS The ignite boilerplate is also fitted out with |
Sorry for my ignorance, but could you please enlighten me a bit more? I've had the worst dev experience of my life setting up my RN project, coming from Java. Just spend 2,5 days on setting up debugging. Going through tons of outdated advice and numerous open issues. I know porting packages written for Node is not the easiest thing to start with, but it shouldn't be this hard. I love the technology, what you guys are doing. I love the simple intuitive approach of Jest. But the barrier of entry to any (non-trivial) project setup is just so high. So my thinking was:
So if above thinking is correct (maybe it is not), then Jest should run against the transformed / transpiled code. I don't care whether it dynamically transforms or runs against a pre-build bundle. Can Jest do this, or is it explicitly designed not to do this (limiting its uses). If yes, how? If no, is this properly documented? Thanks for your help! |
Thanks. I'll find my way. |
@aschrijver the general way Jest handles this is by doing the transpilation itself. So you set up transformers in your config that Jest itself uses to do the transpilation. https://facebook.github.io/jest/docs/configuration.html#transform-object-string-string An example config for Typescript is here to give you an idea of what this could look like: https://github.com./kulshekhar/ts-jest In terms of shims, what I think you might be wanting are actually Jest mocks. A Jest mock can step in instead of an actual module when you import or require it. Does that help at all? |
Thanks @blargity I appreciate your feedback! I might follow up on your transformer suggestion, though I almost started with a different test tool. I will update the stackoverflow questions I have created for this issue with your additional comments! Regarding the mocks. No that will not work. I know the dependency will break if I port node-based stuff to android. I have to find the breakages through debugging, and then adjust shims accordingly until everything works. I am not creating isolated unit tests, but I intend to have the unit tests of a number of existing (former node-based) packages working as before after the package is ported. |
You can import your shims in a setup file, does that help? https://facebook.github.io/jest/docs/en/configuration.html#setupfiles-array |
Thanks @SimenB for your input. Well, I don't think this is meant for this purpose, just like in Java I wouldn't put code compilation in the Before and After of my integration tests. And also my project setup already has done all the plumbing and correctly patched bundle + source map is available when tests start. Why would I need to reconfigure all this? |
Is it possible to run tests on bundled code though? I'd like to do this in the final step of my CI so I know the actually code which we will be putting into production is tested, it seems rather flaky otherwise. |
Has anyone figured out a solution for this? I am trying to find out if it is possible to run tests on the compiled bundles, instead of running the tests on the base TypeScript files? |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Bug: Jest runs code from disk, ignores bundled code with shims
What is the current behavior?
I am using Ignite CLI, so I first filed this issue here: infinitered/ignite#1107
See here for additional details.
The problem is that Jest seems to be running tests against the files on my local disk, rather than those that were packaged in the output bundle.
I noticed this because I have shims that should cause unit tests to fail (I have node-based dependencies that I want to mould into my RN project), but they are succeeding.
The deployed app in the emulator is giving the expected errors.
What is the expected behavior?
The tests should fail, so I can debug and figure out which shims I have to tweak to get the node packages running in RN.
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
The text was updated successfully, but these errors were encountered: