Jest is a delightful JavaScript Testing Framework with a focus on simplicity.
Everything that was injected on the test files seems to be handled by packages/jest-runtime. Here it’s injecting the Jest globals and others functions and create the sandbox environment to encapsulate the test, turning it unique and isolated.
Using Node’s experimental vm module, they inject a globals
object in the context of a V8’s
virtual machine and running the test inside it. The globals
object are composed by, the utils
functions like: jest.setTimeout
, jest.fn
, jest.mock
without necessairily import it.
The variable that was responsible to deal with the globals
object is jestGlobals
that is declared
on Runtime
class inside jest-runtime
package. They are setting the globals on setGlobalsForRuntime
method, and they are executed on packages/jest-circus.