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

Latest commit

 

History

History
31 lines (19 loc) · 1.46 KB

File metadata and controls

31 lines (19 loc) · 1.46 KB

Single-context Node.js environment for Jest

⚠️ This project is no longer maintained because the author switched from Jest to Vitest ⚠️

One of Jest's key features is context isolation so tests can't have side-effects on other tests by manipulating the global context. In theory that's a good idea but in practice the current implementation messes around with global types in a way which breaks pretty much all instanceof checks in tests against standard types like Uint8Array for example.

See Jest issue #2549 for details.

This small project provides a single-context Node.js environment which effectively sacrifices the context isolation feature by using a single context for all tests so instanceof checks works again as expected.

Alternatively you may want to try jest-light-runner which tackles the problem right at the base with a new test runner implementation instead of hacking the standard test runner of Jest.

Usage

  • Install dependency:

    npm install -D jest-environment-node-single-context
    
  • Add this property to your Jest config:

    testEnvironment: "jest-environment-node-single-context"