Open Jaid opened 2 years ago
How does jest-runtime
do it today? Maybe it's possible to mock the globals import
I notice if I do not import directly from @jest/globals
my jest.spyOn
calls get incorrect types
jest-runtime
does it by intercepting the require
(or import
) call and returning a module with the correct API (what would be the globals for the currently running module). I'm not sure how this module would do it loaders or module mocks. If globals are enabled it's easy enough (just be a facade for them), but if globals are disabled this module needs to interact with the framework (circus) via https://github.com/facebook/jest/blob/41bf2300895a2c00d0525d21260f0a392819871f/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapter.ts#L37
Switching to jest-light-runner with tests that use
import {it, expect} from "@jest/globals"
currently doesn't work. It's easily fixed by just removing this import and using those magically injected globals, but this way ESLint reports undefined variables and I lose my IDE's type features.So could you either inject your own globals into
from "@jest/globals"
imports or expose your own globals, so I can useimport {it, expect} from "jest-light-runner"
?