Skip to content
This repository has been archived by the owner on Jan 19, 2023. It is now read-only.

Latest commit

 

History

History
24 lines (20 loc) · 1.3 KB

jest.org

File metadata and controls

24 lines (20 loc) · 1.3 KB

Jest

Jest is a delightful JavaScript Testing Framework with a focus on simplicity.

Some annotations about the Jest codebase

How they inject the beforeEach, describe, and others functions on the test file?

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.