-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Use babel transform to inline all requires #3786
Conversation
Improving startup time, and avoiding unused modules in the tree
There is one failing test: the Symbol test, and it shows a real issue (as well as the flaky utils-test that overwrote I can think of two ways to fix this:
We should analyze what gets required in a test context and what environment side-effects they depend on. Maybe we could isolate them all and pass them in from the adapter I posted above, like:
I think that may actually be the best choice – it makes it more explicit what side-effects Jest's test code can depend on during a test run. Also, the speedup for Jest's own test run on this diff is ridiculous. @SimenB, thank you! |
Taking some sort of snapshot of the global environment before running user code might make sense? Or do you want to explicitly pass just the ones needed? |
I think the first step could be to log all modules that are required through |
So thanks to @SimenB data digging I've been able to find that |
Woo, should be ready to merge now! |
Is just eagerly evaluating it enough for now? I an alpha could be released it'd be interesting to run that version on e.g. React and see if stuff is still green. And probably at FB, if that's feasible? And other large test suites, of course. |
Inline require
@@ -11,6 +11,7 @@ | |||
"babel-plugin-transform-es2015-modules-commonjs": "^6.24.1", |
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 should be removed
i messed around with this issue this week. My opinion that we should make everything that is not a test execute in the outer VM scope. I tried updating jest at fb internally, and i couldn't even count how many ways there are to break the test runner. one of the examples: if any of the test modify Array.prototype[Symbol.iterator] = null; any code inside any files that were I spent almost a week trying to catch all of these cases and eventually gave up (one of the test modified To avoid requiring anything in the inner VM scope i was thinking about two things that we'll need to do:
const circusContext = jestCurcus.createContext();
// circusContext has {it, describe, setState, getState} and other globals
Object.assign(innerVMScopeGlobal, circusContext);
We need this for some specific cases. For example, when we throw an try {
expect(1).toBe(2);
} catch (error) {
error instanceOf Error; // false, since the error throw is from the outerVM scope `Error` class.
} i'm not sure what would be the cleanest way to do this, but i'm thinkig about something like this: const innerVMScopeGlobals = extractGlobals(innerVMScopeGlobal);
const expectWithInnerVMScopeGlobals = expect.createWithGlobals(innerVMScopeGlobals);
innerVMScopeGlobal.expect = expectWithInnerVMScopeGlobals;
runtime.requireModule(testPath); // require the actual test file, now there's no way for it to modify anything global that will conflict with Jest's code
circusContext.run(); // run the test suite after the test runs, both circus instance and expect instance are disposed (garbage collected) |
@aaronabramov: I'm fine with this if you can make it work reliably. Anything that does an |
* Fix utils test. * Revert some imports.
See #4340 |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Rebased version of #3493